Moved to minimize hide window instead of close

This commit is contained in:
Core 2022-07-30 09:35:47 +01:00
parent 5920e82a30
commit f50247d923
2 changed files with 56 additions and 31 deletions

View file

@ -1442,69 +1442,90 @@ export class BrowserWindow {
FULL_SCREEN: 3, FULL_SCREEN: 3,
}; };
let wndState = WND_STATE.NORMAL; let wndState = WND_STATE.NORMAL;
const win = BrowserWindow.win;
let isQuitting = false;
BrowserWindow.win.on("resize", (_: any) => { win.on("resize", (_: any) => {
const isMaximized = BrowserWindow.win.isMaximized(); const isMaximized = win.isMaximized();
const isMinimized = BrowserWindow.win.isMinimized(); const isMinimized = win.isMinimized();
const isFullScreen = BrowserWindow.win.isFullScreen(); const isFullScreen = win.isFullScreen();
const state = wndState; const state = wndState;
if (isMinimized && state !== WND_STATE.MINIMIZED) { if (isMinimized && state !== WND_STATE.MINIMIZED) {
wndState = WND_STATE.MINIMIZED; wndState = WND_STATE.MINIMIZED;
BrowserWindow.win.webContents.send('window-state-changed', 'minimized'); win.webContents.send('window-state-changed', 'minimized');
} else if (isFullScreen && state !== WND_STATE.FULL_SCREEN) { } else if (isFullScreen && state !== WND_STATE.FULL_SCREEN) {
wndState = WND_STATE.FULL_SCREEN; wndState = WND_STATE.FULL_SCREEN;
BrowserWindow.win.webContents.send('window-state-changed', 'fullscreen') win.webContents.send('window-state-changed', 'fullscreen')
} else if (isMaximized && state !== WND_STATE.MAXIMIZED) { } else if (isMaximized && state !== WND_STATE.MAXIMIZED) {
wndState = WND_STATE.MAXIMIZED; wndState = WND_STATE.MAXIMIZED;
BrowserWindow.win.webContents.send('window-state-changed', 'maximized') win.webContents.send('window-state-changed', 'maximized')
BrowserWindow.win.webContents.executeJavaScript(`app.chrome.maximized = true`); win.webContents.executeJavaScript(`app.chrome.maximized = true`);
} else if (state !== WND_STATE.NORMAL) { } else if (state !== WND_STATE.NORMAL) {
wndState = WND_STATE.NORMAL; wndState = WND_STATE.NORMAL;
BrowserWindow.win.webContents.send('window-state-changed', 'normal') win.webContents.send('window-state-changed', 'normal')
BrowserWindow.win.webContents.executeJavaScript( win.webContents.executeJavaScript(
`app.chrome.maximized = false` `app.chrome.maximized = false`
); );
} }
}); });
let isQuiting = false // let isQuiting = false
win.on("minimize", (e: any) => {
BrowserWindow.win.on("close", (event: Event) => { console.log("[Window - App.ts]", "Minimized")
if ((utils.getStoreValue('general.close_button_hide') || process.platform === "darwin") && !isQuiting) { if (process.platform !== "darwin" && utils.getStoreValue("general.close_button_hide")) {
event.preventDefault(); console.log("Minimizing")
BrowserWindow.win.hide(); e.preventDefault()
} else { win.hide();
BrowserWindow.win.webContents.executeJavaScript(`
window.localStorage.setItem("currentTrack", JSON.stringify(app.mk.nowPlayingItem));
window.localStorage.setItem("currentTime", JSON.stringify(app.mk.currentPlaybackTime));
window.localStorage.setItem("currentQueue", JSON.stringify(app.mk.queue._unplayedQueueItems));
ipcRenderer.send('stopGCast','');`)
BrowserWindow.win.destroy();
} }
}) })
win.on("close", (e: any) => {
console.log("[Window - App.ts] Closing")
if (process.platform === "darwin" && !isQuitting) {
console.log("[Window - App.ts]", "hide on close");
e.preventDefault()
win.hide()
}
win.webContents.executeJavaScript(`
window.localStorage.setItem("currentTrack", JSON.stringify(app.mk.nowPlayingItem));
window.localStorage.setItem("currentTime", JSON.stringify(app.mk.currentPlaybackTime));
window.localStorage.setItem("currentQueue", JSON.stringify(app.mk.queue._unplayedQueueItems));
ipcRenderer.send('stopGCast','');`)
})
app.on('before-quit', () => { app.on('before-quit', () => {
isQuiting = true console.log("[Window - App.ts] Before Quit")
isQuitting = true
}); });
app.on('activate', function () { app.on('activate', function () {
BrowserWindow.win.show() console.log("[Window - App.ts] Activate")
BrowserWindow.win.focus() win.show()
}); });
// Quit when all windows are closed. // Quit when all windows are closed.
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {
app.quit() app.quit()
} }
}) })
BrowserWindow.win.on("closed", () => { // BrowserWindow.win.on("close", (event: Event) => {
BrowserWindow.win = null; // if ((utils.getStoreValue('general.close_button_hide') || process.platform === "darwin") && !isQuiting) {
}); // event.preventDefault();
// BrowserWindow.win.hide();
// } else {
// BrowserWindow.win.webContents.executeJavaScript(`
// window.localStorage.setItem("currentTrack", JSON.stringify(app.mk.nowPlayingItem));
// window.localStorage.setItem("currentTime", JSON.stringify(app.mk.currentPlaybackTime));
// window.localStorage.setItem("currentQueue", JSON.stringify(app.mk.queue._unplayedQueueItems));
// ipcRenderer.send('stopGCast','');`)
// BrowserWindow.win.destroy();
// }
// })
// Set window Handler // Set window Handler
BrowserWindow.win.webContents.setWindowOpenHandler((x: any) => { BrowserWindow.win.webContents.setWindowOpenHandler((x: any) => {

View file

@ -19,6 +19,10 @@ window.CiderCache = CiderCache
window.CiderFrontAPI = CiderFrontAPI window.CiderFrontAPI = CiderFrontAPI
window.wsapi = wsapi window.wsapi = wsapi
window.onbeforeunload = () => {
console.log("[app] onbeforeunload")
}
if (app.cfg.advanced.disableLogging === true) { if (app.cfg.advanced.disableLogging === true) {
window.console = { window.console = {
log: function() {}, log: function() {},