diff options
| author | 8cy <[email protected]> | 2020-06-22 15:47:46 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-06-22 15:47:46 -0700 |
| commit | e34f19a50bda8de4812e9c2c364c303e1fd7ebfe (patch) | |
| tree | dd980c424adbb82771cd0fe41a5f4d7418af73f4 /menu.js | |
| download | monkey-type-desktop-e34f19a50bda8de4812e9c2c364c303e1fd7ebfe.tar.xz monkey-type-desktop-e34f19a50bda8de4812e9c2c364c303e1fd7ebfe.zip | |
woah :star:
Diffstat (limited to 'menu.js')
| -rw-r--r-- | menu.js | 181 |
1 files changed, 181 insertions, 0 deletions
@@ -0,0 +1,181 @@ +'use strict'; +const path = require('path'); +const { app, Menu, shell } = require('electron'); +const { + is, + appMenu, + aboutMenuItem, + openUrlMenuItem, + openNewGitHubIssue, + debugInfo +} = require('electron-util'); +const config = require('./config'); + +const showPreferences = () => { + // Show the app's preferences here +}; + +const helpSubmenu = [ + openUrlMenuItem({ + label: 'My Website', + url: 'https://kyzer.co/' + }), + openUrlMenuItem({ + label: 'Source Code', + url: 'https://github.com/8cy/MonkeyDesktop' + }), + { + label: 'Report an Issue…', + click() { + const body = ` +<!-- Please succinctly describe your issue and steps to reproduce it. --> + + +--- + +${debugInfo()}`; + + openNewGitHubIssue({ + user: '8cy', + repo: 'MonkeyDesktop', + body + }); + } + } +]; + +if (!is.macos) { + helpSubmenu.push( + { + type: 'separator' + }, + aboutMenuItem({ + icon: path.join(__dirname, 'static', 'icon.png'), + text: 'Made with love by Sin. Original Monkey Type web-application made by Miodec.' + }) + ); +} + +// Only pushed if debug mode. +const debugSubmenu = [ + { + label: 'Show Settings', + click() { + config.openInEditor(); + } + }, + { + label: 'Show App Data', + click() { + shell.openItem(app.getPath('userData')); + } + }, + { + type: 'separator' + }, + { + label: 'Delete Settings', + click() { + config.clear(); + app.relaunch(); + app.quit(); + } + }, + { + label: 'Delete App Data', + click() { + shell.moveItemToTrash(app.getPath('userData')); + app.relaunch(); + app.quit(); + } + } +]; + +const macosTemplate = [ + appMenu([ + { + label: 'Preferences…', + accelerator: 'Command+,', + click() { + showPreferences(); + } + } + ]), + { + role: 'fileMenu', + submenu: [ + { + label: 'Custom' + }, + { + type: 'separator' + }, + { + role: 'close' + } + ] + }, + { + role: 'editMenu' + }, + { + role: 'viewMenu' + }, + { + role: 'windowMenu' + }, + { + role: 'help', + submenu: helpSubmenu + } +]; + +// Linux and Windows +const otherTemplate = [ + { + role: 'fileMenu', + submenu: [ + { + label: 'Custom' + }, + { + type: 'separator' + }, + { + label: 'Settings', + accelerator: 'Control+,', + click() { + showPreferences(); + } + }, + { + type: 'separator' + }, + { + role: 'quit' + } + ] + }, + { + role: 'editMenu' + }, + { + role: 'viewMenu' + }, + { + role: 'help', + submenu: helpSubmenu + } +]; + +const template = process.platform === 'darwin' ? macosTemplate : otherTemplate; + +// Ideally, this should be un-commented and only pushed if in debug mode, but I find it pretty useful and chose to keep it in release. +//if (is.development) { + template.push({ + label: 'Debug', + submenu: debugSubmenu + }); +//} + +module.exports = Menu.buildFromTemplate(template); |