From 401ba1c879a1760e8c9a0f6710c68b2946416682 Mon Sep 17 00:00:00 2001 From: Agampreet Singh <68941022+agam778@users.noreply.github.com> Date: Fri, 9 Jun 2023 22:09:31 +0530 Subject: [PATCH] Use autoUpdater for checking for updates if on macOS or Windows --- app/menu.js | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/app/menu.js b/app/menu.js index c110208..5a9e07c 100644 --- a/app/menu.js +++ b/app/menu.js @@ -3,6 +3,8 @@ const useragents = require("./useragents.json"); const { app, dialog, BrowserWindow } = require("electron"); const axios = require("axios"); const { clearActivity, setActivity } = require("./rpc"); +const { shell } = require("electron"); +const { autoUpdater } = require("electron-updater"); function getValueOrDefault(key, defaultValue) { const value = store.get(key); @@ -23,16 +25,30 @@ async function checkForUpdates() { const latestVersion = data.tag_name; if (currentVersion !== latestVersion) { - const updatedialog = dialog.showMessageBoxSync({ - type: "info", - title: "Update Available", - message: `Your App's version: ${currentVersion}\nLatest version: ${latestVersion}\n\nPlease update to the latest version.`, - buttons: ["Download", "Close"], - }); - if (updatedialog === 0) { - shell.openExternal( - "https://github.com/agam778/MS-365-Electron/releases/latest" - ); + if (process.platform === "win32" || process.platform === "darwin") { + autoUpdater.checkForUpdatesAndNotify().then((result) => { + if (result === null) { + dialog.showMessageBoxSync({ + type: "info", + title: "No Update Available", + message: `Current version: ${currentVersion}\nLatest version: ${latestVersion}\n\nYou are already using the latest version.`, + buttons: ["OK"], + }); + } + }); + return; + } else { + const updatedialog = dialog.showMessageBoxSync({ + type: "info", + title: "Update Available", + message: `Current version: ${currentVersion}\nLatest version: ${latestVersion}\n\nPlease update to the latest version.`, + buttons: ["Download", "Close"], + }); + if (updatedialog === 0) { + shell.openExternal( + "https://github.com/agam778/MS-365-Electron/releases/latest" + ); + } } } else { dialog.showMessageBoxSync({