mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-17 05:02:06 +00:00
fix memory leak +
in-app-menu updates menu only if needed
This commit is contained in:
6
index.js
6
index.js
@ -152,7 +152,13 @@ function createMainWindow() {
|
|||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let createdWindow = false;
|
||||||
app.on("browser-window-created", (event, win) => {
|
app.on("browser-window-created", (event, win) => {
|
||||||
|
//Ensure listeners aren't registered when creating input dialog
|
||||||
|
if(createdWindow){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
createdWindow = true;
|
||||||
loadPlugins(win);
|
loadPlugins(win);
|
||||||
|
|
||||||
win.webContents.on("did-fail-load", () => {
|
win.webContents.on("did-fail-load", () => {
|
||||||
|
|||||||
@ -16,7 +16,7 @@ const originalBuildMenu = Menu.buildFromTemplate;
|
|||||||
// This function natively gets called on all submenu so no more reason to use recursion
|
// This function natively gets called on all submenu so no more reason to use recursion
|
||||||
Menu.buildFromTemplate = (template) => {
|
Menu.buildFromTemplate = (template) => {
|
||||||
// Fix checkboxes and radio buttons
|
// Fix checkboxes and radio buttons
|
||||||
updateCheckboxesAndRadioButtons(template);
|
updateTemplate(template);
|
||||||
|
|
||||||
// return as normal
|
// return as normal
|
||||||
return originalBuildMenu(template);
|
return originalBuildMenu(template);
|
||||||
@ -55,22 +55,26 @@ function switchMenuVisibility() {
|
|||||||
win.webContents.send("updateMenu", visible);
|
win.webContents.send("updateMenu", visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCheckbox(item) {
|
function updateCheckboxesAndRadioButtons(item, isRadio, hasSubmenu) {
|
||||||
//check item
|
if (!isRadio) {
|
||||||
|
//fix checkbox
|
||||||
item.checked = !item.checked;
|
item.checked = !item.checked;
|
||||||
//update menu (closes it)
|
}
|
||||||
|
//update menu if radio / hasSubmenu
|
||||||
|
if (isRadio || hasSubmenu) {
|
||||||
win.webContents.send("updateMenu", true);
|
win.webContents.send("updateMenu", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update checkboxes/radio buttons
|
// Update checkboxes/radio buttons
|
||||||
function updateCheckboxesAndRadioButtons(template) {
|
function updateTemplate(template) {
|
||||||
for (let item of template) {
|
for (let item of template) {
|
||||||
// Change onClick of checkbox+radio
|
// Change onClick of checkbox+radio
|
||||||
if ((item.type === "checkbox" || item.type === "radio") && !item.fixed) {
|
if ((item.type === "checkbox" || item.type === "radio") && !item.fixed) {
|
||||||
let originalOnclick = item.click;
|
let originalOnclick = item.click;
|
||||||
item.click = (itemClicked) => {
|
item.click = (itemClicked) => {
|
||||||
originalOnclick(itemClicked);
|
originalOnclick(itemClicked);
|
||||||
checkCheckbox(itemClicked);
|
updateCheckboxesAndRadioButtons(itemClicked, item.type==='radio', item.hasSubmenu);
|
||||||
};
|
};
|
||||||
item.fixed = true;
|
item.fixed = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user