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,
};
let wndState = WND_STATE.NORMAL;
const win = BrowserWindow.win;
let isQuitting = false;
BrowserWindow.win.on("resize", (_: any) => {
const isMaximized = BrowserWindow.win.isMaximized();
const isMinimized = BrowserWindow.win.isMinimized();
const isFullScreen = BrowserWindow.win.isFullScreen();
win.on("resize", (_: any) => {
const isMaximized = win.isMaximized();
const isMinimized = win.isMinimized();
const isFullScreen = win.isFullScreen();
const state = wndState;
if (isMinimized && state !== 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) {
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) {
wndState = WND_STATE.MAXIMIZED;
BrowserWindow.win.webContents.send('window-state-changed', 'maximized')
BrowserWindow.win.webContents.executeJavaScript(`app.chrome.maximized = true`);
win.webContents.send('window-state-changed', 'maximized')
win.webContents.executeJavaScript(`app.chrome.maximized = true`);
} else if (state !== WND_STATE.NORMAL) {
wndState = WND_STATE.NORMAL;
BrowserWindow.win.webContents.send('window-state-changed', 'normal')
BrowserWindow.win.webContents.executeJavaScript(
win.webContents.send('window-state-changed', 'normal')
win.webContents.executeJavaScript(
`app.chrome.maximized = false`
);
}
});
let isQuiting = false
BrowserWindow.win.on("close", (event: Event) => {
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();
// let isQuiting = false
win.on("minimize", (e: any) => {
console.log("[Window - App.ts]", "Minimized")
if (process.platform !== "darwin" && utils.getStoreValue("general.close_button_hide")) {
console.log("Minimizing")
e.preventDefault()
win.hide();
}
})
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', () => {
isQuiting = true
console.log("[Window - App.ts] Before Quit")
isQuitting = true
});
app.on('activate', function () {
BrowserWindow.win.show()
BrowserWindow.win.focus()
console.log("[Window - App.ts] Activate")
win.show()
});
// Quit when all windows are 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') {
app.quit()
}
})
BrowserWindow.win.on("closed", () => {
BrowserWindow.win = null;
});
// BrowserWindow.win.on("close", (event: Event) => {
// 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
BrowserWindow.win.webContents.setWindowOpenHandler((x: any) => {

View file

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