-
Notifications
You must be signed in to change notification settings - Fork 108
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
6 changed files
with
86 additions
and
160 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
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 |
---|---|---|
@@ -1,128 +1,88 @@ | ||
import { app } from "electron"; | ||
import zoom from "./zoom"; | ||
import { app, Menu, dialog } from "electron"; | ||
import { updater, UpdateState } from "./updater"; | ||
import isDev from "electron-is-dev"; | ||
|
||
const menu: Electron.MenuItemConstructorOptions[] = [ | ||
{ | ||
label: "Application", | ||
submenu: [ | ||
{ | ||
label: "About Bdash", | ||
role: "about" | ||
}, | ||
{ | ||
type: "separator" | ||
}, | ||
{ | ||
label: "Hide Bdash", | ||
accelerator: "CmdOrCtrl+H", | ||
role: "hide" | ||
}, | ||
{ | ||
label: "Hide Others", | ||
accelerator: "Option+CmdOrCtrl+H", | ||
role: "hideothers" | ||
}, | ||
{ | ||
label: "Show All", | ||
role: "unhide" | ||
}, | ||
{ | ||
type: "separator" | ||
}, | ||
{ | ||
label: "Quit", | ||
accelerator: "CmdOrCtrl+Q", | ||
click: () => { | ||
app.quit(); | ||
} | ||
const editMenu: Electron.MenuItemConstructorOptions = { | ||
label: "Edit", | ||
submenu: [{ role: "cut" }, { role: "copy" }, { role: "paste" }, { role: "selectall" }] | ||
}; | ||
|
||
const viewMenu: Electron.MenuItemConstructorOptions = { | ||
label: "View", | ||
submenu: [ | ||
{ role: "toggledevtools" }, | ||
{ type: "separator" }, | ||
{ role: "resetzoom" }, | ||
{ role: "zoomin" }, | ||
{ role: "zoomout" } | ||
] | ||
}; | ||
|
||
if (isDev && Array.isArray(viewMenu.submenu)) { | ||
viewMenu.submenu.unshift({ role: "reload" }); | ||
} | ||
|
||
const windowMenu: Electron.MenuItemConstructorOptions = { | ||
role: "window", | ||
submenu: [{ role: "minimize" }, { role: "close" }] | ||
}; | ||
|
||
const helpMenu: Electron.MenuItemConstructorOptions = { | ||
role: "help", | ||
submenu: [ | ||
{ | ||
label: "Report Issue", | ||
click() { | ||
require("electron").shell.openExternal("https://github.com/bdash-app/bdash/issues/new"); | ||
} | ||
] | ||
}, | ||
{ | ||
label: "Edit", | ||
submenu: [ | ||
{ | ||
label: "Undo", | ||
accelerator: "CmdOrCtrl+Z", | ||
role: "undo" | ||
}, | ||
{ | ||
label: "Redo", | ||
accelerator: "Shift+CmdOrCtrl+Z", | ||
role: "redo" | ||
}, | ||
{ | ||
type: "separator" | ||
}, | ||
{ | ||
label: "Cut", | ||
accelerator: "CmdOrCtrl+X", | ||
role: "cut" | ||
}, | ||
{ | ||
label: "Copy", | ||
accelerator: "CmdOrCtrl+C", | ||
role: "copy" | ||
}, | ||
{ | ||
label: "Paste", | ||
accelerator: "CmdOrCtrl+V", | ||
role: "paste" | ||
}, | ||
{ | ||
label: "Select All", | ||
accelerator: "CmdOrCtrl+A", | ||
role: "selectall" | ||
} | ||
] | ||
}; | ||
|
||
const checkForUpdateItem = { | ||
label: "Check for Updates...", | ||
click() { | ||
switch (updater.state) { | ||
case UpdateState.UpdateNotAvailable: { | ||
const message = "There are currently no updates available."; | ||
dialog.showMessageBox({ message }); | ||
return; | ||
} | ||
] | ||
}, | ||
{ | ||
label: "View", | ||
submenu: [ | ||
{ | ||
label: "Zoom In", | ||
accelerator: "CmdOrCtrl+Plus", | ||
click: () => zoom.zoomIn() | ||
}, | ||
{ | ||
label: "Zoom Out", | ||
accelerator: "CmdOrCtrl+-", | ||
click: () => zoom.zoomOut() | ||
}, | ||
{ | ||
label: "Zoom Reset", | ||
accelerator: "CmdOrCtrl+0", | ||
click: () => zoom.reset() | ||
}, | ||
{ type: "separator" }, | ||
{ | ||
label: "Reload", | ||
accelerator: "CmdOrCtrl+Alt+R", | ||
click: (_, focusedWindow) => { | ||
if (focusedWindow) { | ||
focusedWindow.reload(); | ||
} | ||
} | ||
}, | ||
{ | ||
label: "Toggle Developer Tools", | ||
accelerator: process.platform === "darwin" ? "Alt+Command+I" : "Ctrl+Shift+I", | ||
click: (_, focusedWindow: any) => { | ||
if (focusedWindow) { | ||
focusedWindow.toggleDevTools(); | ||
case UpdateState.UpdateDownloaded: { | ||
const message = "There is an available update. Restart app to apply the latest update."; | ||
const buttons = ["Update Now", "Later"]; | ||
dialog.showMessageBox({ message, buttons }, buttonIndex => { | ||
if (buttonIndex === 0) { | ||
updater.quit(); | ||
} | ||
} | ||
}); | ||
return; | ||
} | ||
] | ||
}, | ||
{ | ||
label: "Window", | ||
role: "window", | ||
} | ||
} | ||
}; | ||
|
||
const template: Electron.MenuItemConstructorOptions[] = [editMenu, viewMenu, windowMenu, helpMenu]; | ||
|
||
if (process.platform === "darwin") { | ||
template.unshift({ | ||
label: app.getName(), | ||
submenu: [ | ||
{ label: "Minimize", accelerator: "CmdOrCtrl+M", role: "minimize" }, | ||
{ label: "Bring All to Front", role: "front" } | ||
{ role: "about" }, | ||
checkForUpdateItem, | ||
{ type: "separator" }, | ||
{ role: "hide" }, | ||
{ role: "hideothers" }, | ||
{ role: "unhide" }, | ||
{ type: "separator" }, | ||
{ role: "quit" } | ||
] | ||
} | ||
]; | ||
}); | ||
} else if (Array.isArray(helpMenu.submenu)) { | ||
helpMenu.submenu.push(checkForUpdateItem); | ||
} | ||
|
||
export default menu; | ||
export function initMenu() { | ||
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
This file was deleted.
Oops, something went wrong.
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