Formatted store and settings, added label elements to all inputs in settings, renamed keybinds to keybindings, optimised some code

This commit is contained in:
Core 2022-04-29 17:02:59 +01:00
parent 796a717dca
commit c9a5fc546f
No known key found for this signature in database
GPG key ID: FE9BF1B547F8F3C6
4 changed files with 1160 additions and 985 deletions

View file

@ -2,12 +2,6 @@ import {app, Menu, shell} from "electron";
import {utils} from "../base/utils";
export default class Thumbar {
/**
* Private variables for interaction in plugins
*/
private _win: any;
private _app: any;
private _store: any;
/**
* Base Plugin Details (Eventually implemented into a GUI in settings)
@ -15,27 +9,225 @@ export default class Thumbar {
public name: string = 'Menubar Plugin';
public description: string = 'Creates the menubar';
public version: string = '1.0.0';
public author: string = 'Core / Quacksire';
/**
* Thumbnail Toolbar Assets
* NATIVE-IMAGE DOESN'T SUPPORT SVG
private icons: { [key: string]: Electron.NativeImage } = {
remoteIcon: nativeImage.createFromPath(join(utils.getPath('rendererPath'), 'views/svg/smartphone.svg')).toPNG(),
soundIcon: nativeImage.createFromPath(join(utils.getPath('rendererPath'), 'views/svg/headphones.svg')).toPNG(),
aboutIcon: nativeImage.createFromPath(join(utils.getPath('rendererPath'), 'views/svg/info.svg')).toPNG(),
settingsIcon: nativeImage.createFromPath(join(utils.getPath('rendererPath'), 'views/svg/settings.svg')).toPNG(),
logoutIcon: nativeImage.createFromPath(join(utils.getPath('rendererPath'), 'views/svg/log-out.svg')).toPNG(),
ciderIcon: nativeImage.createFromPath(join(utils.getPath('rendererPath'), 'assets/logocute.png')).toPNG(),
}
*/
public author: string = 'Core';
public contributors: string[] = ['Core', 'Qwack', 'Monochromish'];
/**
* Menubar Assets
* @private
*/
private isMac: boolean = process.platform === 'darwin';
private _menuTemplate: any;
private _menuTemplate: any = [
{
label: app.getName(),
submenu: [
{
label: 'About',
click: () => utils.getWindow().webContents.executeJavaScript(`app.appRoute('about')`)
},
{type: 'separator'},
{
label: 'Settings',
accelerator: utils.getStoreValue("general.keybindings.settings").join('+'),
click: () => utils.getWindow().webContents.executeJavaScript(`app.appRoute('settings')`)
},
{type: 'separator'},
{role: 'services'},
{type: 'separator'},
{role: 'hide'},
{role: 'hideOthers'},
{role: 'unhide'},
{type: 'separator'},
{role: 'quit'}
]
},
{
label: 'View',
submenu: [
{role: 'reload'},
{role: 'forceReload'},
{role: 'toggleDevTools'},
{type: 'separator'},
{role: 'resetZoom'},
{role: 'zoomIn'},
{role: 'zoomOut'},
{type: 'separator'},
{role: 'togglefullscreen'},
]
},
{
label: 'Window',
submenu: [
{role: 'minimize'},
{
label: 'Show',
click: () => utils.getWindow().show()
},
{role: 'zoom'},
...(this.isMac ? [
{type: 'separator'},
{role: 'front'},
{role: 'close'},
] : [
{role: 'close'},
]),
{
label: 'Edit',
submenu: [
{role: 'undo'},
{role: 'redo'},
{type: 'separator'},
{role: 'cut'},
{role: 'copy'},
{role: 'paste'},
]
},
{type: 'separator'},
{
label: 'Toggle Private Session',
accelerator: utils.getStoreValue("general.keybindings.togglePrivateSession").join('+'),
click: () => utils.getWindow().webContents.executeJavaScript(`app.cfg.general.privateEnabled = !app.cfg.general.privateEnabled`)
},
{type: 'separator'},
{
label: 'Web Remote',
accelerator: utils.getStoreValue("general.keybindings.webRemote").join('+'),
sublabel: 'Opens in external window',
click: () => utils.getWindow().webContents.executeJavaScript(`app.appRoute('remote-pair')`)
},
{
label: 'Audio Settings',
accelerator: utils.getStoreValue("general.keybindings.audioSettings").join('+'),
click: () => utils.getWindow().webContents.executeJavaScript(`app.modals.audioSettings = true`)
},
{
label: 'Plug-in Menu',
accelerator: utils.getStoreValue("general.keybindings.pluginMenu").join('+'),
click: () => utils.getWindow().webContents.executeJavaScript(`app.modals.pluginMenu = true`)
}
]
},
{
label: 'Controls',
submenu: [
{
label: 'Pause / Play',
accelerator: 'Space',
click: () => utils.getWindow().webContents.executeJavaScript(`app.SpacePause()`)
},
{
label: 'Next',
accelerator: 'CommandOrControl+Right',
click: () => utils.getWindow().webContents.executeJavaScript(`MusicKitInterop.next()`)
},
{
label: 'Previous',
accelerator: 'CommandOrControl+Left',
click: () => utils.getWindow().webContents.executeJavaScript(`MusicKitInterop.previous()`)
},
{type: 'separator'},
{
label: 'Volume Up',
accelerator: 'CommandOrControl+Up',
click: () => utils.getWindow().webContents.executeJavaScript(`app.volumeUp()`)
},
{
label: 'Volume Down',
accelerator: 'CommandOrControl+Down',
click: () => utils.getWindow().webContents.executeJavaScript(`app.volumeDown()`)
},
{
label: 'Browse',
accelerator: utils.getStoreValue("general.keybindings.browse").join('+'),
click: () => utils.getWindow().webContents.executeJavaScript(`app.appRoute('browse')`)
},
{type: 'separator'},
{
label: 'Artists',
accelerator: utils.getStoreValue("general.keybindings.artists").join('+'),
click: () => utils.getWindow().webContents.executeJavaScript(`app.appRoute('library-artists')`)
},
{
label: 'Search',
accelerator: utils.getStoreValue("general.keybindings.search").join('+'),
click: () => utils.getWindow().webContents.executeJavaScript(`app.appRoute('search')`)
},
{type: 'separator'},
{
label: 'Album',
accelerator: utils.getStoreValue("general.keybindings.albums").join('+'),
click: () => utils.getWindow().webContents.executeJavaScript(`app.appRoute('library-albums')`)
},
{type: 'separator'},
{
label: 'Cast To Devices',
accelerator: utils.getStoreValue("general.keybindings.castToDevices").join('+'),
click: () => utils.getWindow().webContents.executeJavaScript(`app.modals.castMenu = true`)
}
]
},
{
label: 'Account',
submenu: [
{
label: 'Account Settings',
click: () => utils.getWindow().webContents.executeJavaScript(`app.appRoute('apple-account-settings')`)
},
{
label: 'Sign Out',
click: () => utils.getWindow().webContents.executeJavaScript(`app.unauthorize()`)
}
]
},
{
label: 'Support',
role: 'help',
submenu: [
{
label: 'Discord',
click: () => shell.openExternal("https://discord.gg/AppleMusic").catch(console.error)
},
{
label: 'GitHub Wiki',
click: () => shell.openExternal("https://github.com/ciderapp/Cider/wiki/Troubleshooting").catch(console.error)
},
{type: 'separator'},
{
label: 'Report a...',
submenu: [
{
label: 'Bug',
click: () => shell.openExternal("https://github.com/ciderapp/Cider/issues/new?assignees=&labels=bug%2Ctriage&template=bug_report.yaml&title=%5BBug%5D%3A+").catch(console.error)
},
{
label: 'Feature Request',
click: () => shell.openExternal("https://github.com/ciderapp/Cider/discussions/new?category=feature-request").catch(console.error)
},
{
label: 'Translation Report/Request',
click: () => shell.openExternal("https://github.com/ciderapp/Cider/issues/new?assignees=&labels=%F0%9F%8C%90+Translations&template=translation.yaml&title=%5BTranslation%5D%3A+").catch(console.error)
},
]
},
{type: 'separator'},
{
label: 'View License',
click: () => shell.openExternal("https://github.com/ciderapp/Cider/blob/main/LICENSE").catch(console.error)
},
{type: 'separator'},
{
label: 'Toggle Developer Tools',
accelerator: utils.getStoreValue("general.keybindings.openDeveloperTools").join('+'),
click: () => utils.getWindow().webContents.openDevTools()
},
{
label: 'Open Configuration File in Editor',
click: () => utils.getStoreInstance().openInEditor()
}
]
}
];
/*******************************************************************************************
* Public Methods
@ -44,230 +236,14 @@ export default class Thumbar {
/**
* Runs on plugin load (Currently run on application start)
*/
constructor(utils: { getApp: () => any; getStore: () => any; getWindow: () => any; }) {
this._app = utils.getApp();
this._store = utils.getStore();
this._menuTemplate = [
{
label: app.getName(),
submenu: [
{
label: 'About',
click: () => this._win.webContents.executeJavaScript(`app.appRoute('about')`)
},
{type: 'separator'},
{
label: 'Settings',
accelerator: this._store.general.keybind.settings.join('+'),
click: () => this._win.webContents.executeJavaScript(`app.appRoute('settings')`)
},
{type: 'separator'},
{role: 'services'},
{type: 'separator'},
{role: 'hide'},
{role: 'hideOthers'},
{role: 'unhide'},
{type: 'separator'},
{role: 'quit'}
]
},
{
label: 'View',
submenu: [
{role: 'reload'},
{role: 'forceReload'},
{role: 'toggleDevTools'},
{type: 'separator'},
{role: 'resetZoom'},
{role: 'zoomIn'},
{role: 'zoomOut'},
{type: 'separator'},
{role: 'togglefullscreen'},
]
},
{
label: 'Window',
submenu: [
{role: 'minimize'},
{
label: 'Show',
click: () => utils.getWindow().show()
},
{role: 'zoom'},
...(this.isMac ? [
{type: 'separator'},
{role: 'front'},
{role: 'close'},
] : [
{role: 'close'},
]),
{
label: 'Edit',
submenu: [
{role: 'undo'},
{role: 'redo'},
{type: 'separator'},
{role: 'cut'},
{role: 'copy'},
{role: 'paste'},
]
},
{type: 'separator'},
{
label: 'Toggle Private Session',
accelerator: this._store.general.keybind.togglePrivateSession.join('+'),
click: () => this._win.webContents.executeJavaScript(`app.cfg.general.privateEnabled = !app.cfg.general.privateEnabled`)
},
{type: 'separator'},
{
label: 'Web Remote',
accelerator: this._store.general.keybind.webRemote.join('+'),
sublabel: 'Opens in external window',
click: () => this._win.webContents.executeJavaScript(`app.appRoute('remote-pair')`)
},
{
label: 'Audio Settings',
accelerator: this._store.general.keybind.audioSettings.join('+'),
click: () => this._win.webContents.executeJavaScript(`app.modals.audioSettings = true`)
},
{
label: 'Plug-in Menu',
accelerator: this._store.general.keybind.pluginMenu.join('+'),
click: () => this._win.webContents.executeJavaScript(`app.modals.pluginMenu = true`)
}
]
},
{
label: 'Controls',
submenu: [
{
label: 'Pause / Play',
accelerator: 'Space',
click: () => this._win.webContents.executeJavaScript(`app.SpacePause()`)
},
{
label: 'Next',
accelerator: 'CommandOrControl+Right',
click: () => this._win.webContents.executeJavaScript(`MusicKitInterop.next()`)
},
{
label: 'Previous',
accelerator: 'CommandOrControl+Left',
click: () => this._win.webContents.executeJavaScript(`MusicKitInterop.previous()`)
},
{type: 'separator'},
{
label: 'Volume Up',
accelerator: 'CommandOrControl+Up',
click: () => this._win.webContents.executeJavaScript(`app.volumeUp()`)
},
{
label: 'Volume Down',
accelerator: 'CommandOrControl+Down',
click: () => this._win.webContents.executeJavaScript(`app.volumeDown()`)
},
{
label: 'Browse',
accelerator: this._store.general.keybind.browse.join('+'),
click: () => this._win.webContents.executeJavaScript(`app.appRoute('browse')`)
},
{type: 'separator'},
{
label: 'Artists',
accelerator: this._store.general.keybind.artists.join('+'),
click: () => this._win.webContents.executeJavaScript(`app.appRoute('library-artists')`)
},
{
label: 'Search',
accelerator: this._store.general.keybind.search.join('+'),
click: () => this._win.webContents.executeJavaScript(`app.appRoute('search')`)
},
{type: 'separator'},
{
label: 'Album',
accelerator: this._store.general.keybind.albums.join('+'),
click: () => this._win.webContents.executeJavaScript(`app.appRoute('library-albums')`)
},
{type: 'separator'},
{
label: 'Cast To Devices',
accelerator: this._store.general.keybind.castToDevices.join('+'),
click: () => this._win.webContents.executeJavaScript(`app.modals.castMenu = true`)
}
]
},
{
label: 'Account',
submenu: [
{
label: 'Account Settings',
click: () => this._win.webContents.executeJavaScript(`app.appRoute('apple-account-settings')`)
},
{
label: 'Sign Out',
click: () => this._win.webContents.executeJavaScript(`app.unauthorize()`)
}
]
},
{
label: 'Support',
role: 'help',
submenu: [
{
label: 'Discord',
click: () => shell.openExternal("https://discord.gg/AppleMusic").catch(console.error)
},
{
label: 'GitHub Wiki',
click: () => shell.openExternal("https://github.com/ciderapp/Cider/wiki/Troubleshooting").catch(console.error)
},
{type: 'separator'},
{
label: 'Report a...',
submenu: [
{
label: 'Bug',
click: () => shell.openExternal("https://github.com/ciderapp/Cider/issues/new?assignees=&labels=bug%2Ctriage&template=bug_report.yaml&title=%5BBug%5D%3A+").catch(console.error)
},
{
label: 'Feature Request',
click: () => shell.openExternal("https://github.com/ciderapp/Cider/discussions/new?category=feature-request").catch(console.error)
},
{
label: 'Translation Report/Request',
click: () => shell.openExternal("https://github.com/ciderapp/Cider/issues/new?assignees=&labels=%F0%9F%8C%90+Translations&template=translation.yaml&title=%5BTranslation%5D%3A+").catch(console.error)
},
]
},
{type: 'separator'},
{
label: 'View License',
click: () => shell.openExternal("https://github.com/ciderapp/Cider/blob/main/LICENSE").catch(console.error)
},
{type: 'separator'},
{
label: 'Toggle Developer Tools',
accelerator: this._store.general.keybind.openDeveloperTools.join('+'),
click: () => this._win.webContents.openDevTools()
},
{
label: 'Open Configuration File in Editor',
click: () => this._store.openInEditor()
}
]
}
];
constructor(_utils: utils) {
console.debug(`[Plugin][${this.name}] Loading Complete.`);
}
/**
* Runs on app ready
*/
onReady(win: Electron.BrowserWindow): void {
this._win = win;
onReady(_win: Electron.BrowserWindow): void {
const menu = Menu.buildFromTemplate(this._menuTemplate);
Menu.setApplicationMenu(menu)
}