Files
Agent-Workbench/src/core/desktop/launch-options.mjs
T

16 lines
843 B
JavaScript

import path from 'node:path';
import { samePath } from './file-state.mjs';
export function desktopLaunchOptions(argv, { defaultApp = false, mainFile } = {}) {
const args = argv.slice(1), options = {};
while (/^--(?:inspect|remote-debugging-port)=\d+$/.test(args[0] ?? '')) args.shift();
if (defaultApp && (!args.length || !mainFile || !samePath(path.resolve(args.shift()), mainFile))) throw new Error('Desktop entry does not match the compiled main program.');
while (args.length) {
const flag = args.shift();
if (flag === '--hidden-window' && !options.hidden) { options.hidden = true; continue; }
if (!['--app-root', '--data-root', '--node', '--port'].includes(flag) || !args.length || options[flag] !== undefined) throw new Error('Unsupported desktop option.');
options[flag] = args.shift();
}
return options;
}