mirror of
https://github.com/Vencord/Vesktop.git
synced 2025-02-23 13:45:09 +00:00
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 VENCORD_SETTINGS_FILE = join(VENCORD_SETTINGS_DIR, "settings.json");
|
||||||
|
|
||||||
export const USER_AGENT = `VencordDesktop/${app.getVersion()} (https://github.com/Vencord/Electron)`;
|
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 { join } from "path";
|
||||||
import { ICON_PATH } from "../shared/paths";
|
import { ICON_PATH } from "../shared/paths";
|
||||||
import { createAboutWindow } from "./about";
|
import { createAboutWindow } from "./about";
|
||||||
|
import { DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH } from "./constants";
|
||||||
import { Settings } from "./settings";
|
import { Settings } from "./settings";
|
||||||
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
|
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
|
||||||
import { downloadVencordFiles } from "./utils/vencordLoader";
|
import { downloadVencordFiles } from "./utils/vencordLoader";
|
||||||
|
@ -165,46 +166,39 @@ function initMenuBar(win: BrowserWindow) {
|
||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWindowBoundsOptions() {
|
function getWindowBoundsOptions(): BrowserWindowConstructorOptions {
|
||||||
const options = {} as BrowserWindowConstructorOptions;
|
|
||||||
|
|
||||||
const { x, y, width, height } = Settings.windowBounds ?? {};
|
const { x, y, width, height } = Settings.windowBounds ?? {};
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
width: width ?? DEFAULT_WIDTH,
|
||||||
|
height: height ?? DEFAULT_HEIGHT
|
||||||
|
} as BrowserWindowConstructorOptions;
|
||||||
|
|
||||||
if (x != null && y != null) {
|
if (x != null && y != null) {
|
||||||
options.x = x;
|
options.x = x;
|
||||||
options.y = y;
|
options.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width) options.width = width;
|
if (!Settings.disableMinSize) {
|
||||||
if (height) options.height = height;
|
options.minWidth = MIN_WIDTH;
|
||||||
|
options.minHeight = MIN_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
function initWindowBoundsListeners(win: BrowserWindow) {
|
function initWindowBoundsListeners(win: BrowserWindow) {
|
||||||
win.on("maximize", () => {
|
const saveState = () => {
|
||||||
Settings.maximized = true;
|
Settings.maximized = win.isMaximized();
|
||||||
Settings.minimized = false;
|
Settings.minimized = win.isMinimized();
|
||||||
});
|
};
|
||||||
|
|
||||||
win.on("minimize", () => {
|
win.on("maximize", saveState);
|
||||||
Settings.minimized = true;
|
win.on("minimize", saveState);
|
||||||
});
|
win.on("unmaximize", saveState);
|
||||||
|
|
||||||
win.on("unmaximize", () => {
|
|
||||||
Settings.maximized = false;
|
|
||||||
Settings.minimized = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
const saveBounds = () => {
|
const saveBounds = () => {
|
||||||
const [width, height] = win.getSize();
|
Settings.windowBounds = win.getBounds();
|
||||||
const [x, y] = win.getPosition();
|
|
||||||
|
|
||||||
Settings.windowBounds = {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
x,
|
|
||||||
y
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
win.on("resize", saveBounds);
|
win.on("resize", saveBounds);
|
||||||
|
|
|
@ -9,6 +9,11 @@ export default function SettingsUi() {
|
||||||
const Settings = useSettings();
|
const Settings = useSettings();
|
||||||
const { Forms: { FormSection, FormText, FormDivider, FormSwitch, FormTitle }, Text, Select, Button } = Common;
|
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 (
|
return (
|
||||||
<FormSection>
|
<FormSection>
|
||||||
<Text variant="heading-lg/semibold" style={{ color: "var(--header-primary)" }} tag="h2">
|
<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} />
|
<FormDivider className={Margins.top16 + " " + Margins.bottom16} />
|
||||||
|
|
||||||
<FormSwitch
|
{switches.map(([key, text, note, def]) => (
|
||||||
{...getValueAndOnChange("openLinksWithElectron")}
|
<FormSwitch
|
||||||
note={"This will open links in a new window instead of your WebBrowser"}
|
value={Settings[key] ?? def ?? false}
|
||||||
>
|
onChange={v => Settings[key] = v}
|
||||||
Open Links in app
|
note={note}
|
||||||
</FormSwitch>
|
key={key}
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</FormSwitch>
|
||||||
|
))}
|
||||||
|
|
||||||
<FormTitle>Vencord Desktop Location</FormTitle>
|
<FormTitle>Vencord Desktop Location</FormTitle>
|
||||||
<FormText>
|
<FormText>
|
||||||
|
@ -83,6 +92,6 @@ export default function SettingsUi() {
|
||||||
Reset
|
Reset
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</FormSection>
|
</FormSection >
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
|
||||||
export const STATIC_DIR = join(__dirname, "..", "..", "static");
|
export const STATIC_DIR = /* @__PURE__ */ join(__dirname, "..", "..", "static");
|
||||||
export const ICON_PATH = join(STATIC_DIR, "icon.png");
|
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 {
|
export interface Settings {
|
||||||
maximized?: boolean;
|
maximized?: boolean;
|
||||||
minimized?: boolean;
|
minimized?: boolean;
|
||||||
windowBounds?: {
|
windowBounds?: Rectangle;
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
};
|
|
||||||
discordBranch?: "stable" | "canary" | "ptb";
|
discordBranch?: "stable" | "canary" | "ptb";
|
||||||
openLinksWithElectron?: boolean;
|
openLinksWithElectron?: boolean;
|
||||||
vencordDir?: string;
|
vencordDir?: string;
|
||||||
|
disableMinSize?: boolean;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue