From 701f88213693589db07e1da270c85d90635c96e9 Mon Sep 17 00:00:00 2001 From: Simeon Radivoev Date: Wed, 22 Apr 2026 18:31:32 +0300 Subject: [PATCH] Added nw.js launch options --- .../rclone.ts | 3 +- src/bun/browser.ts | 25 ++++++++++++ src/bun/webview/linux.ts | 39 +++---------------- src/mainview/gen/static-icon-assets.gen.ts | 2 +- tsconfig.json | 1 + 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/bun/api/plugins/builtin/other/com.simeonradivoev.gameflow.rclone/rclone.ts b/src/bun/api/plugins/builtin/other/com.simeonradivoev.gameflow.rclone/rclone.ts index 4b8c59c..ba31a9b 100644 --- a/src/bun/api/plugins/builtin/other/com.simeonradivoev.gameflow.rclone/rclone.ts +++ b/src/bun/api/plugins/builtin/other/com.simeonradivoev.gameflow.rclone/rclone.ts @@ -250,8 +250,7 @@ export default class RcloneIntegration implements PluginType UseJSONLog: true, LogLevel: "DEBUG", HumanReadable: true, - Progress: true, - DryRun: true + Progress: true } }); console.log(data); diff --git a/src/bun/browser.ts b/src/bun/browser.ts index 79c01b8..c86dfef 100644 --- a/src/bun/browser.ts +++ b/src/bun/browser.ts @@ -3,6 +3,9 @@ import { BrowserParams, BuildParams } from './utils/browser-params'; import os from 'node:os'; import { EventEmitter } from 'node:stream'; import { dlopen, FFIType, Pointer } from "bun:ffi"; +import { SERVER_URL } from '@/shared/constants'; +import { host } from './utils/host'; +import fs from 'node:fs/promises'; export default async function init (events: EventEmitter, forceBrowser: boolean, params: BrowserParams) { @@ -19,6 +22,8 @@ export default async function init (events: EventEmitter, forceBrowser: boolean, await runBrowser(events, params); } } + + await runNW(events, params); } function focusWindow (id: Pointer) @@ -44,8 +49,28 @@ function focusWindow (id: Pointer) } } +async function runNW (events: EventEmitter, params: BrowserParams) +{ + const path = process.platform === 'win32' ? './bin/nw/nw.exe' : './bin/nw/nw'; + if (!await fs.exists(path)) + { + console.error("Could not find NW.js"); + return; + } + const signalHandler = new AbortController(); + events.on('exitapp', () => signalHandler.abort()); + const args = [path, `--url=${SERVER_URL(host)}`]; + if (process.env.NODE_ENV !== 'development') args.push("--disable-devtools"); + const nwProcess = Bun.spawn(args, { signal: signalHandler.signal }); + await nwProcess.exited; +} + async function runWebview (events: EventEmitter, params: BrowserParams) { + if (process.platform !== 'win32') + { + throw new Error("Webview only supported on windows"); + } const webviewPath = process.env.IS_BINARY ? `./webview/${os.platform()}` : new URL(`./webview/${os.platform()}`, import.meta.url).href; console.log("Launching Webview Worker at: ", webviewPath); const config: Record = {}; diff --git a/src/bun/webview/linux.ts b/src/bun/webview/linux.ts index c53ccca..6683249 100644 --- a/src/bun/webview/linux.ts +++ b/src/bun/webview/linux.ts @@ -1,36 +1,9 @@ import { Size, SizeHint, Webview } from 'webview-bun'; import webviewWorkerBase from "./base"; -if (process.env.FLATPAK_BUILD === "true") -{ - let webview: Bun.Subprocess | undefined = undefined; - let hostUrl: string | undefined = undefined; - webviewWorkerBase({ - navigate: (url) => - { - hostUrl = url; - - }, destroy: () => webview?.kill(), run: () => - { - webview = Bun.spawn(["webview", hostUrl ?? ''], { - stdout: "inherit", - stderr: "inherit", - env: { - ...process.env, - }, - onExit () - { - postMessage({ data: 'destroyed' }); - } - }); - } - }); -} else -{ - console.log("Launching Webview"); - let size: Size | undefined = undefined; - if (process.env.WINDOW_WIDTH && process.env.WINDOW_HEIGHT) - size = { width: Number(process.env.WINDOW_WIDTH), height: Number(process.env.WINDOW_HEIGHT), hint: SizeHint.NONE }; - const webview = new Webview(process.env.NODE_ENV === 'development', size); - webviewWorkerBase(webview); -} \ No newline at end of file +console.log("Launching Webview"); +let size: Size | undefined = undefined; +if (process.env.WINDOW_WIDTH && process.env.WINDOW_HEIGHT) + size = { width: Number(process.env.WINDOW_WIDTH), height: Number(process.env.WINDOW_HEIGHT), hint: SizeHint.NONE }; +const webview = new Webview(process.env.NODE_ENV === 'development', size); +webviewWorkerBase(webview); \ No newline at end of file diff --git a/src/mainview/gen/static-icon-assets.gen.ts b/src/mainview/gen/static-icon-assets.gen.ts index 1d1a4aa..cb3fe1b 100644 --- a/src/mainview/gen/static-icon-assets.gen.ts +++ b/src/mainview/gen/static-icon-assets.gen.ts @@ -464,7 +464,7 @@ const assets = new Set([ ]); // Store basePath resolved from Vite config -const BASE_PATH = "/"; +const BASE_PATH = "./"; /** diff --git a/tsconfig.json b/tsconfig.json index 49e40c5..7fb79f1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -41,6 +41,7 @@ }, "include": [ "src", + "scripts", "vite.config.ts", "vite-env-override.d.ts" ]