From b0fc14b228c631726f79289f2826185b754e9376 Mon Sep 17 00:00:00 2001 From: AbanobNageh Date: Sat, 13 Jan 2024 18:58:49 +0200 Subject: [PATCH] Saved the app's maximize state between uses. --- js/index.js | 21 ++++++++++++++++++++- main.js | 15 +++++++++++++++ preload.js | 3 +++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/js/index.js b/js/index.js index 9e061b3..6623a61 100644 --- a/js/index.js +++ b/js/index.js @@ -239,6 +239,7 @@ app = new Vue({ showWebPage: false, showTestResults: false, showConsole: false, + isMaximized: false, }, iframe_working: false, @@ -2521,6 +2522,16 @@ window.electronAPI.log((event, text, more_text = "") => { } }); +window.electronAPI.onAppMaximized(() => { + appOptionsChanged = true; + app.app_options.isMaximized = true; +}); + +window.electronAPI.onAppUnMaximized(() => { + appOptionsChanged = true; + app.app_options.isMaximized = false; +}); + //#endregion //#region Electron API wrappers @@ -2545,6 +2556,10 @@ function toggleFullScreen() { window.electronAPI.toggleFullScreen(); } +function maximizeApp() { + window.electronAPI.maximizeApp(); +} + /** * Returns the root directory of the app * @returns {Promise} Root-directory path @@ -2652,7 +2667,7 @@ async function loadAllConfigs() { displayChapterNumbers: false, }); - loadConfigData("app_options", { + await loadConfigData("app_options", { darkMode: true, showNewOnly: false, showCheckUpdatedOnly: false, @@ -2661,7 +2676,11 @@ async function loadAllConfigs() { showWebPage: false, showTestResults: false, showConsole: false, + isMaximized: false, }); + if (app.app_options.isMaximized) { + maximizeApp(); + } await loadConfigArrayData("rules"); app.loading_rules = false; diff --git a/main.js b/main.js index 3ad2e88..168a20d 100644 --- a/main.js +++ b/main.js @@ -104,6 +104,14 @@ const createWindow = () => { mainWindow.on("ready-to-show", () => { mainWindow.show(); + mainWindow.on('maximize', () => { + mainWindow.webContents.send("on-app-maximized"); + }); + + mainWindow.on('unmaximize', () => { + mainWindow.webContents.send("on-app-unmaximized"); + }); + //#region Disabling CORS session.defaultSession.webRequest.onHeadersReceived((details, callback) => { let url = details.url.toLowerCase(); @@ -183,6 +191,7 @@ function handleComs() { ipcMain.on("block-includes", urlIncludesToBlock); ipcMain.on("toggle-fullscreen", toggleFullScreen); ipcMain.on("app-relaunch", relaunchApp); + ipcMain.on("maximize-app", maximizeApp); ipcMain.handle("dir-create", createDirectory); ipcMain.handle("dir-root", rootDir); ipcMain.handle("file-read", readFile); @@ -310,6 +319,12 @@ async function updateApp(e, appZipUrl = "") { } } +function maximizeApp() { + if (!mainWindow.isMaximized()) { + mainWindow.maximize(); + } +} + function relaunchApp() { app.relaunch(); app.exit(); diff --git a/preload.js b/preload.js index b117e3d..c87d336 100644 --- a/preload.js +++ b/preload.js @@ -21,6 +21,7 @@ contextBridge.exposeInMainWorld("electronAPI", { urlIncludesToBlock: (includes) => ipcRenderer.send("block-includes", includes), toggleFullScreen: () => ipcRenderer.send("toggle-fullscreen"), + maximizeApp: () => ipcRenderer.send("maximize-app"), // --- renderer to main - 2 way rootDir: () => ipcRenderer.invoke("dir-root"), @@ -38,4 +39,6 @@ contextBridge.exposeInMainWorld("electronAPI", { // --- main to renderer log: (callback) => ipcRenderer.on("log-message", callback), + onAppMaximized: (callback) => ipcRenderer.on("on-app-maximized", callback), + onAppUnMaximized: (callback) => ipcRenderer.on("on-app-unmaximized", callback), });