You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
4.8 KiB
204 lines
4.8 KiB
const { app, Menu } = require('electron')
|
|
// import { autoUpdater } from "electron-updater"
|
|
// const version = app.getVersion();
|
|
|
|
const isMac = process.platform === 'darwin'
|
|
|
|
function createMenu(win) {
|
|
let menu = null
|
|
const template = [
|
|
...(isMac ? [{
|
|
label: app.name,
|
|
submenu: [
|
|
{ role: 'about' },
|
|
{ type: 'separator' },
|
|
{ role: 'services' },
|
|
{ type: 'separator' },
|
|
{ type: 'separator' },
|
|
{
|
|
label: 'Preferences...',
|
|
accelerator: (() => isMac ? 'CmdOrCtrl+,' : 'Ctrl+,')(),
|
|
click: () => {
|
|
win.webContents.send("changeRouteTo", "/settings")
|
|
},
|
|
role: 'preferences'
|
|
},
|
|
{ type: 'separator' },
|
|
{ role: 'hide' },
|
|
{ role: 'hideothers' },
|
|
{ role: 'unhide' },
|
|
{ type: 'separator' },
|
|
{ role: 'quit' }
|
|
]
|
|
}] : []),
|
|
{
|
|
label: 'Edit',
|
|
submenu: [
|
|
{ role: 'undo' },
|
|
{ role: 'redo' },
|
|
{ type: 'separator' },
|
|
{ role: 'cut' },
|
|
{ role: 'copy' },
|
|
{ role: 'paste' },
|
|
...(isMac ? [
|
|
{ role: 'delete' },
|
|
{ role: 'selectAll' },
|
|
{ type: 'separator' },
|
|
{
|
|
label: 'Speech',
|
|
submenu: [
|
|
{ role: 'startspeaking' },
|
|
{ role: 'stopspeaking' }
|
|
]
|
|
}
|
|
] : [
|
|
{ role: 'delete' },
|
|
{ type: 'separator' },
|
|
{ role: 'selectAll' }
|
|
])
|
|
]
|
|
},
|
|
{
|
|
label: 'Controls',
|
|
submenu: [
|
|
{
|
|
label: 'Play',
|
|
accelerator: 'Space',
|
|
click: () => {
|
|
win.webContents.send("play")
|
|
},
|
|
},
|
|
{
|
|
label: 'Next',
|
|
accelerator: 'CmdOrCtrl+Right',
|
|
click: () => {
|
|
win.webContents.send("next")
|
|
},
|
|
},
|
|
{
|
|
label: 'Previous',
|
|
accelerator: 'CmdOrCtrl+Left',
|
|
click: () => {
|
|
win.webContents.send("previous")
|
|
},
|
|
},
|
|
{
|
|
label: 'Increase Volume',
|
|
accelerator: 'CmdOrCtrl+Up',
|
|
click: () => {
|
|
win.webContents.send("increaseVolume")
|
|
},
|
|
},
|
|
{
|
|
label: 'Decrease Volume',
|
|
accelerator: 'CmdOrCtrl+Down',
|
|
click: () => {
|
|
win.webContents.send("decreaseVolume")
|
|
},
|
|
},
|
|
{
|
|
label: 'Like',
|
|
accelerator: 'CmdOrCtrl+L',
|
|
click: () => {
|
|
win.webContents.send("like")
|
|
},
|
|
},
|
|
{
|
|
label: 'Repeat',
|
|
accelerator: 'Alt+R',
|
|
click: () => {
|
|
win.webContents.send("repeat")
|
|
},
|
|
},
|
|
{
|
|
label: 'Shuffle',
|
|
accelerator: 'Alt+S',
|
|
click: () => {
|
|
win.webContents.send("shuffle")
|
|
},
|
|
}
|
|
]
|
|
},
|
|
{
|
|
label: 'Window',
|
|
submenu: [
|
|
{ role: 'minimize' },
|
|
{ role: 'zoom' },
|
|
{ role: 'reload' },
|
|
{ role: 'forcereload' },
|
|
{ role: 'toggledevtools' },
|
|
{ type: 'separator' },
|
|
{ role: 'togglefullscreen' },
|
|
...(isMac ? [
|
|
{ type: 'separator' },
|
|
{ role: 'front' },
|
|
{ type: 'separator' },
|
|
{
|
|
role: 'window',
|
|
id: 'window',
|
|
label: 'Yes Play Music',
|
|
type: 'checkbox',
|
|
checked: true,
|
|
click: () => {
|
|
const current = menu.getMenuItemById('window')
|
|
if (current.checked === false) {
|
|
win.hide()
|
|
} else {
|
|
win.show()
|
|
}
|
|
},
|
|
}
|
|
] : [
|
|
{ role: 'close' }
|
|
])
|
|
]
|
|
},
|
|
{
|
|
label: 'Help',
|
|
submenu: [
|
|
{
|
|
label: 'Github',
|
|
click: async () => {
|
|
const { shell } = require('electron')
|
|
await shell.openExternal('https://github.com/qier222/YesPlayMusic')
|
|
}
|
|
},
|
|
{
|
|
label: 'Electron',
|
|
click: async () => {
|
|
const { shell } = require('electron')
|
|
await shell.openExternal('https://electronjs.org')
|
|
}
|
|
},
|
|
]
|
|
}
|
|
]
|
|
// for window
|
|
// if (process.platform === "win32") {
|
|
// template.push({
|
|
// label: "Help",
|
|
// submenu: [
|
|
// {
|
|
// label: `Current version v${version}`,
|
|
// enabled: false,
|
|
// },
|
|
// {
|
|
// label: "Check for update",
|
|
// accelerator: "Ctrl+U",
|
|
// click: (item, focusedWindow) => {
|
|
// win = focusedWindow;
|
|
// updateSource = "menu";
|
|
// autoUpdater.checkForUpdates();
|
|
// },
|
|
// },
|
|
// ],
|
|
// });
|
|
// }
|
|
menu = Menu.buildFromTemplate(template)
|
|
Menu.setApplicationMenu(menu)
|
|
}
|
|
|
|
module.exports = createMenu
|
|
|
|
|