diff --git a/app/main/package.json b/app/main/package.json index 14416543..83fa3895 100644 --- a/app/main/package.json +++ b/app/main/package.json @@ -89,7 +89,7 @@ "electron-is-dev": "^2.0.0", "electron-updater": "^4.6.5", "lodash.debounce": "^4.0.8", - "node-notifier": "^8.0.2", + "node-notifier": "10.0.1", "universal-analytics": "^0.4.23", "uuid": "7.0.3", "v8-compile-cache": "^2.1.1" @@ -99,7 +99,7 @@ "@jest-runner/electron": "^3.0.0", "electron-devtools-installer": "^3.2.0", "@types/lodash.debounce": "^4.0.6", - "@types/node-notifier": "^6.0.1", + "@types/node-notifier": "8.0.2", "@types/universal-analytics": "^0.4.4", "@types/uuid": "7.0.3", "babel-core": "^6.26.3", diff --git a/app/main/src/main.ts b/app/main/src/main.ts index 30e2ca92..d3329a29 100644 --- a/app/main/src/main.ts +++ b/app/main/src/main.ts @@ -43,6 +43,8 @@ import { FullscreenState, setFullscreenBreakHandler, } from "./lifecycleEventHandlers/fullScreenBreak"; +import WindowsToaster from "node-notifier/notifiers/toaster"; +import NotificationCenter from "node-notifier/notifiers/notificationcenter"; const onProduction = app.isPackaged; @@ -241,6 +243,32 @@ function createSystemTray() { }); } +type NotificationProps = { + title: string; + message: string; + actions: string[]; + callback?: (err: Error | null, response: string) => void; +}; + +function notify(props: NotificationProps) { + // This is because it can take different types depending on the initialised OS. + // Just for some reason, whoever sorted the types out of this library only really considered JS rather than TS. + const notification: WindowsToaster.Notification & + NotificationCenter.Notification = { + icon: notificationIcon, + title: props.title, + message: props.message, + actions: props.actions, + appID: "com.roldanjr.pomatez", + sound: true, + wait: true, + }; + + notifier.notify(notification, (err, response) => { + if (props.callback) props.callback(err, response); + }); +} + if (!onlySingleInstance) { app.quit(); } else { @@ -303,40 +331,31 @@ if (!onlySingleInstance) { const autoUpdater = activateAutoUpdate({ onUpdateAvailable: (info) => { - notifier.notify( - { - icon: notificationIcon, - title: "NEW UPDATE IS AVAILABLE", - message: `App version ${info.version} ready to be downloaded.`, - actions: ["View Released Notes"], - sound: true, - wait: true, - }, - (err, response) => { + notify({ + title: "NEW UPDATE IS AVAILABLE", + message: `App version ${info.version} ready to be downloaded.`, + actions: ["View Released Notes"], + callback: (err, response) => { if (!err) { shell.openExternal(RELEASED_NOTES_LINK); } - } - ); + }, + }); }, onUpdateDownloaded: (info) => { - notifier.notify( - { - icon: notificationIcon, - title: "READY TO BE INSTALLED", - message: "Update has been successfully downloaded.", - actions: ["Quit and Install", "Install it Later"], - sound: true, - wait: true, - }, - (err, response) => { + notify({ + title: "READY TO BE INSTALLED", + message: "Update has been successfully downloaded.", + // Temporarily commented out due to an issue with snoretoast https://github.com/mikaelbr/node-notifier/issues/332 + actions: ["Quit and Install" /*, "Install it Later"*/], + callback: (err, response) => { if (!err) { - if (response === "quit and install") { - autoUpdater.quitAndInstall(); - } + //if (response === "quit and install") { + autoUpdater.quitAndInstall(); + //} } - } - ); + }, + }); }, }); }); diff --git a/yarn.lock b/yarn.lock index 97f9105a..999153bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3994,10 +3994,10 @@ resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197" integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA== -"@types/node-notifier@^6.0.1": - version "6.0.1" - resolved "https://registry.yarnpkg.com/@types/node-notifier/-/node-notifier-6.0.1.tgz#282bb8c37d69be3343c359efc8b9c97fad46a0e9" - integrity sha512-PBkKwgjxu2aA24zh5Rng8FlL03R4zopZbTtzeKbWLfF+AMeHBMk3Ls12K/yZchYhe/riuiarPXcRJGUBLGb15w== +"@types/node-notifier@8.0.2": + version "8.0.2" + resolved "https://registry.yarnpkg.com/@types/node-notifier/-/node-notifier-8.0.2.tgz#77c5de29c6e8adb915222b01864128cc3e78d553" + integrity sha512-5v0PhPv0AManpxT7W25Zipmj/Lxp1WqfkcpZHyqSloB+gGoAHRBuzhrCelFKrPvNF5ki3gAcO4kxaGO2/21u8g== dependencies: "@types/node" "*" @@ -12760,16 +12760,16 @@ node-machine-id@1.1.12: resolved "https://registry.yarnpkg.com/node-machine-id/-/node-machine-id-1.1.12.tgz#37904eee1e59b320bb9c5d6c0a59f3b469cb6267" integrity sha512-QNABxbrPa3qEIfrE6GOJ7BYIuignnJw7iQ2YPbc3Nla1HzRJjXzZOiikfF8m7eAMfichLt3M4VgLOetqgDmgGQ== -node-notifier@^8.0.2: - version "8.0.2" - resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-8.0.2.tgz#f3167a38ef0d2c8a866a83e318c1ba0efeb702c5" - integrity sha512-oJP/9NAdd9+x2Q+rfphB2RJCHjod70RcRLjosiPMMu5gjIfwVnOUGq2nbTjTUbmy0DJ/tFIVT30+Qe3nzl4TJg== +node-notifier@10.0.1: + version "10.0.1" + resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-10.0.1.tgz#0e82014a15a8456c4cfcdb25858750399ae5f1c7" + integrity sha512-YX7TSyDukOZ0g+gmzjB6abKu+hTGvO8+8+gIFDsRCU2t8fLV/P2unmt+LGFaIa4y64aX98Qksa97rgz4vMNeLQ== dependencies: growly "^1.3.0" is-wsl "^2.2.0" - semver "^7.3.2" + semver "^7.3.5" shellwords "^0.1.1" - uuid "^8.3.0" + uuid "^8.3.2" which "^2.0.2" node-releases@^2.0.13: @@ -17596,7 +17596,7 @@ uuid@^3.0.0, uuid@^3.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== -uuid@^8.3.0, uuid@^8.3.2: +uuid@^8.3.2: version "8.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==