Add Default window size and custom size option

- Default window size has been set as the size as 71% width and 74% height of the screen's resolution, which won't make the window size too small for large monitors.

- Additionally, implemented a new menu option allowing users to select or set custom default window sizes.

Resolves #246
This commit is contained in:
Agampreet Singh
2024-07-22 12:13:59 +05:30
parent ffc3042053
commit 67d61a4cc9
6 changed files with 236 additions and 38 deletions

16
app/dimensions.js Normal file
View File

@@ -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 };

View File

@@ -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", () => {

View File

@@ -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,

View File

@@ -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");