From 8612d1fbfd441944e169316b4cbabc91e1f059bf Mon Sep 17 00:00:00 2001 From: TNT3530 Date: Tue, 10 Feb 2026 15:36:35 -0600 Subject: [PATCH] Add Home Server config --- forge.config.ts | 5 ++ public/homeserver.html | 182 +++++++++++++++++++++++++++++++++++++++++ src/config.d.ts | 1 + src/main.ts | 4 +- src/native/config.ts | 20 +++++ src/native/window.ts | 27 ++++-- src/world/config.ts | 3 + 7 files changed, 231 insertions(+), 11 deletions(-) create mode 100644 public/homeserver.html diff --git a/forge.config.ts b/forge.config.ts index 40952df..c10a96e 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -151,6 +151,11 @@ const config: ForgeConfig = { config: "vite.preload.config.ts", target: "preload", }, + { + entry: "public/homeserver.html", + config: "vite.preload.config.ts", + target: "preload", + } ], renderer: [], }), diff --git a/public/homeserver.html b/public/homeserver.html new file mode 100644 index 0000000..c44304c --- /dev/null +++ b/public/homeserver.html @@ -0,0 +1,182 @@ + + + + + + + + Stoat Desktop + + + + + + + +
+
+
+ + + + + + + + + + + + + + + +
+
+
+
+ Hello! +

Connect to a Stoat Server

+
+
+
+ + +
+
+
+ + + \ No newline at end of file diff --git a/src/config.d.ts b/src/config.d.ts index d7a89db..01e6b64 100644 --- a/src/config.d.ts +++ b/src/config.d.ts @@ -5,6 +5,7 @@ declare type DesktopConfig = { spellchecker: boolean; hardwareAcceleration: boolean; discordRpc: boolean; + homeserver: string; windowState: { isMaximised: boolean; }; diff --git a/src/main.ts b/src/main.ts index 5256d5f..c093f7a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,7 @@ import { autoLaunch } from "./native/autoLaunch"; import { config } from "./native/config"; import { initDiscordRpc } from "./native/discordRpc"; import { initTray } from "./native/tray"; -import { BUILD_URL, createMainWindow, mainWindow } from "./native/window"; +import { createMainWindow, mainWindow } from "./native/window"; // Squirrel-specific logic // create/remove shortcuts on Windows when installing / uninstalling @@ -77,7 +77,7 @@ if (acquiredLock) { app.on("web-contents-created", (_, contents) => { // prevent navigation out of build URL origin contents.on("will-navigate", (event, navigationUrl) => { - if (new URL(navigationUrl).origin !== BUILD_URL.origin) { + if (new URL(navigationUrl).origin !== config.homeserver) { event.preventDefault(); } }); diff --git a/src/native/config.ts b/src/native/config.ts index 7021be3..0b49aeb 100644 --- a/src/native/config.ts +++ b/src/native/config.ts @@ -25,6 +25,9 @@ const schema = { discordRpc: { type: "boolean", } as JSONSchema.Boolean, + homeserver: { + type: "string" + } as JSONSchema.String, windowState: { type: "object", properties: { @@ -56,6 +59,7 @@ const store = new Store({ spellchecker: true, hardwareAcceleration: true, discordRpc: true, + homeserver: "", windowState: { isMaximised: false, }, @@ -74,6 +78,7 @@ class Config { spellchecker: this.spellchecker, hardwareAcceleration: this.hardwareAcceleration, discordRpc: this.discordRpc, + homeserver: this.homeserver, windowState: this.windowState, }); } @@ -168,6 +173,21 @@ class Config { this.sync(); } + get homeserver() { + return (store as never as { get(k: string): string }).get( + "homeserver", + ); + } + + set homeserver(value: string) { + (store as never as { set(k: string, value: string): void }).set( + "homeserver", + value, + ); + + this.sync(); + } + get windowState() { return ( store as never as { get(k: string): DesktopConfig["windowState"] } diff --git a/src/native/window.ts b/src/native/window.ts index 571e504..b04f530 100644 --- a/src/native/window.ts +++ b/src/native/window.ts @@ -17,13 +17,6 @@ import { updateTrayMenu } from "./tray"; // global reference to main window export let mainWindow: BrowserWindow; -// currently in-use build -export const BUILD_URL = new URL( - app.commandLine.hasSwitch("force-server") - ? app.commandLine.getSwitchValue("force-server") - : /*MAIN_WINDOW_VITE_DEV_SERVER_URL ??*/ "https://beta.revolt.chat", -); - // internal window state let shouldQuit = false; @@ -32,6 +25,15 @@ const windowIcon = nativeImage.createFromDataURL(windowIconAsset); // windowIcon.setTemplateImage(true); +ipcMain.on("updateHomeserver", (e, args) => { + config.homeserver = args; + config.sync(); + + setTimeout(() => { + mainWindow.loadURL(config.homeserver); + }, 2000); +}); + /** * Create the main application window */ @@ -63,8 +65,15 @@ export function createMainWindow() { } // load the entrypoint - mainWindow.loadURL(BUILD_URL.toString()); - + if(config.homeserver == "") //user has yet to set a host + { + mainWindow.loadFile(join(__dirname, "public/homeserver.html")); + } + else + { + mainWindow.loadURL(config.homeserver); + } + // minimise window to tray mainWindow.on("close", (event) => { if (!shouldQuit && config.minimiseToTray) { diff --git a/src/world/config.ts b/src/world/config.ts index 8d0a202..3fdbf57 100644 --- a/src/world/config.ts +++ b/src/world/config.ts @@ -14,4 +14,7 @@ contextBridge.exposeInMainWorld("desktopConfig", { setAutostart(value: boolean) { ipcRenderer.send("setAutostart", value); }, + setHomeserver(value: string) { + ipcRenderer.send("updateHomeserver", value); + } });