diff --git a/README.md b/README.md index f6fcefc..ea5429c 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,27 @@ pnpm package pnpm make ``` +Various useful commands for development testing: + +```bash +# connect to the development server +pnpm start -- --force-server http://localhost:5173 + +# test the flatpak (after `make`) +pnpm install:flatpak +pnpm run:flatpak +# ... also connect to dev server like so: +pnpm run:flatpak --force-server http://localhost:5173 + +# Nix-specific instructions for testing +pnpm package +pnpm run:nix +# ... as before: +pnpm run:nix --force-server=http://localhost:5173 +# a better solution would be telling +# Electron Forge where system Electron is +``` + ### Pulling in Stoat's assets If you want to pull in Stoat brand assets after pulling, run the following: diff --git a/default.nix b/default.nix index a020ce6..f343ef1 100644 --- a/default.nix +++ b/default.nix @@ -12,6 +12,11 @@ pkgs.mkShell rec { pkgs.nodejs pkgs.nodejs.pkgs.pnpm + # Electron + (pkgs.writeShellScriptBin "electron-nix" '' + exec ${pkgs.electron}/bin/electron "$@" + '') + # build target: zip pkgs.zip diff --git a/package.json b/package.json index 7c745d9..ee24d55 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "stoat-desktop", "productName": "stoat-desktop", - "version": "1.1.9", + "version": "1.1.10", "main": ".vite/build/main.js", "repository": "stoatchat/desktop", "scripts": { @@ -11,7 +11,8 @@ "publish": "electron-forge publish", "lint": "eslint --ext .ts,.tsx .", "install:flatpak": "flatpak --user install out/make/flatpak/x86_64/chat.stoat.stoat-desktop_stable_x86_64.flatpak", - "run:flatpak": "flatpak run --socket=session-bus chat.stoat.stoat-desktop" + "run:flatpak": "flatpak run --socket=session-bus chat.stoat.stoat-desktop", + "run:nix": "/usr/bin/env electron-nix ." }, "keywords": [], "author": { diff --git a/src/native/config.ts b/src/native/config.ts index 01c3422..7021be3 100644 --- a/src/native/config.ts +++ b/src/native/config.ts @@ -66,6 +66,18 @@ const store = new Store({ * Shim for `electron-store` because typings are broken */ class Config { + sync() { + mainWindow.webContents.send("config", { + firstLaunch: this.firstLaunch, + customFrame: this.customFrame, + minimiseToTray: this.minimiseToTray, + spellchecker: this.spellchecker, + hardwareAcceleration: this.hardwareAcceleration, + discordRpc: this.discordRpc, + windowState: this.windowState, + }); + } + get firstLaunch() { return (store as never as { get(k: string): boolean }).get("firstLaunch"); } @@ -75,6 +87,8 @@ class Config { "firstLaunch", value, ); + + this.sync(); } get customFrame() { @@ -86,6 +100,8 @@ class Config { "customFrame", value, ); + + this.sync(); } get minimiseToTray() { @@ -99,6 +115,8 @@ class Config { "minimiseToTray", value, ); + + this.sync(); } get spellchecker() { @@ -112,6 +130,8 @@ class Config { "spellchecker", value, ); + + this.sync(); } get hardwareAcceleration() { @@ -125,6 +145,8 @@ class Config { "hardwareAcceleration", value, ); + + this.sync(); } get discordRpc() { @@ -142,6 +164,8 @@ class Config { "discordRpc", value, ); + + this.sync(); } get windowState() { @@ -156,13 +180,16 @@ class Config { set(k: string, value: DesktopConfig["windowState"]): void; } ).set("windowState", value); + + this.sync(); } } export const config = new Config(); -ipcMain.on("config", (newConfig) => +ipcMain.on("config", (_, newConfig: Partial) => { + console.info("Received new configuration", newConfig); Object.entries(newConfig).forEach( - ([key, value]) => (config[key as keyof DesktopConfig] = value), - ), -); + ([key, value]) => (config[key as keyof DesktopConfig] = value as never), + ); +}); diff --git a/src/native/tray.ts b/src/native/tray.ts index 5d720e9..54d2573 100644 --- a/src/native/tray.ts +++ b/src/native/tray.ts @@ -18,6 +18,10 @@ export function initTray() { updateTrayMenu(); tray.setToolTip("Stoat for Desktop"); tray.setImage(trayIcon); + tray.on("click", () => { + mainWindow.show(); + mainWindow.focus(); + }); } export function updateTrayMenu() { diff --git a/src/native/window.ts b/src/native/window.ts index 2aa32a4..571e504 100644 --- a/src/native/window.ts +++ b/src/native/window.ts @@ -40,8 +40,8 @@ export function createMainWindow() { mainWindow = new BrowserWindow({ minWidth: 300, minHeight: 300, - width: 1100, - height: 600, + width: 1280, + height: 720, backgroundColor: "#191919", frame: !config.customFrame, icon: windowIcon, @@ -54,6 +54,9 @@ export function createMainWindow() { }, }); + // hide the options + mainWindow.setMenu(null); + // maximise the window if it was maximised before if (config.windowState.isMaximised) { mainWindow.maximize(); @@ -101,6 +104,9 @@ export function createMainWindow() { } }); + // send the config + mainWindow.webContents.on("did-finish-load", () => config.sync()); + // configure spellchecker context menu mainWindow.webContents.on("context-menu", (_, params) => { const menu = new Menu();