mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 02:31:45 +00:00
Refactor into switchMenuVisibility
This commit is contained in:
@ -19,38 +19,38 @@ mainMenuTemplate = function (winHook) {
|
|||||||
let win;
|
let win;
|
||||||
|
|
||||||
//check that menu doesn't get created twice
|
//check that menu doesn't get created twice
|
||||||
let isFixed = false;
|
let done = false;
|
||||||
|
|
||||||
module.exports = winImport => {
|
module.exports = winImport => {
|
||||||
win = winImport;
|
win = winImport;
|
||||||
// css for custom scrollbar + disable drag area(was causing bugs)
|
// css for custom scrollbar + disable drag area(was causing bugs)
|
||||||
injectCSS(win.webContents, path.join(__dirname, 'style.css'));
|
injectCSS(win.webContents, path.join(__dirname, 'style.css'));
|
||||||
win.on('ready-to-show', () => {
|
win.on('ready-to-show', () => {
|
||||||
//build new menu (once)
|
// (apparently ready-to-show is called twice)
|
||||||
if (!isFixed) {
|
if (done) {
|
||||||
let template = mainMenuTemplate(win);
|
return
|
||||||
let menu = Menu.buildFromTemplate(template);
|
|
||||||
Menu.setApplicationMenu(menu);
|
|
||||||
isFixed = true;
|
|
||||||
}
|
}
|
||||||
|
done = true;
|
||||||
|
let template = mainMenuTemplate(win);
|
||||||
|
let menu = Menu.buildFromTemplate(template);
|
||||||
|
Menu.setApplicationMenu(menu);
|
||||||
|
|
||||||
//register keyboard shortcut && hide menu if hideMenu is enabled
|
//register keyboard shortcut && hide menu if hideMenu is enabled
|
||||||
if (config.get('options.hideMenu')) {
|
if (config.get('options.hideMenu')) {
|
||||||
win.webContents.send('updateMenu', null);
|
switchMenuVisibility();
|
||||||
let enabled = false;
|
|
||||||
electronLocalshortcut.register(win, 'Esc', () => {
|
electronLocalshortcut.register(win, 'Esc', () => {
|
||||||
if (enabled) {
|
switchMenuVisibility();
|
||||||
win.webContents.send('updateMenu', null);
|
|
||||||
enabled = false;
|
|
||||||
} else {
|
|
||||||
win.webContents.send('updateMenu', true);
|
|
||||||
enabled = true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let visible = true;
|
||||||
|
function switchMenuVisibility() {
|
||||||
|
visible=!visible;
|
||||||
|
win.webContents.send('updateMenu',visible)
|
||||||
|
}
|
||||||
|
|
||||||
//go over each item in menu
|
//go over each item in menu
|
||||||
function fixCheck(ogTemplate) {
|
function fixCheck(ogTemplate) {
|
||||||
for (let position in ogTemplate) {
|
for (let position in ogTemplate) {
|
||||||
|
|||||||
Reference in New Issue
Block a user