diff --git a/src/main/constants.ts b/src/main/constants.ts index 2dbab33..a08d364 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -10,3 +10,9 @@ export const VENCORD_QUICKCSS_FILE = join(VENCORD_SETTINGS_DIR, "quickCss.css"); export const VENCORD_SETTINGS_FILE = join(VENCORD_SETTINGS_DIR, "settings.json"); export const USER_AGENT = `VencordDesktop/${app.getVersion()} (https://github.com/Vencord/Electron)`; + +// dimensions shamelessly stolen from Discord Desktop :3 +export const MIN_WIDTH = 940; +export const MIN_HEIGHT = 500; +export const DEFAULT_WIDTH = 1280; +export const DEFAULT_HEIGHT = 720; diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 54adbf7..2036590 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -2,6 +2,7 @@ import { BrowserWindow, BrowserWindowConstructorOptions, Menu, Tray, app } from import { join } from "path"; import { ICON_PATH } from "../shared/paths"; import { createAboutWindow } from "./about"; +import { DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH } from "./constants"; import { Settings } from "./settings"; import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally"; import { downloadVencordFiles } from "./utils/vencordLoader"; @@ -165,46 +166,39 @@ function initMenuBar(win: BrowserWindow) { Menu.setApplicationMenu(menu); } -function getWindowBoundsOptions() { - const options = {} as BrowserWindowConstructorOptions; - +function getWindowBoundsOptions(): BrowserWindowConstructorOptions { const { x, y, width, height } = Settings.windowBounds ?? {}; + + const options = { + width: width ?? DEFAULT_WIDTH, + height: height ?? DEFAULT_HEIGHT + } as BrowserWindowConstructorOptions; + if (x != null && y != null) { options.x = x; options.y = y; } - if (width) options.width = width; - if (height) options.height = height; + if (!Settings.disableMinSize) { + options.minWidth = MIN_WIDTH; + options.minHeight = MIN_HEIGHT; + } return options; } function initWindowBoundsListeners(win: BrowserWindow) { - win.on("maximize", () => { - Settings.maximized = true; - Settings.minimized = false; - }); + const saveState = () => { + Settings.maximized = win.isMaximized(); + Settings.minimized = win.isMinimized(); + }; - win.on("minimize", () => { - Settings.minimized = true; - }); - - win.on("unmaximize", () => { - Settings.maximized = false; - Settings.minimized = false; - }); + win.on("maximize", saveState); + win.on("minimize", saveState); + win.on("unmaximize", saveState); const saveBounds = () => { - const [width, height] = win.getSize(); - const [x, y] = win.getPosition(); - - Settings.windowBounds = { - width, - height, - x, - y - }; + Settings.windowBounds = win.getBounds(); }; win.on("resize", saveBounds); diff --git a/src/renderer/components/Settings.tsx b/src/renderer/components/Settings.tsx index 145815f..f97f6e6 100644 --- a/src/renderer/components/Settings.tsx +++ b/src/renderer/components/Settings.tsx @@ -9,6 +9,11 @@ export default function SettingsUi() { const Settings = useSettings(); const { Forms: { FormSection, FormText, FormDivider, FormSwitch, FormTitle }, Text, Select, Button } = Common; + const switches: [keyof typeof Settings, string, string, boolean?][] = [ + ["openLinksWithElectron", "Open Links in app", "Opens links in a new window instead of your WebBrowser"], + ["disableMinSize", "Disable minimum window size", "Allows you to resize the window smaller than the default size"], + ]; + return ( @@ -33,12 +38,16 @@ export default function SettingsUi() { - - Open Links in app - + {switches.map(([key, text, note, def]) => ( + Settings[key] = v} + note={note} + key={key} + > + {text} + + ))} Vencord Desktop Location @@ -83,6 +92,6 @@ export default function SettingsUi() { Reset - + ); } diff --git a/src/shared/paths.ts b/src/shared/paths.ts index e85489d..794cd89 100644 --- a/src/shared/paths.ts +++ b/src/shared/paths.ts @@ -1,4 +1,4 @@ import { join } from "path"; -export const STATIC_DIR = join(__dirname, "..", "..", "static"); -export const ICON_PATH = join(STATIC_DIR, "icon.png"); +export const STATIC_DIR = /* @__PURE__ */ join(__dirname, "..", "..", "static"); +export const ICON_PATH = /* @__PURE__ */ join(STATIC_DIR, "icon.png"); diff --git a/src/shared/settings.d.ts b/src/shared/settings.d.ts index ec3527f..6b2671b 100644 --- a/src/shared/settings.d.ts +++ b/src/shared/settings.d.ts @@ -1,13 +1,11 @@ +import type { Rectangle } from "electron"; + export interface Settings { maximized?: boolean; minimized?: boolean; - windowBounds?: { - x: number; - y: number; - width: number; - height: number; - }; + windowBounds?: Rectangle; discordBranch?: "stable" | "canary" | "ptb"; openLinksWithElectron?: boolean; vencordDir?: string; + disableMinSize?: boolean; }