-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract app menu & updater logic to separate modules
- Loading branch information
1 parent
73d2cfb
commit 8e0fc4b
Showing
3 changed files
with
145 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { app, shell, Menu } from 'electron' | ||
import updater from '@/app-updater' | ||
|
||
// const template = [] | ||
const name = app.getName() | ||
const isMac = process.platform === 'darwin' | ||
|
||
const template = [ | ||
// { role: 'appMenu' } | ||
...(isMac ? [{ | ||
label: name, | ||
submenu: [ | ||
{ | ||
label: 'About ' + name, | ||
role: 'about' | ||
}, | ||
{ | ||
label: 'Check for updates', | ||
click: async (menuItem) => { | ||
await updater.checkForUpdates(menuItem) | ||
} | ||
}, | ||
{ type: 'separator' }, | ||
{ role: 'hide' }, | ||
{ role: 'hideOthers' }, | ||
{ role: 'unhide' }, | ||
{ type: 'separator' }, | ||
{ | ||
label: 'Quit', | ||
accelerator: 'Command+Q', | ||
click() { app.quit(); } | ||
}, | ||
] | ||
}] : []), | ||
// { role: 'viewMenu' } | ||
{ | ||
label: 'View', | ||
submenu: [ | ||
{ role: 'reload' }, | ||
{ role: 'forceReload' }, | ||
{ role: 'toggleDevTools' }, | ||
{ type: 'separator' }, | ||
{ role: 'togglefullscreen' } | ||
] | ||
}, | ||
// { role: 'windowMenu' } | ||
{ | ||
label: 'Window', | ||
submenu: [ | ||
{ role: 'minimize' }, | ||
{ role: 'zoom' }, | ||
...(isMac ? [ | ||
{ type: 'separator' }, | ||
{ role: 'front' }, | ||
{ type: 'separator' }, | ||
{ role: 'window' } | ||
] : [ | ||
{ role: 'close' } | ||
]) | ||
] | ||
}, | ||
{ | ||
role: 'help', | ||
submenu: [ | ||
{ | ||
label: 'Check out the public repository', | ||
click: async () => await shell.openExternal('https://github.com/gwleuverink/clickup-time-tracker') | ||
}, | ||
{ | ||
label: 'Sponsor me on GitHub ❤', | ||
click: async () => await shell.openExternal('https://github.com/sponsors/gwleuverink') | ||
} | ||
] | ||
} | ||
] | ||
|
||
export async function createMenu() { | ||
const menu = Menu.buildFromTemplate(template); | ||
Menu.setApplicationMenu(menu); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { dialog } from 'electron' | ||
import { autoUpdater } from 'electron-updater' | ||
|
||
|
||
let updater | ||
autoUpdater.autoDownload = false; | ||
|
||
autoUpdater.on('error', (error) => { | ||
dialog.showErrorBox('Error: ', error == null ? "unknown" : (error.stack || error).toString()) | ||
}) | ||
|
||
autoUpdater.on('update-available', () => { | ||
dialog.showMessageBox({ | ||
type: 'info', | ||
title: 'Found Updates', | ||
message: 'Found updates, do you want update now?', | ||
buttons: ['Sure', 'No'] | ||
}).then((buttonIndex) => { | ||
|
||
if (buttonIndex === 0) { | ||
autoUpdater.downloadUpdate() | ||
} | ||
else { | ||
updater.enabled = true | ||
updater = null | ||
} | ||
}) | ||
}) | ||
|
||
autoUpdater.on('update-not-available', () => { | ||
dialog.showMessageBox({ | ||
title: 'No Updates', | ||
message: 'Current version is up-to-date.' | ||
}) | ||
updater.enabled = true | ||
updater = null | ||
}) | ||
|
||
autoUpdater.on('update-downloaded', () => { | ||
dialog.showMessageBox({ | ||
title: 'Install Updates', | ||
message: 'Updates downloaded, application will be quit for update...' | ||
}).then(() => { | ||
setImmediate(() => autoUpdater.quitAndInstall()) | ||
}) | ||
}) | ||
|
||
|
||
// export this to MenuItem click callback | ||
function checkForUpdates(menuItem) { | ||
updater = menuItem | ||
updater.enabled = false | ||
autoUpdater.checkForUpdates() | ||
} | ||
|
||
export default { | ||
checkForUpdates, | ||
checkForUpdatesAndNotify: autoUpdater.checkForUpdatesAndNotify, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters