From 9d70925dfbd43fc08906f217d57f1dd145f33d83 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 22 Jul 2024 07:34:17 +1000 Subject: [PATCH 01/19] feat: check for updates --- src/electron/main.js | 297 +++++++++++++++++++++++-------------------- 1 file changed, 158 insertions(+), 139 deletions(-) diff --git a/src/electron/main.js b/src/electron/main.js index 8a290881c..29c383c4f 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -1,156 +1,175 @@ const { - ipcMain: ipc, - app, - nativeTheme, - globalShortcut, - Menu, -} = require('electron/main'); -const { menubar } = require('menubar'); -const { autoUpdater } = require('electron-updater'); -const { onFirstRunMaybe } = require('./first-run'); -const path = require('node:path'); + ipcMain: ipc, + app, + nativeTheme, + globalShortcut, + Menu, +} = require("electron/main"); +const { menubar } = require("menubar"); +const { autoUpdater } = require("electron-updater"); +const { onFirstRunMaybe } = require("./first-run"); +const path = require("node:path"); // TODO: Remove @electron/remote use - see #650 -require('@electron/remote/main').initialize(); +require("@electron/remote/main").initialize(); const idleIcon = path.resolve( - `${__dirname}/../../assets/images/tray-idleTemplate.png`, + `${__dirname}/../../assets/images/tray-idleTemplate.png`, ); const activeIcon = path.resolve( - `${__dirname}/../../assets/images/tray-active.png`, + `${__dirname}/../../assets/images/tray-active.png`, ); const browserWindowOpts = { - width: 500, - height: 400, - minWidth: 500, - minHeight: 400, - resizable: false, - webPreferences: { - enableRemoteModule: true, - nodeIntegration: true, - contextIsolation: false, - }, + width: 500, + height: 400, + minWidth: 500, + minHeight: 400, + resizable: false, + webPreferences: { + enableRemoteModule: true, + nodeIntegration: true, + contextIsolation: false, + }, }; +const mb = menubar({ + icon: idleIcon, + index: `file://${__dirname}/index.html`, + browserWindow: browserWindowOpts, + preloadWindow: true, + showDockIcon: false, +}); + const contextMenu = Menu.buildFromTemplate([ - { - role: 'reload', - }, - { - role: 'toggleDevTools', - }, - { type: 'separator' }, - { - label: 'Quit', - click: () => { - app.quit(); - }, - }, + { + role: "reload", + }, + { + role: "toggleDevTools", + }, + { type: "separator" }, + { + label: "Check for updates", + click: () => { + autoUpdater.checkForUpdatesAndNotify(); + }, + }, + { + label: "Quit", + click: () => { + app.quit(); + }, + }, ]); app.whenReady().then(async () => { - await onFirstRunMaybe(); - - const mb = menubar({ - icon: idleIcon, - index: `file://${__dirname}/index.html`, - browserWindow: browserWindowOpts, - preloadWindow: true, - showDockIcon: false, - }); - - mb.on('ready', () => { - autoUpdater.checkForUpdatesAndNotify(); - - mb.app.setAppUserModelId('com.electron.gitify'); - - // Tray configuration - mb.tray.setIgnoreDoubleClickEvents(true); - mb.tray.on('right-click', (_event, bounds) => { - mb.tray.popUpContextMenu(contextMenu, { x: bounds.x, y: bounds.y }); - }); - - // Custom key events - mb.window.webContents.on('before-input-event', (event, input) => { - if (input.key === 'Escape') { - mb.window.hide(); - event.preventDefault(); - } - }); - - // DevTools configuration - mb.window.webContents.on('devtools-opened', () => { - mb.window.setSize(800, 600); - mb.window.center(); - mb.window.resizable = true; - mb.window.setAlwaysOnTop(true); - }); - - mb.window.webContents.on('devtools-closed', () => { - const trayBounds = mb.tray.getBounds(); - mb.window.setSize(browserWindowOpts.width, browserWindowOpts.height); - mb.positioner.move('trayCenter', trayBounds); - mb.window.resizable = false; - }); - }); - - nativeTheme.on('updated', () => { - if (nativeTheme.shouldUseDarkColors) { - mb.window.webContents.send('gitify:update-theme', 'DARK'); - } else { - mb.window.webContents.send('gitify:update-theme', 'LIGHT'); - } - }); - - /** - * Gitify custom IPC events - */ - ipc.handle('gitify:version', () => app.getVersion()); - - ipc.on('gitify:window-show', () => mb.showWindow()); - - ipc.on('gitify:window-hide', () => mb.hideWindow()); - - ipc.on('gitify:quit', () => mb.app.quit()); - - ipc.on('gitify:icon-active', () => { - if (!mb.tray.isDestroyed()) { - mb.tray.setImage(activeIcon); - } - }); - - ipc.on('gitify:icon-idle', () => { - if (!mb.tray.isDestroyed()) { - mb.tray.setImage(idleIcon); - } - }); - - ipc.on('gitify:update-title', (_, title) => { - if (!mb.tray.isDestroyed()) { - mb.tray.setTitle(title); - } - }); - - ipc.on( - 'gitify:update-keyboard-shortcut', - (_, { enabled, keyboardShortcut }) => { - if (!enabled) { - globalShortcut.unregister(keyboardShortcut); - return; - } - - globalShortcut.register(keyboardShortcut, () => { - if (mb.window.isVisible()) { - mb.hideWindow(); - } else { - mb.showWindow(); - } - }); - }, - ); - - ipc.on('gitify:update-auto-launch', (_, settings) => { - app.setLoginItemSettings(settings); - }); + await onFirstRunMaybe(); + + mb.on("ready", () => { + autoUpdater.checkForUpdatesAndNotify(); + + mb.app.setAppUserModelId("com.electron.gitify"); + + // Tray configuration + mb.tray.setIgnoreDoubleClickEvents(true); + mb.tray.on("right-click", (_event, bounds) => { + mb.tray.popUpContextMenu(contextMenu, { x: bounds.x, y: bounds.y }); + }); + + // Custom key events + mb.window.webContents.on("before-input-event", (event, input) => { + if (input.key === "Escape") { + mb.window.hide(); + event.preventDefault(); + } + }); + + // DevTools configuration + mb.window.webContents.on("devtools-opened", () => { + mb.window.setSize(800, 600); + mb.window.center(); + mb.window.resizable = true; + mb.window.setAlwaysOnTop(true); + }); + + mb.window.webContents.on("devtools-closed", () => { + const trayBounds = mb.tray.getBounds(); + mb.window.setSize(browserWindowOpts.width, browserWindowOpts.height); + mb.positioner.move("trayCenter", trayBounds); + mb.window.resizable = false; + }); + }); + + nativeTheme.on("updated", () => { + if (nativeTheme.shouldUseDarkColors) { + mb.window.webContents.send("gitify:update-theme", "DARK"); + } else { + mb.window.webContents.send("gitify:update-theme", "LIGHT"); + } + }); + + autoUpdater.on("checking-for-update", () => { + console.log("Checking for update..."); + // TODO - display the update status in the UI + }); + autoUpdater.on("update-available", (info) => { + console.log("Update available."); + // TODO - display the update status in the UI + }); + autoUpdater.on("update-not-available", (info) => { + console.log("Update not available."); + // TODO - display the update status in the UI + }); + + /** + * Gitify custom IPC events + */ + ipc.handle("gitify:version", () => app.getVersion()); + + ipc.on("gitify:window-show", () => mb.showWindow()); + + ipc.on("gitify:window-hide", () => mb.hideWindow()); + + ipc.on("gitify:quit", () => mb.app.quit()); + + ipc.on("gitify:icon-active", () => { + if (!mb.tray.isDestroyed()) { + mb.tray.setImage(activeIcon); + } + }); + + ipc.on("gitify:icon-idle", () => { + if (!mb.tray.isDestroyed()) { + mb.tray.setImage(idleIcon); + } + }); + + ipc.on("gitify:update-title", (_, title) => { + if (!mb.tray.isDestroyed()) { + mb.tray.setTitle(title); + } + }); + + ipc.on( + "gitify:update-keyboard-shortcut", + (_, { enabled, keyboardShortcut }) => { + if (!enabled) { + globalShortcut.unregister(keyboardShortcut); + return; + } + + globalShortcut.register(keyboardShortcut, () => { + if (mb.window.isVisible()) { + mb.hideWindow(); + } else { + mb.showWindow(); + } + }); + }, + ); + + ipc.on("gitify:update-auto-launch", (_, settings) => { + app.setLoginItemSettings(settings); + }); }); From 529992afac7ef29e2b43aa4a84f828d04c05ba97 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 22 Jul 2024 07:51:53 +1000 Subject: [PATCH 02/19] feat: check for updates --- src/context/App.tsx | 5 + src/electron/main.js | 310 ++++++++++++++++++++--------------------- src/utils/constants.ts | 2 + 3 files changed, 162 insertions(+), 155 deletions(-) diff --git a/src/context/App.tsx b/src/context/App.tsx index 5c4bb409c..27b1e6869 100644 --- a/src/context/App.tsx +++ b/src/context/App.tsx @@ -1,4 +1,5 @@ import { webFrame } from 'electron'; +import { autoUpdater } from 'electron-updater'; import { type ReactNode, createContext, @@ -149,6 +150,10 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { fetchNotifications({ auth, settings }); }, Constants.FETCH_INTERVAL); + useInterval(() => { + autoUpdater.checkForUpdatesAndNotify(); + }, Constants.AUTO_UPDATE_CHECK_INTERVAL); + useEffect(() => { const count = getNotificationCount(notifications); diff --git a/src/electron/main.js b/src/electron/main.js index 29c383c4f..cf9e0345b 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -1,175 +1,175 @@ const { - ipcMain: ipc, - app, - nativeTheme, - globalShortcut, - Menu, -} = require("electron/main"); -const { menubar } = require("menubar"); -const { autoUpdater } = require("electron-updater"); -const { onFirstRunMaybe } = require("./first-run"); -const path = require("node:path"); + ipcMain: ipc, + app, + nativeTheme, + globalShortcut, + Menu, +} = require('electron/main'); +const { menubar } = require('menubar'); +const { autoUpdater } = require('electron-updater'); +const { onFirstRunMaybe } = require('./first-run'); +const path = require('node:path'); // TODO: Remove @electron/remote use - see #650 -require("@electron/remote/main").initialize(); +require('@electron/remote/main').initialize(); const idleIcon = path.resolve( - `${__dirname}/../../assets/images/tray-idleTemplate.png`, + `${__dirname}/../../assets/images/tray-idleTemplate.png`, ); const activeIcon = path.resolve( - `${__dirname}/../../assets/images/tray-active.png`, + `${__dirname}/../../assets/images/tray-active.png`, ); const browserWindowOpts = { - width: 500, - height: 400, - minWidth: 500, - minHeight: 400, - resizable: false, - webPreferences: { - enableRemoteModule: true, - nodeIntegration: true, - contextIsolation: false, - }, + width: 500, + height: 400, + minWidth: 500, + minHeight: 400, + resizable: false, + webPreferences: { + enableRemoteModule: true, + nodeIntegration: true, + contextIsolation: false, + }, }; const mb = menubar({ - icon: idleIcon, - index: `file://${__dirname}/index.html`, - browserWindow: browserWindowOpts, - preloadWindow: true, - showDockIcon: false, + icon: idleIcon, + index: `file://${__dirname}/index.html`, + browserWindow: browserWindowOpts, + preloadWindow: true, + showDockIcon: false, }); const contextMenu = Menu.buildFromTemplate([ - { - role: "reload", - }, - { - role: "toggleDevTools", - }, - { type: "separator" }, - { - label: "Check for updates", - click: () => { - autoUpdater.checkForUpdatesAndNotify(); - }, - }, - { - label: "Quit", - click: () => { - app.quit(); - }, - }, + { + role: 'reload', + }, + { + role: 'toggleDevTools', + }, + { type: 'separator' }, + { + label: 'Check for updates', + click: () => { + autoUpdater.checkForUpdatesAndNotify(); + }, + }, + { + label: 'Quit', + click: () => { + app.quit(); + }, + }, ]); app.whenReady().then(async () => { - await onFirstRunMaybe(); - - mb.on("ready", () => { - autoUpdater.checkForUpdatesAndNotify(); - - mb.app.setAppUserModelId("com.electron.gitify"); - - // Tray configuration - mb.tray.setIgnoreDoubleClickEvents(true); - mb.tray.on("right-click", (_event, bounds) => { - mb.tray.popUpContextMenu(contextMenu, { x: bounds.x, y: bounds.y }); - }); - - // Custom key events - mb.window.webContents.on("before-input-event", (event, input) => { - if (input.key === "Escape") { - mb.window.hide(); - event.preventDefault(); - } - }); - - // DevTools configuration - mb.window.webContents.on("devtools-opened", () => { - mb.window.setSize(800, 600); - mb.window.center(); - mb.window.resizable = true; - mb.window.setAlwaysOnTop(true); - }); - - mb.window.webContents.on("devtools-closed", () => { - const trayBounds = mb.tray.getBounds(); - mb.window.setSize(browserWindowOpts.width, browserWindowOpts.height); - mb.positioner.move("trayCenter", trayBounds); - mb.window.resizable = false; - }); - }); - - nativeTheme.on("updated", () => { - if (nativeTheme.shouldUseDarkColors) { - mb.window.webContents.send("gitify:update-theme", "DARK"); - } else { - mb.window.webContents.send("gitify:update-theme", "LIGHT"); - } - }); - - autoUpdater.on("checking-for-update", () => { - console.log("Checking for update..."); - // TODO - display the update status in the UI - }); - autoUpdater.on("update-available", (info) => { - console.log("Update available."); - // TODO - display the update status in the UI - }); - autoUpdater.on("update-not-available", (info) => { - console.log("Update not available."); - // TODO - display the update status in the UI - }); - - /** - * Gitify custom IPC events - */ - ipc.handle("gitify:version", () => app.getVersion()); - - ipc.on("gitify:window-show", () => mb.showWindow()); - - ipc.on("gitify:window-hide", () => mb.hideWindow()); - - ipc.on("gitify:quit", () => mb.app.quit()); - - ipc.on("gitify:icon-active", () => { - if (!mb.tray.isDestroyed()) { - mb.tray.setImage(activeIcon); - } - }); - - ipc.on("gitify:icon-idle", () => { - if (!mb.tray.isDestroyed()) { - mb.tray.setImage(idleIcon); - } - }); - - ipc.on("gitify:update-title", (_, title) => { - if (!mb.tray.isDestroyed()) { - mb.tray.setTitle(title); - } - }); - - ipc.on( - "gitify:update-keyboard-shortcut", - (_, { enabled, keyboardShortcut }) => { - if (!enabled) { - globalShortcut.unregister(keyboardShortcut); - return; - } - - globalShortcut.register(keyboardShortcut, () => { - if (mb.window.isVisible()) { - mb.hideWindow(); - } else { - mb.showWindow(); - } - }); - }, - ); - - ipc.on("gitify:update-auto-launch", (_, settings) => { - app.setLoginItemSettings(settings); - }); + await onFirstRunMaybe(); + + mb.on('ready', () => { + autoUpdater.checkForUpdatesAndNotify(); + + mb.app.setAppUserModelId('com.electron.gitify'); + + // Tray configuration + mb.tray.setIgnoreDoubleClickEvents(true); + mb.tray.on('right-click', (_event, bounds) => { + mb.tray.popUpContextMenu(contextMenu, { x: bounds.x, y: bounds.y }); + }); + + // Custom key events + mb.window.webContents.on('before-input-event', (event, input) => { + if (input.key === 'Escape') { + mb.window.hide(); + event.preventDefault(); + } + }); + + // DevTools configuration + mb.window.webContents.on('devtools-opened', () => { + mb.window.setSize(800, 600); + mb.window.center(); + mb.window.resizable = true; + mb.window.setAlwaysOnTop(true); + }); + + mb.window.webContents.on('devtools-closed', () => { + const trayBounds = mb.tray.getBounds(); + mb.window.setSize(browserWindowOpts.width, browserWindowOpts.height); + mb.positioner.move('trayCenter', trayBounds); + mb.window.resizable = false; + }); + }); + + nativeTheme.on('updated', () => { + if (nativeTheme.shouldUseDarkColors) { + mb.window.webContents.send('gitify:update-theme', 'DARK'); + } else { + mb.window.webContents.send('gitify:update-theme', 'LIGHT'); + } + }); + + autoUpdater.on('checking-for-update', () => { + console.log('Checking for update...'); + // TODO - display the update status in the UI + }); + autoUpdater.on('update-available', (info) => { + console.log('Update available.'); + // TODO - display the update status in the UI + }); + autoUpdater.on('update-not-available', (info) => { + console.log('Update not available.'); + // TODO - display the update status in the UI + }); + + /** + * Gitify custom IPC events + */ + ipc.handle('gitify:version', () => app.getVersion()); + + ipc.on('gitify:window-show', () => mb.showWindow()); + + ipc.on('gitify:window-hide', () => mb.hideWindow()); + + ipc.on('gitify:quit', () => mb.app.quit()); + + ipc.on('gitify:icon-active', () => { + if (!mb.tray.isDestroyed()) { + mb.tray.setImage(activeIcon); + } + }); + + ipc.on('gitify:icon-idle', () => { + if (!mb.tray.isDestroyed()) { + mb.tray.setImage(idleIcon); + } + }); + + ipc.on('gitify:update-title', (_, title) => { + if (!mb.tray.isDestroyed()) { + mb.tray.setTitle(title); + } + }); + + ipc.on( + 'gitify:update-keyboard-shortcut', + (_, { enabled, keyboardShortcut }) => { + if (!enabled) { + globalShortcut.unregister(keyboardShortcut); + return; + } + + globalShortcut.register(keyboardShortcut, () => { + if (mb.window.isVisible()) { + mb.hideWindow(); + } else { + mb.showWindow(); + } + }); + }, + ); + + ipc.on('gitify:update-auto-launch', (_, settings) => { + app.setLoginItemSettings(settings); + }); }); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 15ed6ef59..5ca16cd87 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -23,6 +23,8 @@ export const Constants = { FETCH_INTERVAL: 60000, + AUTO_UPDATE_CHECK_INTERVAL: 3600000, + DEFAULT_KEYBOARD_SHORTCUT: 'CommandOrControl+Shift+G', // GitHub Docs From 86dc234fb04108dd1884d27e5f7057bba9c0e98d Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 22 Jul 2024 07:52:36 +1000 Subject: [PATCH 03/19] feat: check for updates --- src/electron/main.js | 316 +++++++++++++++++++++---------------------- 1 file changed, 158 insertions(+), 158 deletions(-) diff --git a/src/electron/main.js b/src/electron/main.js index cf9e0345b..35bae7f39 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -1,175 +1,175 @@ const { - ipcMain: ipc, - app, - nativeTheme, - globalShortcut, - Menu, -} = require('electron/main'); -const { menubar } = require('menubar'); -const { autoUpdater } = require('electron-updater'); -const { onFirstRunMaybe } = require('./first-run'); -const path = require('node:path'); + ipcMain: ipc, + app, + nativeTheme, + globalShortcut, + Menu, +} = require("electron/main"); +const { menubar } = require("menubar"); +const { autoUpdater } = require("electron-updater"); +const { onFirstRunMaybe } = require("./first-run"); +const path = require("node:path"); // TODO: Remove @electron/remote use - see #650 -require('@electron/remote/main').initialize(); +require("@electron/remote/main").initialize(); const idleIcon = path.resolve( - `${__dirname}/../../assets/images/tray-idleTemplate.png`, + `${__dirname}/../../assets/images/tray-idleTemplate.png`, ); const activeIcon = path.resolve( - `${__dirname}/../../assets/images/tray-active.png`, + `${__dirname}/../../assets/images/tray-active.png`, ); const browserWindowOpts = { - width: 500, - height: 400, - minWidth: 500, - minHeight: 400, - resizable: false, - webPreferences: { - enableRemoteModule: true, - nodeIntegration: true, - contextIsolation: false, - }, + width: 500, + height: 400, + minWidth: 500, + minHeight: 400, + resizable: false, + webPreferences: { + enableRemoteModule: true, + nodeIntegration: true, + contextIsolation: false, + }, }; -const mb = menubar({ - icon: idleIcon, - index: `file://${__dirname}/index.html`, - browserWindow: browserWindowOpts, - preloadWindow: true, - showDockIcon: false, -}); - const contextMenu = Menu.buildFromTemplate([ - { - role: 'reload', - }, - { - role: 'toggleDevTools', - }, - { type: 'separator' }, - { - label: 'Check for updates', - click: () => { - autoUpdater.checkForUpdatesAndNotify(); - }, - }, - { - label: 'Quit', - click: () => { - app.quit(); - }, - }, + { + role: "reload", + }, + { + role: "toggleDevTools", + }, + { type: "separator" }, + { + label: "Check for updates", + click: () => { + autoUpdater.checkForUpdatesAndNotify(); + }, + }, + { + label: "Quit", + click: () => { + app.quit(); + }, + }, ]); app.whenReady().then(async () => { - await onFirstRunMaybe(); - - mb.on('ready', () => { - autoUpdater.checkForUpdatesAndNotify(); - - mb.app.setAppUserModelId('com.electron.gitify'); - - // Tray configuration - mb.tray.setIgnoreDoubleClickEvents(true); - mb.tray.on('right-click', (_event, bounds) => { - mb.tray.popUpContextMenu(contextMenu, { x: bounds.x, y: bounds.y }); - }); - - // Custom key events - mb.window.webContents.on('before-input-event', (event, input) => { - if (input.key === 'Escape') { - mb.window.hide(); - event.preventDefault(); - } - }); - - // DevTools configuration - mb.window.webContents.on('devtools-opened', () => { - mb.window.setSize(800, 600); - mb.window.center(); - mb.window.resizable = true; - mb.window.setAlwaysOnTop(true); - }); - - mb.window.webContents.on('devtools-closed', () => { - const trayBounds = mb.tray.getBounds(); - mb.window.setSize(browserWindowOpts.width, browserWindowOpts.height); - mb.positioner.move('trayCenter', trayBounds); - mb.window.resizable = false; - }); - }); - - nativeTheme.on('updated', () => { - if (nativeTheme.shouldUseDarkColors) { - mb.window.webContents.send('gitify:update-theme', 'DARK'); - } else { - mb.window.webContents.send('gitify:update-theme', 'LIGHT'); - } - }); - - autoUpdater.on('checking-for-update', () => { - console.log('Checking for update...'); - // TODO - display the update status in the UI - }); - autoUpdater.on('update-available', (info) => { - console.log('Update available.'); - // TODO - display the update status in the UI - }); - autoUpdater.on('update-not-available', (info) => { - console.log('Update not available.'); - // TODO - display the update status in the UI - }); - - /** - * Gitify custom IPC events - */ - ipc.handle('gitify:version', () => app.getVersion()); - - ipc.on('gitify:window-show', () => mb.showWindow()); - - ipc.on('gitify:window-hide', () => mb.hideWindow()); - - ipc.on('gitify:quit', () => mb.app.quit()); - - ipc.on('gitify:icon-active', () => { - if (!mb.tray.isDestroyed()) { - mb.tray.setImage(activeIcon); - } - }); - - ipc.on('gitify:icon-idle', () => { - if (!mb.tray.isDestroyed()) { - mb.tray.setImage(idleIcon); - } - }); - - ipc.on('gitify:update-title', (_, title) => { - if (!mb.tray.isDestroyed()) { - mb.tray.setTitle(title); - } - }); - - ipc.on( - 'gitify:update-keyboard-shortcut', - (_, { enabled, keyboardShortcut }) => { - if (!enabled) { - globalShortcut.unregister(keyboardShortcut); - return; - } - - globalShortcut.register(keyboardShortcut, () => { - if (mb.window.isVisible()) { - mb.hideWindow(); - } else { - mb.showWindow(); - } - }); - }, - ); - - ipc.on('gitify:update-auto-launch', (_, settings) => { - app.setLoginItemSettings(settings); - }); + await onFirstRunMaybe(); + + const mb = menubar({ + icon: idleIcon, + index: `file://${__dirname}/index.html`, + browserWindow: browserWindowOpts, + preloadWindow: true, + showDockIcon: false, + }); + + mb.on("ready", () => { + autoUpdater.checkForUpdatesAndNotify(); + + mb.app.setAppUserModelId("com.electron.gitify"); + + // Tray configuration + mb.tray.setIgnoreDoubleClickEvents(true); + mb.tray.on("right-click", (_event, bounds) => { + mb.tray.popUpContextMenu(contextMenu, { x: bounds.x, y: bounds.y }); + }); + + // Custom key events + mb.window.webContents.on("before-input-event", (event, input) => { + if (input.key === "Escape") { + mb.window.hide(); + event.preventDefault(); + } + }); + + // DevTools configuration + mb.window.webContents.on("devtools-opened", () => { + mb.window.setSize(800, 600); + mb.window.center(); + mb.window.resizable = true; + mb.window.setAlwaysOnTop(true); + }); + + mb.window.webContents.on("devtools-closed", () => { + const trayBounds = mb.tray.getBounds(); + mb.window.setSize(browserWindowOpts.width, browserWindowOpts.height); + mb.positioner.move("trayCenter", trayBounds); + mb.window.resizable = false; + }); + }); + + nativeTheme.on("updated", () => { + if (nativeTheme.shouldUseDarkColors) { + mb.window.webContents.send("gitify:update-theme", "DARK"); + } else { + mb.window.webContents.send("gitify:update-theme", "LIGHT"); + } + }); + + autoUpdater.on("checking-for-update", () => { + console.log("Checking for update..."); + // TODO - display the update status in the UI + }); + autoUpdater.on("update-available", (info) => { + console.log("Update available."); + // TODO - display the update status in the UI + }); + autoUpdater.on("update-not-available", (info) => { + console.log("Update not available."); + // TODO - display the update status in the UI + }); + + /** + * Gitify custom IPC events + */ + ipc.handle("gitify:version", () => app.getVersion()); + + ipc.on("gitify:window-show", () => mb.showWindow()); + + ipc.on("gitify:window-hide", () => mb.hideWindow()); + + ipc.on("gitify:quit", () => mb.app.quit()); + + ipc.on("gitify:icon-active", () => { + if (!mb.tray.isDestroyed()) { + mb.tray.setImage(activeIcon); + } + }); + + ipc.on("gitify:icon-idle", () => { + if (!mb.tray.isDestroyed()) { + mb.tray.setImage(idleIcon); + } + }); + + ipc.on("gitify:update-title", (_, title) => { + if (!mb.tray.isDestroyed()) { + mb.tray.setTitle(title); + } + }); + + ipc.on( + "gitify:update-keyboard-shortcut", + (_, { enabled, keyboardShortcut }) => { + if (!enabled) { + globalShortcut.unregister(keyboardShortcut); + return; + } + + globalShortcut.register(keyboardShortcut, () => { + if (mb.window.isVisible()) { + mb.hideWindow(); + } else { + mb.showWindow(); + } + }); + }, + ); + + ipc.on("gitify:update-auto-launch", (_, settings) => { + app.setLoginItemSettings(settings); + }); }); From 846cd97b19d7eb7c782288ca0eb3200d216638b0 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 22 Jul 2024 07:52:56 +1000 Subject: [PATCH 04/19] feat: check for updates --- src/electron/main.js | 316 +++++++++++++++++++++---------------------- 1 file changed, 158 insertions(+), 158 deletions(-) diff --git a/src/electron/main.js b/src/electron/main.js index 35bae7f39..824d58ec9 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -1,175 +1,175 @@ const { - ipcMain: ipc, - app, - nativeTheme, - globalShortcut, - Menu, -} = require("electron/main"); -const { menubar } = require("menubar"); -const { autoUpdater } = require("electron-updater"); -const { onFirstRunMaybe } = require("./first-run"); -const path = require("node:path"); + ipcMain: ipc, + app, + nativeTheme, + globalShortcut, + Menu, +} = require('electron/main'); +const { menubar } = require('menubar'); +const { autoUpdater } = require('electron-updater'); +const { onFirstRunMaybe } = require('./first-run'); +const path = require('node:path'); // TODO: Remove @electron/remote use - see #650 -require("@electron/remote/main").initialize(); +require('@electron/remote/main').initialize(); const idleIcon = path.resolve( - `${__dirname}/../../assets/images/tray-idleTemplate.png`, + `${__dirname}/../../assets/images/tray-idleTemplate.png`, ); const activeIcon = path.resolve( - `${__dirname}/../../assets/images/tray-active.png`, + `${__dirname}/../../assets/images/tray-active.png`, ); const browserWindowOpts = { - width: 500, - height: 400, - minWidth: 500, - minHeight: 400, - resizable: false, - webPreferences: { - enableRemoteModule: true, - nodeIntegration: true, - contextIsolation: false, - }, + width: 500, + height: 400, + minWidth: 500, + minHeight: 400, + resizable: false, + webPreferences: { + enableRemoteModule: true, + nodeIntegration: true, + contextIsolation: false, + }, }; const contextMenu = Menu.buildFromTemplate([ - { - role: "reload", - }, - { - role: "toggleDevTools", - }, - { type: "separator" }, - { - label: "Check for updates", - click: () => { - autoUpdater.checkForUpdatesAndNotify(); - }, - }, - { - label: "Quit", - click: () => { - app.quit(); - }, - }, + { + role: 'reload', + }, + { + role: 'toggleDevTools', + }, + { type: 'separator' }, + { + label: 'Check for updates', + click: () => { + autoUpdater.checkForUpdatesAndNotify(); + }, + }, + { + label: 'Quit', + click: () => { + app.quit(); + }, + }, ]); app.whenReady().then(async () => { - await onFirstRunMaybe(); - - const mb = menubar({ - icon: idleIcon, - index: `file://${__dirname}/index.html`, - browserWindow: browserWindowOpts, - preloadWindow: true, - showDockIcon: false, - }); - - mb.on("ready", () => { - autoUpdater.checkForUpdatesAndNotify(); - - mb.app.setAppUserModelId("com.electron.gitify"); - - // Tray configuration - mb.tray.setIgnoreDoubleClickEvents(true); - mb.tray.on("right-click", (_event, bounds) => { - mb.tray.popUpContextMenu(contextMenu, { x: bounds.x, y: bounds.y }); - }); - - // Custom key events - mb.window.webContents.on("before-input-event", (event, input) => { - if (input.key === "Escape") { - mb.window.hide(); - event.preventDefault(); - } - }); - - // DevTools configuration - mb.window.webContents.on("devtools-opened", () => { - mb.window.setSize(800, 600); - mb.window.center(); - mb.window.resizable = true; - mb.window.setAlwaysOnTop(true); - }); - - mb.window.webContents.on("devtools-closed", () => { - const trayBounds = mb.tray.getBounds(); - mb.window.setSize(browserWindowOpts.width, browserWindowOpts.height); - mb.positioner.move("trayCenter", trayBounds); - mb.window.resizable = false; - }); - }); - - nativeTheme.on("updated", () => { - if (nativeTheme.shouldUseDarkColors) { - mb.window.webContents.send("gitify:update-theme", "DARK"); - } else { - mb.window.webContents.send("gitify:update-theme", "LIGHT"); - } - }); - - autoUpdater.on("checking-for-update", () => { - console.log("Checking for update..."); - // TODO - display the update status in the UI - }); - autoUpdater.on("update-available", (info) => { - console.log("Update available."); - // TODO - display the update status in the UI - }); - autoUpdater.on("update-not-available", (info) => { - console.log("Update not available."); - // TODO - display the update status in the UI - }); - - /** - * Gitify custom IPC events - */ - ipc.handle("gitify:version", () => app.getVersion()); - - ipc.on("gitify:window-show", () => mb.showWindow()); - - ipc.on("gitify:window-hide", () => mb.hideWindow()); - - ipc.on("gitify:quit", () => mb.app.quit()); - - ipc.on("gitify:icon-active", () => { - if (!mb.tray.isDestroyed()) { - mb.tray.setImage(activeIcon); - } - }); - - ipc.on("gitify:icon-idle", () => { - if (!mb.tray.isDestroyed()) { - mb.tray.setImage(idleIcon); - } - }); - - ipc.on("gitify:update-title", (_, title) => { - if (!mb.tray.isDestroyed()) { - mb.tray.setTitle(title); - } - }); - - ipc.on( - "gitify:update-keyboard-shortcut", - (_, { enabled, keyboardShortcut }) => { - if (!enabled) { - globalShortcut.unregister(keyboardShortcut); - return; - } - - globalShortcut.register(keyboardShortcut, () => { - if (mb.window.isVisible()) { - mb.hideWindow(); - } else { - mb.showWindow(); - } - }); - }, - ); - - ipc.on("gitify:update-auto-launch", (_, settings) => { - app.setLoginItemSettings(settings); - }); + await onFirstRunMaybe(); + + const mb = menubar({ + icon: idleIcon, + index: `file://${__dirname}/index.html`, + browserWindow: browserWindowOpts, + preloadWindow: true, + showDockIcon: false, + }); + + mb.on('ready', () => { + autoUpdater.checkForUpdatesAndNotify(); + + mb.app.setAppUserModelId('com.electron.gitify'); + + // Tray configuration + mb.tray.setIgnoreDoubleClickEvents(true); + mb.tray.on('right-click', (_event, bounds) => { + mb.tray.popUpContextMenu(contextMenu, { x: bounds.x, y: bounds.y }); + }); + + // Custom key events + mb.window.webContents.on('before-input-event', (event, input) => { + if (input.key === 'Escape') { + mb.window.hide(); + event.preventDefault(); + } + }); + + // DevTools configuration + mb.window.webContents.on('devtools-opened', () => { + mb.window.setSize(800, 600); + mb.window.center(); + mb.window.resizable = true; + mb.window.setAlwaysOnTop(true); + }); + + mb.window.webContents.on('devtools-closed', () => { + const trayBounds = mb.tray.getBounds(); + mb.window.setSize(browserWindowOpts.width, browserWindowOpts.height); + mb.positioner.move('trayCenter', trayBounds); + mb.window.resizable = false; + }); + }); + + nativeTheme.on('updated', () => { + if (nativeTheme.shouldUseDarkColors) { + mb.window.webContents.send('gitify:update-theme', 'DARK'); + } else { + mb.window.webContents.send('gitify:update-theme', 'LIGHT'); + } + }); + + autoUpdater.on('checking-for-update', () => { + console.log('Checking for update...'); + // TODO - display the update status in the UI + }); + autoUpdater.on('update-available', (info) => { + console.log('Update available.'); + // TODO - display the update status in the UI + }); + autoUpdater.on('update-not-available', (info) => { + console.log('Update not available.'); + // TODO - display the update status in the UI + }); + + /** + * Gitify custom IPC events + */ + ipc.handle('gitify:version', () => app.getVersion()); + + ipc.on('gitify:window-show', () => mb.showWindow()); + + ipc.on('gitify:window-hide', () => mb.hideWindow()); + + ipc.on('gitify:quit', () => mb.app.quit()); + + ipc.on('gitify:icon-active', () => { + if (!mb.tray.isDestroyed()) { + mb.tray.setImage(activeIcon); + } + }); + + ipc.on('gitify:icon-idle', () => { + if (!mb.tray.isDestroyed()) { + mb.tray.setImage(idleIcon); + } + }); + + ipc.on('gitify:update-title', (_, title) => { + if (!mb.tray.isDestroyed()) { + mb.tray.setTitle(title); + } + }); + + ipc.on( + 'gitify:update-keyboard-shortcut', + (_, { enabled, keyboardShortcut }) => { + if (!enabled) { + globalShortcut.unregister(keyboardShortcut); + return; + } + + globalShortcut.register(keyboardShortcut, () => { + if (mb.window.isVisible()) { + mb.hideWindow(); + } else { + mb.showWindow(); + } + }); + }, + ); + + ipc.on('gitify:update-auto-launch', (_, settings) => { + app.setLoginItemSettings(settings); + }); }); From 50b0e69c19d38c53d38f9ce4894d94ed89534904 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 22 Jul 2024 09:30:03 +1000 Subject: [PATCH 05/19] feat: check for updates --- src/components/settings/SettingsFooter.tsx | 36 ++++++++++++++++++++-- src/electron/main.js | 19 +++++++----- src/types.ts | 5 +++ 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/components/settings/SettingsFooter.tsx b/src/components/settings/SettingsFooter.tsx index 54d4c4708..74c66269e 100644 --- a/src/components/settings/SettingsFooter.tsx +++ b/src/components/settings/SettingsFooter.tsx @@ -1,13 +1,20 @@ -import { PersonIcon, XCircleIcon } from '@primer/octicons-react'; +import { + AlertFillIcon, + CheckCircleFillIcon, + PersonIcon, + XCircleIcon, +} from '@primer/octicons-react'; +import { ipcRenderer } from 'electron'; import { type FC, useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { BUTTON_CLASS_NAME } from '../../styles/gitify'; -import { Size } from '../../types'; +import { IconColor, Size, VersionCheck } from '../../types'; import { getAppVersion, quitApp } from '../../utils/comms'; import { openGitifyReleaseNotes } from '../../utils/links'; export const SettingsFooter: FC = () => { const [appVersion, setAppVersion] = useState(null); + const [newVersionAvailable, setNewVersionAvailable] = useState(false); const navigate = useNavigate(); useEffect(() => { @@ -21,6 +28,15 @@ export const SettingsFooter: FC = () => { })(); }, []); + useEffect(() => { + ipcRenderer.on( + 'gitify:version-check', + (_, version: VersionCheck, _info: string) => { + setNewVersionAvailable(version === VersionCheck.UPDATE_AVAILABLE); + }, + ); + }, []); + return (
From b2ed9b20a53ab6de389b2ebe4f5d7d3e7f30357b Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 23 Jul 2024 06:56:27 +1000 Subject: [PATCH 11/19] feat: check for updates --- src/components/settings/SettingsFooter.tsx | 15 +++--- src/electron/main.js | 55 +++++++++++++--------- src/types.ts | 5 -- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/components/settings/SettingsFooter.tsx b/src/components/settings/SettingsFooter.tsx index d8ba315c5..3edf7e4b8 100644 --- a/src/components/settings/SettingsFooter.tsx +++ b/src/components/settings/SettingsFooter.tsx @@ -8,13 +8,13 @@ import { ipcRenderer } from 'electron'; import { type FC, useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { BUTTON_CLASS_NAME } from '../../styles/gitify'; -import { AutoUpdaterCheck, IconColor, Size } from '../../types'; +import { IconColor, Size } from '../../types'; import { getAppVersion, quitApp } from '../../utils/comms'; import { openGitifyReleaseNotes } from '../../utils/links'; export const SettingsFooter: FC = () => { const [appVersion, setAppVersion] = useState(null); - const [newVersionAvailable, setNewVersionAvailable] = useState(false); + const [isUpdateAvailable, setIsUpdateAvailable] = useState(false); const navigate = useNavigate(); useEffect(() => { @@ -29,12 +29,9 @@ export const SettingsFooter: FC = () => { }, []); useEffect(() => { - ipcRenderer.on( - 'gitify:auto-updater', - (_, version: AutoUpdaterCheck, _info: string) => { - setNewVersionAvailable(version === AutoUpdaterCheck.UPDATE_AVAILABLE); - }, - ); + ipcRenderer.on('gitify:auto-updater', (_, isUpdateAvailable: boolean) => { + setIsUpdateAvailable(isUpdateAvailable); + }); }, []); return ( @@ -47,7 +44,7 @@ export const SettingsFooter: FC = () => { > Gitify {appVersion} - {newVersionAvailable ? ( + {isUpdateAvailable ? ( diff --git a/src/electron/main.js b/src/electron/main.js index 5b642c8bc..1c4cd25f5 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -36,20 +36,37 @@ const browserWindowOpts = { }, }; +let isUpdateAvailable = false; +let isUpdateDownloaded = false; + const contextMenu = Menu.buildFromTemplate([ { - role: 'reload', + label: 'Check for updates', + click: () => { + checkForUpdates(); + }, }, { - role: 'toggleDevTools', + label: 'An update is available', + enabled: false, + visible: isUpdateAvailable, }, - { type: 'separator' }, { - label: 'Check for updates', + label: 'Restart to update', + visible: isUpdateDownloaded, click: () => { - checkForUpdates(); + autoUpdater.quitAndInstall(); }, }, + { type: 'separator' }, + + { + role: 'reload', + }, + { + role: 'toggleDevTools', + }, + { type: 'separator' }, { label: 'Quit', click: () => { @@ -105,29 +122,21 @@ app.whenReady().then(async () => { checkForUpdates(); setInterval(checkForUpdates, 24 * 60 * 60 * 1000); // 24 hours - autoUpdater.on('update-available', (info) => { - log.info('Auto Updater: New update available', info); - mb.window.webContents.send( - 'gitify:auto-updater', - 'UPDATE_AVAILABLE', - info, - ); + autoUpdater.on('update-available', () => { + log.info('Auto Updater: New update available'); + isUpdateAvailable = true; + mb.window.webContents.send('gitify:auto-updater', isUpdateAvailable); }); - autoUpdater.on('update-not-available', (info) => { + autoUpdater.on('update-not-available', () => { log.info('Auto Updater: Already on the latest version'); - mb.window.webContents.send( - 'gitify:auto-updater', - 'UPDATE_NOT_AVAILABLE', - info, - ); + isUpdateAvailable = false; + mb.window.webContents.send('gitify:auto-updater', isUpdateAvailable); }); - autoUpdater.on('update-downloaded', (_info) => { - log.info('Auto Updater: Update downloaded; will install in 5 seconds'); - setTimeout(() => { - autoUpdater.quitAndInstall(); - }, 5000); + autoUpdater.on('update-downloaded', () => { + log.info('Auto Updater: Update downloaded'); + isUpdateDownloaded = true; }); }); diff --git a/src/types.ts b/src/types.ts index 058b83b66..a51c648e5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -105,11 +105,6 @@ export enum Theme { DARK = 'DARK', } -export enum AutoUpdaterCheck { - UPDATE_AVAILABLE = 'UPDATE_AVAILABLE', - UPDATE_NOT_AVAILABLE = 'UPDATE_NOT_AVAILABLE', -} - export enum OpenPreference { FOREGROUND = 'FOREGROUND', BACKGROUND = 'FOREGROUND', From b93a53daa328fdacc708a7bad8893a67e471d126 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 23 Jul 2024 09:07:17 +1000 Subject: [PATCH 12/19] feat: check for updates --- src/electron/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/electron/main.js b/src/electron/main.js index 1c4cd25f5..43818eab5 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -173,7 +173,7 @@ app.whenReady().then(async () => { ipc.on('gitify:update-title', (_, title) => { if (!mb.tray.isDestroyed()) { - mb.tray.setTitle(title); + mb.tray.setTitle(`${isUpdateAvailable ? '⬇ ' : ''}${title}`); } }); From dcadc3022009060358dd9a77768202d02dc11eea Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 23 Jul 2024 09:17:51 +1000 Subject: [PATCH 13/19] feat: check for updates --- src/electron/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/electron/main.js b/src/electron/main.js index 43818eab5..5a0e80b49 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -36,7 +36,7 @@ const browserWindowOpts = { }, }; -let isUpdateAvailable = false; +let isUpdateAvailable = true; let isUpdateDownloaded = false; const contextMenu = Menu.buildFromTemplate([ @@ -173,7 +173,7 @@ app.whenReady().then(async () => { ipc.on('gitify:update-title', (_, title) => { if (!mb.tray.isDestroyed()) { - mb.tray.setTitle(`${isUpdateAvailable ? '⬇ ' : ''}${title}`); + mb.tray.setTitle(`${isUpdateAvailable ? '⤓' : ''}${title}`); } }); From cfab571f7ed4963baaf8603560a2605027e7d8e0 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 23 Jul 2024 09:18:46 +1000 Subject: [PATCH 14/19] feat: check for updates --- src/electron/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/electron/main.js b/src/electron/main.js index 5a0e80b49..d9e64fbeb 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -36,7 +36,7 @@ const browserWindowOpts = { }, }; -let isUpdateAvailable = true; +let isUpdateAvailable = false; let isUpdateDownloaded = false; const contextMenu = Menu.buildFromTemplate([ From b9477816f621fdf6b0a2dff62e44a8dde457fa52 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 22 Jul 2024 21:42:11 -0400 Subject: [PATCH 15/19] hide check for updates if one is available --- src/electron/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/electron/main.js b/src/electron/main.js index 86beb219d..f00e98584 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -42,6 +42,7 @@ let isUpdateDownloaded = false; const contextMenu = Menu.buildFromTemplate([ { label: 'Check for updates', + visible: !isUpdateAvailable, click: () => { checkForUpdates(); }, From 382d6a8e7c98805e156c1fa83f4c6368dbba7245 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 24 Jul 2024 02:43:59 +1000 Subject: [PATCH 16/19] Merge branch 'main' into feature/check-for-updates --- src/electron/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/electron/main.js b/src/electron/main.js index 4dce2ab39..078b31646 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -128,7 +128,7 @@ app.whenReady().then(async () => { mb.window.resizable = false; }); - // Auto Update + // Auto Updater checkForUpdates(); setInterval(checkForUpdates, 24 * 60 * 60 * 1000); // 24 hours From f834c5c754d0f4a33ec9ca77a944f4f7ba091c8b Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 24 Jul 2024 04:36:45 +1000 Subject: [PATCH 17/19] increase coverage --- .../settings/SettingsFooter.test.tsx | 42 +++++++++++++++++++ src/components/settings/SettingsFooter.tsx | 16 ++++--- .../SettingsFooter.test.tsx.snap | 42 +++++++++++++++++++ src/routes/Settings.tsx | 13 +++++- 4 files changed, 102 insertions(+), 11 deletions(-) diff --git a/src/components/settings/SettingsFooter.test.tsx b/src/components/settings/SettingsFooter.test.tsx index 365593422..5e0b23c0b 100644 --- a/src/components/settings/SettingsFooter.test.tsx +++ b/src/components/settings/SettingsFooter.test.tsx @@ -76,6 +76,48 @@ describe('routes/components/settings/SettingsFooter.tsx', () => { }); }); + describe('update available visual indicator', () => { + it('using latest version', async () => { + await act(async () => { + render( + + + + + , + ); + }); + + expect( + screen.getByTitle('You are using the latest version'), + ).toMatchSnapshot(); + }); + + it('new version available', async () => { + await act(async () => { + render( + + + + + , + ); + }); + + expect(screen.getByTitle('New version available')).toMatchSnapshot(); + }); + }); + it('should open release notes', async () => { process.env = { ...originalEnv, diff --git a/src/components/settings/SettingsFooter.tsx b/src/components/settings/SettingsFooter.tsx index 3edf7e4b8..2485f0171 100644 --- a/src/components/settings/SettingsFooter.tsx +++ b/src/components/settings/SettingsFooter.tsx @@ -4,7 +4,6 @@ import { PersonIcon, XCircleIcon, } from '@primer/octicons-react'; -import { ipcRenderer } from 'electron'; import { type FC, useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { BUTTON_CLASS_NAME } from '../../styles/gitify'; @@ -12,9 +11,14 @@ import { IconColor, Size } from '../../types'; import { getAppVersion, quitApp } from '../../utils/comms'; import { openGitifyReleaseNotes } from '../../utils/links'; -export const SettingsFooter: FC = () => { +interface ISettingsFooter { + isUpdateAvailable?: boolean; +} + +export const SettingsFooter: FC = ({ + isUpdateAvailable = false, +}: ISettingsFooter) => { const [appVersion, setAppVersion] = useState(null); - const [isUpdateAvailable, setIsUpdateAvailable] = useState(false); const navigate = useNavigate(); useEffect(() => { @@ -28,12 +32,6 @@ export const SettingsFooter: FC = () => { })(); }, []); - useEffect(() => { - ipcRenderer.on('gitify:auto-updater', (_, isUpdateAvailable: boolean) => { - setIsUpdateAvailable(isUpdateAvailable); - }); - }, []); - return (
- +
); }; From 693ab5d68b53b8cd04a77f9bb7c85d5c1bd0ae1a Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 24 Jul 2024 05:00:09 +1000 Subject: [PATCH 18/19] adjust alignment --- src/components/settings/SettingsFooter.tsx | 33 +++++++++-------- .../__snapshots__/Settings.test.tsx.snap | 36 ++++++++++--------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/components/settings/SettingsFooter.tsx b/src/components/settings/SettingsFooter.tsx index 2485f0171..e53ca02ec 100644 --- a/src/components/settings/SettingsFooter.tsx +++ b/src/components/settings/SettingsFooter.tsx @@ -40,21 +40,26 @@ export const SettingsFooter: FC = ({ title="View release notes" onClick={() => openGitifyReleaseNotes(appVersion)} > - +
Gitify {appVersion} - {isUpdateAvailable ? ( - - - - ) : ( - - - - )} - + + {isUpdateAvailable ? ( + + + + ) : ( + + + + )} + +