diff --git a/desktop/src/auto-update.js b/desktop/src/auto-update.js --- a/desktop/src/auto-update.js +++ b/desktop/src/auto-update.js @@ -3,15 +3,15 @@ // eslint-disable-next-line import/extensions import { app, ipcMain, autoUpdater } from 'electron/main'; -const getUpdateUrl = version => +const getUpdateURL = (version: string) => `https://electron-update.commtechnologies.org/update/${process.platform}/${version}`; export function initAutoUpdate(): void { - autoUpdater.setFeedURL({ url: getUpdateUrl(app.getVersion()) }); + autoUpdater.setFeedURL({ url: getUpdateURL(app.getVersion()) }); // Check for new updates every 10 minutes const updateIntervalMs = 10 * 60_000; - let currentTimeout = null; + let currentTimeout: ?TimeoutID = null; const scheduleCheckForUpdates = () => { if (!currentTimeout) { currentTimeout = setTimeout(() => { diff --git a/desktop/src/handle-squirrel-event.js b/desktop/src/handle-squirrel-event.js --- a/desktop/src/handle-squirrel-event.js +++ b/desktop/src/handle-squirrel-event.js @@ -16,7 +16,7 @@ const updateExe = path.resolve(process.execPath, '..', '..', 'Update.exe'); const commExeName = path.basename(process.execPath); - const spawnUpdate = args => { + const spawnUpdate = (args: string[]) => { return spawn(updateExe, args, { detached: true }).on('close', app.quit); }; diff --git a/desktop/src/main.js b/desktop/src/main.js --- a/desktop/src/main.js +++ b/desktop/src/main.js @@ -10,6 +10,7 @@ autoUpdater, // eslint-disable-next-line import/extensions } from 'electron/main'; +import type { Event, MenuItemConstructorOptions } from 'electron'; import contextMenu from 'electron-context-menu'; import fs from 'fs'; import path from 'path'; @@ -32,7 +33,7 @@ let mainWindow = null; const setApplicationMenu = () => { - let mainMenu = []; + let mainMenu: MenuItemConstructorOptions[] = []; if (isMac) { mainMenu = [ { @@ -157,7 +158,11 @@ }; ipcMain.on('double-click-top-bar', doubleClickTopBar); - const updateDownloaded = (event, releaseNotes, releaseName) => { + const updateDownloaded = ( + event: Event, + releaseNotes?: string, + releaseName: string, + ) => { win.webContents.send('on-new-version-available', releaseName); }; autoUpdater.on('update-downloaded', updateDownloaded); diff --git a/desktop/src/preload.js b/desktop/src/preload.js --- a/desktop/src/preload.js +++ b/desktop/src/preload.js @@ -2,12 +2,16 @@ // eslint-disable-next-line import/extensions import { contextBridge, ipcRenderer } from 'electron/renderer'; +import type { IpcRendererEvent } from 'electron'; import type { ElectronBridge } from 'lib/types/electron-types.js'; const bridge: ElectronBridge = { onNavigate: callback => { - const withEvent = (event, ...args) => callback(...args); + const withEvent = ( + event: IpcRendererEvent, + ...args: $ReadOnlyArray + ) => callback(...args); ipcRenderer.on('on-navigate', withEvent); return () => ipcRenderer.removeListener('on-navigate', withEvent); }, @@ -16,7 +20,10 @@ setBadge: value => ipcRenderer.send('set-badge', value), version: ipcRenderer.sendSync('get-version'), onNewVersionAvailable: callback => { - const withEvent = (event, ...args) => callback(...args); + const withEvent = ( + event: IpcRendererEvent, + ...args: $ReadOnlyArray + ) => callback(...args); ipcRenderer.on('on-new-version-available', withEvent); return () => ipcRenderer.removeListener('on-new-version-available', withEvent); @@ -24,13 +31,19 @@ updateToNewVersion: () => ipcRenderer.send('update-to-new-version'), platform: { win32: 'windows', darwin: 'macos' }[process.platform], onDeviceTokenRegistered: callback => { - const withEvent = (event, ...args) => callback(...args); + const withEvent = ( + event: IpcRendererEvent, + ...args: $ReadOnlyArray + ) => callback(...args); ipcRenderer.on('on-device-token-registered', withEvent); return () => ipcRenderer.removeListener('on-device-token-registered', withEvent); }, onNotificationClicked: callback => { - const withEvent = (event, ...args) => callback(...args); + const withEvent = ( + event: IpcRendererEvent, + ...args: $ReadOnlyArray + ) => callback(...args); ipcRenderer.on('on-notification-clicked', withEvent); return () => ipcRenderer.removeListener('on-notification-clicked', withEvent); diff --git a/desktop/src/push-notifications.js b/desktop/src/push-notifications.js --- a/desktop/src/push-notifications.js +++ b/desktop/src/push-notifications.js @@ -1,5 +1,9 @@ // @flow +import type { + PushNotificationManager as PushNotificationManagerType, + PushNotificationReceivedEventArgs, +} from '@commapp/windowspush'; // eslint-disable-next-line import/extensions import { app, pushNotifications, Notification } from 'electron/main'; import EventEmitter from 'events'; @@ -20,7 +24,10 @@ windowsPushNotificationManager = PushNotificationManager.default; - const handleEvent = (manager, event) => { + const handleEvent = ( + manager: PushNotificationManagerType, + event: PushNotificationReceivedEventArgs, + ) => { const byteArray = []; for (let i = 0; i < event.payload.length; i++) { byteArray.push(event.payload[i]); @@ -62,7 +69,7 @@ } } else if (process.platform === 'win32' && windowsPushNotificationManager) { try { - const token = await new Promise((resolvePromise, reject) => { + const token = await new Promise((resolvePromise, reject) => { windowsPushNotificationManager.createChannelAsync( 'f09f4211-a998-40c1-a515-689e3faecb62', (error, result) => {