-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
178 additions
and
15 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
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,105 @@ | ||
const { app, Menu } = require('electron') | ||
const { checkForUpdates } = require('./updater') | ||
|
||
const isMac = process.platform === 'darwin' | ||
|
||
const template = [ | ||
// { role: 'appMenu' } | ||
...(isMac | ||
? [ | ||
{ | ||
label: app.name, | ||
submenu: [ | ||
{ role: 'about' }, | ||
{ type: 'separator' }, | ||
{ role: 'services' }, | ||
{ type: 'separator' }, | ||
{ role: 'hide' }, | ||
{ role: 'hideothers' }, | ||
{ role: 'unhide' }, | ||
{ type: 'separator' }, | ||
{ role: 'quit' } | ||
] | ||
} | ||
] | ||
: []), | ||
// { role: 'fileMenu' } | ||
{ | ||
label: 'File', | ||
submenu: [isMac ? { role: 'close' } : { role: 'quit' }] | ||
}, | ||
// { role: 'editMenu' } | ||
{ | ||
label: 'Edit', | ||
submenu: [ | ||
{ role: 'undo' }, | ||
{ role: 'redo' }, | ||
{ type: 'separator' }, | ||
{ role: 'cut' }, | ||
{ role: 'copy' }, | ||
{ role: 'paste' }, | ||
...(isMac | ||
? [ | ||
{ role: 'pasteAndMatchStyle' }, | ||
{ role: 'delete' }, | ||
{ role: 'selectAll' }, | ||
{ type: 'separator' }, | ||
{ | ||
label: 'Speech', | ||
submenu: [{ role: 'startspeaking' }, { role: 'stopspeaking' }] | ||
} | ||
] | ||
: [{ role: 'delete' }, { type: 'separator' }, { role: 'selectAll' }]) | ||
] | ||
}, | ||
// { role: 'viewMenu' } | ||
{ | ||
label: 'View', | ||
submenu: [ | ||
{ role: 'reload' }, | ||
{ role: 'forcereload' }, | ||
{ role: 'toggledevtools' }, | ||
{ type: 'separator' }, | ||
{ role: 'resetzoom' }, | ||
{ role: 'zoomin' }, | ||
{ role: 'zoomout' }, | ||
{ 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 For Updates', | ||
click: checkForUpdates | ||
}, | ||
{ | ||
label: 'Learn More', | ||
click: async () => { | ||
const { shell } = require('electron') | ||
await shell.openExternal('https://boostnote.io') | ||
} | ||
} | ||
] | ||
} | ||
] | ||
|
||
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,69 @@ | ||
/** | ||
* updater.js | ||
* | ||
* Please use manual update only when it is really required, otherwise please use recommended non-intrusive auto update. | ||
* | ||
* Import steps: | ||
* 1. create `updater.js` for the code snippet | ||
* 2. require `updater.js` for menu implementation, and set `checkForUpdates` callback from `updater` for the click property of `Check Updates...` MenuItem. | ||
*/ | ||
const { dialog } = require('electron') | ||
const { autoUpdater } = require('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'] | ||
}, | ||
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...' | ||
}, | ||
() => { | ||
setImmediate(() => autoUpdater.quitAndInstall()) | ||
} | ||
) | ||
}) | ||
|
||
// export this to MenuItem click callback | ||
function checkForUpdates(menuItem, focusedWindow, event) { | ||
updater = menuItem | ||
updater.enabled = false | ||
autoUpdater.checkForUpdates() | ||
} | ||
module.exports.checkForUpdates = checkForUpdates |
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