Merge pull request #1331 from ciderapp/bugfix/windowhide
Bugfix/windowhide
This commit is contained in:
commit
5d45295e6e
1 changed files with 26 additions and 33 deletions
|
@ -1442,70 +1442,63 @@ 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`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
win.on("close", (e: any) => {
|
||||||
let isQuiting = false
|
if ((process.platform === "darwin" || utils.getStoreValue("general.close_button_hide")) && !isQuitting) {
|
||||||
|
e.preventDefault()
|
||||||
BrowserWindow.win.on("close", (event: Event) => {
|
win.hide()
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
win.on("closed", (_: any) => {
|
||||||
|
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
|
isQuitting = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('activate', function () {
|
app.on('activate', function () {
|
||||||
BrowserWindow.win.show()
|
win.show()
|
||||||
BrowserWindow.win.focus()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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 = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set window Handler
|
// Set window Handler
|
||||||
BrowserWindow.win.webContents.setWindowOpenHandler((x: any) => {
|
BrowserWindow.win.webContents.setWindowOpenHandler((x: any) => {
|
||||||
if (x.url.includes("apple") || x.url.includes("localhost")) {
|
if (x.url.includes("apple") || x.url.includes("localhost")) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue