diff --git a/app/dimensions.js b/app/dimensions.js new file mode 100644 index 0000000..acede9e --- /dev/null +++ b/app/dimensions.js @@ -0,0 +1,16 @@ +import { app, screen } from "electron"; + +let screenWidth, screenHeight; +app.on("ready", () => { + ({ width: screenWidth, height: screenHeight } = screen.getPrimaryDisplay().workAreaSize); +}); + +function getScreenWidth() { + return screenWidth; +} + +function getScreenHeight() { + return screenHeight; +} + +export { getScreenWidth, getScreenHeight }; diff --git a/app/main.js b/app/main.js index 97d0f92..16ce99e 100644 --- a/app/main.js +++ b/app/main.js @@ -1,4 +1,4 @@ -import { app, Menu, BrowserWindow, dialog, nativeImage } from "electron"; +import { app, Menu, BrowserWindow, dialog, nativeImage, screen } from "electron"; import { clearActivity, setActivity, loginToRPC } from "./rpc.js"; import { initialize, trackEvent } from "@aptabase/electron/main"; import { ElectronBlocker } from "@cliqz/adblocker-electron"; @@ -7,6 +7,7 @@ import { fileURLToPath } from "url"; import { dirname } from "path"; import { join } from "path"; +import { getScreenWidth, getScreenHeight } from "./dimensions.js"; import Windows from "./useragents.json" with { type: "json" }; import checkInternetConnected from "check-internet-connected"; import contextMenu from "electron-context-menu"; @@ -17,6 +18,8 @@ import logpkg from "electron-log"; const { transports, log: _log, functions } = logpkg; const __filename = fileURLToPath(import.meta.url); +const windowHeight = getValue("windowHeight"); +const windowWidth = getValue("windowWidth"); const __dirname = dirname(__filename); const { autoUpdater } = updaterpkg; @@ -32,8 +35,8 @@ function createWindow() { const partition = enterpriseOrNormal === "?auth=1" ? "persist:personal" : "persist:work"; const win = new BrowserWindow({ - width: 1181, - height: 670, + width: Math.round(getScreenWidth() * getValue("windowWidth")), + height: Math.round(getScreenHeight() * getValue("windowHeight")), icon: join(__dirname, "/assets/icons/png/1024x1024.png"), show: false, webPreferences: { @@ -46,8 +49,8 @@ function createWindow() { win.setAutoHideMenuBar(getValue("autohide-menubar") === "true"); const splash = new BrowserWindow({ - width: 810, - height: 610, + width: Math.round(getScreenWidth() * 0.49), + height: Math.round(getScreenHeight() * 0.65), transparent: true, frame: false, icon: join(__dirname, "/assets/icons/png/1024x1024.png"), @@ -133,7 +136,13 @@ app.on("web-contents-created", (event, contents) => { if (getValue("discordrpcstatus") === "true") { setActivity(`On "${BrowserWindow.getFocusedWindow().webContents.getTitle()}"`); } - return { action: "allow", overrideBrowserWindowOptions: { width: 1081, height: 610 } }; + return { + action: "allow", + overrideBrowserWindowOptions: { + width: Math.round(getScreenWidth() * (windowWidth - 0.07)), + height: Math.round(getScreenHeight() * (windowHeight - 0.07)), + }, + }; } }); contents.on("did-finish-load", () => { diff --git a/app/menu.js b/app/menu.js index 2f7b3bd..2f6e80d 100644 --- a/app/menu.js +++ b/app/menu.js @@ -2,10 +2,12 @@ import { app, dialog, BrowserWindow, ShareMenu, clipboard } from "electron"; import { getValue, setValue } from "./store.js"; import { ElectronBlocker } from "@cliqz/adblocker-electron"; import { clearActivity, setActivity } from "./rpc.js"; +import prompt from "electron-prompt"; import { fileURLToPath } from "url"; import { shell } from "electron"; import { dirname } from "path"; +import { getScreenWidth, getScreenHeight } from "./dimensions.js"; import useragents from "./useragents.json" with { type: "json" }; import updaterpkg from "electron-updater"; import fetch from "cross-fetch"; @@ -153,6 +155,165 @@ const commonPreferencesSubmenu = [ checked: getValue("websites-in-new-window") === "false", }, { type: "separator" }, + { + label: "Custom Main Window Size", + submenu: [ + { + label: "Default", + type: "radio", + click: () => { + setValue("customWindowSize", false); + setValue("windowWidth", 0.71); + setValue("windowHeight", 0.74); + dialog.showMessageBoxSync({ + type: "info", + title: "Custom Main Window Size", + message: + "You have set the main window size to the default size.\n\nPlease restart the app to apply the changes.", + buttons: ["OK"], + }); + }, + checked: + getValue("windowWidth") === 0.71 && + getValue("windowHeight") === 0.74 && + getValue("customWindowSize") === false, + }, + { + label: "60%", + type: "radio", + click: () => { + setValue("customWindowSize", false); + setValue("windowWidth", 0.6); + setValue("windowHeight", 0.6); + dialog.showMessageBoxSync({ + type: "info", + title: "Custom Main Window Size", + message: + "You have set the main window size to 60% of your screen size.\n\nPlease restart the app to apply the changes.", + buttons: ["OK"], + }); + }, + checked: + getValue("windowWidth") === 0.6 && + getValue("windowHeight") === 0.6 && + getValue("customWindowSize") === false, + }, + { + label: "70%", + type: "radio", + click: () => { + setValue("windowWidth", 0.7); + setValue("windowHeight", 0.7); + dialog.showMessageBoxSync({ + type: "info", + title: "Custom Main Window Size", + message: + "You have set the main window size to 70% of your screen size.\n\nPlease restart the app to apply the changes.", + buttons: ["OK"], + }); + }, + checked: + getValue("windowWidth") === 0.7 && + getValue("windowHeight") === 0.7 && + getValue("customWindowSize") === false, + }, + { + label: "80%", + type: "radio", + click: () => { + setValue("customWindowSize", false); + setValue("windowWidth", 0.8); + setValue("windowHeight", 0.8); + dialog.showMessageBoxSync({ + type: "info", + title: "Custom Main Window Size", + message: + "You have set the main window size to 80% of your screen size.\n\nPlease restart the app to apply the changes.", + buttons: ["OK"], + }); + }, + checked: + getValue("windowWidth") === 0.8 && + getValue("windowHeight") === 0.8 && + getValue("customWindowSize") === false, + }, + { + label: "90%", + type: "radio", + click: () => { + setValue("customWindowSize", false); + setValue("windowWidth", 0.9); + setValue("windowHeight", 0.9); + dialog.showMessageBoxSync({ + type: "info", + title: "Custom Main Window Size", + message: + "You have set the main window size to 90% of your screen size.\n\nPlease restart the app to apply the changes.", + buttons: ["OK"], + }); + }, + checked: + getValue("windowWidth") === 0.9 && + getValue("windowHeight") === 0.9 && + getValue("customWindowSize") === false, + }, + { + label: "100% (Maximize)", + type: "radio", + click: () => { + setValue("customWindowSize", false); + setValue("windowWidth", 1); + setValue("windowHeight", 1); + dialog.showMessageBoxSync({ + type: "info", + title: "Custom Main Window Size", + message: + "You have set the main window size to 100% of your screen size, which will maximise the window.\n\nPlease restart the app to apply the changes.", + buttons: ["OK"], + }); + }, + checked: + getValue("windowWidth") === 1 && + getValue("windowHeight") === 1 && + getValue("customWindowSize") === false, + }, + { + label: "Custom", + type: "radio", + click: () => { + prompt({ + title: "Custom Main Window Size", + label: "Enter size in percentage (without % sign)", + value: "10", + inputAttrs: { + type: "number", + required: true, + min: 10, + max: 100, + }, + type: "input", + }) + .then((r) => { + if (r === null) { + return; + } + const size = r / 100; + setValue("customWindowSize", true); + setValue("windowWidth", size); + setValue("windowHeight", size); + dialog.showMessageBoxSync({ + type: "info", + title: "Custom Main Window Size", + message: `You have set the main window size to ${r}% of your screen size.\n\nPlease restart the app to apply the changes.`, + buttons: ["OK"], + }); + }) + .catch(console.error); + }, + checked: getValue("customWindowSize") === true, + }, + ], + }, { label: "Custom Home Page", submenu: [ @@ -463,8 +624,8 @@ const menulayout = [ accelerator: "CmdOrCtrl+N", click: () => { let newWindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: true, devTools: true, @@ -479,8 +640,8 @@ const menulayout = [ accelerator: "CmdOrCtrl+Shift+N", click: () => { let newWindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: true, devTools: true, @@ -616,8 +777,8 @@ const menulayout = [ if (getValue("enterprise-or-normal") === "?auth=2") { if (getValue("websites-in-new-window") === "true") { let wordwindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -633,8 +794,8 @@ const menulayout = [ } else if (getValue("enterprise-or-normal") === "?auth=1") { if (getValue("websites-in-new-window") === "true") { let wordwindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -656,8 +817,8 @@ const menulayout = [ if (getValue("enterprise-or-normal") === "?auth=2") { if (getValue("websites-in-new-window") === "true") { let excelwindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -673,8 +834,8 @@ const menulayout = [ } else if (getValue("enterprise-or-normal") === "?auth=1") { if (getValue("websites-in-new-window") === "true") { let excelwindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -696,8 +857,8 @@ const menulayout = [ if (getValue("enterprise-or-normal") === "?auth=2") { if (getValue("websites-in-new-window") === "true") { let powerpointwindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -713,8 +874,8 @@ const menulayout = [ } else if (getValue("enterprise-or-normal") === "?auth=1") { if (getValue("websites-in-new-window") === "true") { let powerpointwindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -736,8 +897,8 @@ const menulayout = [ if (getValue("enterprise-or-normal") === "?auth=2") { if (getValue("websites-in-new-window") === "true") { let outlookwindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -751,8 +912,8 @@ const menulayout = [ } else if (getValue("enterprise-or-normal") === "?auth=1") { if (getValue("websites-in-new-window") === "true") { let outlookwindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -774,8 +935,8 @@ const menulayout = [ if (getValue("enterprise-or-normal") === "?auth=2") { if (getValue("websites-in-new-window") === "true") { let onedrivewindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -791,8 +952,8 @@ const menulayout = [ } else if (getValue("enterprise-or-normal") === "?auth=1") { if (getValue("websites-in-new-window") === "true") { let onedrivewindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -814,8 +975,8 @@ const menulayout = [ if (getValue("enterprise-or-normal") === "?auth=2") { if (getValue("websites-in-new-window") === "true") { let onenotewindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -831,8 +992,8 @@ const menulayout = [ } else if (getValue("enterprise-or-normal") === "?auth=1") { if (getValue("websites-in-new-window") === "true") { let onenotewindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -852,8 +1013,8 @@ const menulayout = [ if (getValue("enterprise-or-normal") === "?auth=2") { if (getValue("websites-in-new-window") === "true") { let allappswindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, @@ -867,8 +1028,8 @@ const menulayout = [ } else if (getValue("enterprise-or-normal") === "?auth=1") { if (getValue("websites-in-new-window") === "true") { let allappswindow = new BrowserWindow({ - width: 1081, - height: 570, + width: Math.round(getScreenWidth() * (getValue("windowWidth") - 0.07)), + height: Math.round(getScreenHeight() * (getValue("windowHeight") - 0.07)), webPreferences: { nodeIntegration: false, contextIsolation: true, diff --git a/app/store.js b/app/store.js index f879624..d8380fd 100644 --- a/app/store.js +++ b/app/store.js @@ -29,6 +29,9 @@ getValueOrDefault("blockadsandtrackers", "false"); getValueOrDefault("dynamicicons", "true"); getValueOrDefault("autoupdater", "true"); getValueOrDefault("custompage", "home"); +getValueOrDefault("windowWidth", 0.71); +getValueOrDefault("windowHeight", 0.74); +getValueOrDefault("customWindowSize", false); if (getValue("enterprise-or-normal") === "https://microsoft365.com/?auth=1") { setValue("enterprise-or-normal", "?auth=1"); diff --git a/package.json b/package.json index 90da5a2..91f06b5 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "electron-context-menu": "^4.0.0", "electron-dl": "^4.0.0", "electron-log": "^5.0.0-beta.25", + "electron-prompt": "^1.7.0", "electron-store": "^10.0.0", "electron-updater": "^6.1.4", "node-gyp": "^10.0.0" diff --git a/yarn.lock b/yarn.lock index a303a6f..5e6ff95 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1578,6 +1578,13 @@ __metadata: languageName: node linkType: hard +"electron-prompt@npm:^1.7.0": + version: 1.7.0 + resolution: "electron-prompt@npm:1.7.0" + checksum: 10c0/5c2be70739838257944c8e9ade800b13b8efe4f908d46d3fd28740c8f4460150df70a80acd8138e66bd782befb64ccf8d30c616ad2762644d8998d5a6bdd34da + languageName: node + linkType: hard + "electron-publish@npm:24.13.1": version: 24.13.1 resolution: "electron-publish@npm:24.13.1" @@ -3047,6 +3054,7 @@ __metadata: electron-context-menu: "npm:^4.0.0" electron-dl: "npm:^4.0.0" electron-log: "npm:^5.0.0-beta.25" + electron-prompt: "npm:^1.7.0" electron-store: "npm:^10.0.0" electron-updater: "npm:^6.1.4" eslint: "npm:^8.52.0"