Add minimum window height & width
This commit is contained in:
parent
27b6264c79
commit
ba0e8fedd0
5 changed files with 48 additions and 41 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 (
|
||||
<FormSection>
|
||||
<Text variant="heading-lg/semibold" style={{ color: "var(--header-primary)" }} tag="h2">
|
||||
|
@ -33,12 +38,16 @@ export default function SettingsUi() {
|
|||
|
||||
<FormDivider className={Margins.top16 + " " + Margins.bottom16} />
|
||||
|
||||
<FormSwitch
|
||||
{...getValueAndOnChange("openLinksWithElectron")}
|
||||
note={"This will open links in a new window instead of your WebBrowser"}
|
||||
>
|
||||
Open Links in app
|
||||
</FormSwitch>
|
||||
{switches.map(([key, text, note, def]) => (
|
||||
<FormSwitch
|
||||
value={Settings[key] ?? def ?? false}
|
||||
onChange={v => Settings[key] = v}
|
||||
note={note}
|
||||
key={key}
|
||||
>
|
||||
{text}
|
||||
</FormSwitch>
|
||||
))}
|
||||
|
||||
<FormTitle>Vencord Desktop Location</FormTitle>
|
||||
<FormText>
|
||||
|
@ -83,6 +92,6 @@ export default function SettingsUi() {
|
|||
Reset
|
||||
</Button>
|
||||
</div>
|
||||
</FormSection>
|
||||
</FormSection >
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
10
src/shared/settings.d.ts
vendored
10
src/shared/settings.d.ts
vendored
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue