fix hide-menu timing + minify log function

This commit is contained in:
Araxeus
2021-04-05 04:04:29 +03:00
parent 11bd1adbd4
commit 6472002f8a
2 changed files with 27 additions and 21 deletions

View File

@ -8,7 +8,9 @@ const { setApplicationMenu } = require("../../menu");
const { injectCSS } = require("../utils"); const { injectCSS } = require("../utils");
//check that menu doesn't get created twice //check that menu doesn't get created twice
let done = false; let calledReadyToShow = false;
//check menu state isn't changed twice
let calledFinishedLoad = false
//tracks menu visibility //tracks menu visibility
let visible = true; let visible = true;
// win hook for fixing menu // win hook for fixing menu
@ -32,23 +34,30 @@ module.exports = (winImport) => {
win.on("ready-to-show", () => { win.on("ready-to-show", () => {
// (apparently ready-to-show is called twice) // (apparently ready-to-show is called twice)
if (done) { if (calledReadyToShow) {
return; return;
} }
done = true; calledReadyToShow = true;
setApplicationMenu(win); setApplicationMenu(win);
//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")) {
switchMenuVisibility();
electronLocalshortcut.register(win, "Esc", () => { electronLocalshortcut.register(win, "Esc", () => {
switchMenuVisibility(); switchMenuVisibility();
}); });
} }
// fix bug with menu not applying on start when no internet connection available
setMenuVisibility(visible);
}); });
//set menu visibility on load
win.webContents.on("did-finish-load", () => {
if (calledFinishedLoad) {
return;
}
calledFinishedLoad = true;
// fix bug with menu not applying on start when no internet connection available
setMenuVisibility(!config.get("options.hideMenu"));
})
}; };
function switchMenuVisibility() { function switchMenuVisibility() {

View File

@ -3,12 +3,9 @@ const { ipcRenderer } = require("electron");
module.exports = () => { module.exports = () => {
ipcRenderer.on("log", (event, log) => { ipcRenderer.on("log", (event, log) => {
let string = log.toString() || log; let string = log.toString() || log;
if (string) { if (!string || string === "[object Object]") {
string = JSON.stringify(log);
}
console.log(string); console.log(string);
} else {
for (let propery of log) {
console.log(propery.toString() || propery);
}
}
}) })
} };