Added nw.js launch options

This commit is contained in:
Simeon Radivoev 2026-04-22 18:31:32 +03:00
parent 6aacec2c0d
commit 701f882136
Signed by: simeonradivoev
GPG key ID: 7611A451D2A5D37A
5 changed files with 34 additions and 36 deletions

View file

@ -250,8 +250,7 @@ export default class RcloneIntegration implements PluginType<SettingsType>
UseJSONLog: true, UseJSONLog: true,
LogLevel: "DEBUG", LogLevel: "DEBUG",
HumanReadable: true, HumanReadable: true,
Progress: true, Progress: true
DryRun: true
} }
}); });
console.log(data); console.log(data);

View file

@ -3,6 +3,9 @@ import { BrowserParams, BuildParams } from './utils/browser-params';
import os from 'node:os'; import os from 'node:os';
import { EventEmitter } from 'node:stream'; import { EventEmitter } from 'node:stream';
import { dlopen, FFIType, Pointer } from "bun:ffi"; 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) 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 runBrowser(events, params);
} }
} }
await runNW(events, params);
} }
function focusWindow (id: Pointer) 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) 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; 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); console.log("Launching Webview Worker at: ", webviewPath);
const config: Record<string, string> = {}; const config: Record<string, string> = {};

View file

@ -1,36 +1,9 @@
import { Size, SizeHint, Webview } from 'webview-bun'; import { Size, SizeHint, Webview } from 'webview-bun';
import webviewWorkerBase from "./base"; 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"); console.log("Launching Webview");
let size: Size | undefined = undefined; let size: Size | undefined = undefined;
if (process.env.WINDOW_WIDTH && process.env.WINDOW_HEIGHT) 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 }; 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); const webview = new Webview(process.env.NODE_ENV === 'development', size);
webviewWorkerBase(webview); webviewWorkerBase(webview);
}

View file

@ -464,7 +464,7 @@ const assets = new Set<string>([
]); ]);
// Store basePath resolved from Vite config // Store basePath resolved from Vite config
const BASE_PATH = "/"; const BASE_PATH = "./";
/** /**

View file

@ -41,6 +41,7 @@
}, },
"include": [ "include": [
"src", "src",
"scripts",
"vite.config.ts", "vite.config.ts",
"vite-env-override.d.ts" "vite-env-override.d.ts"
] ]