Support packaged Linux AppImage CLI registration with a stable wrapper that invokes the outer AppImage and resolves the CLI entry from APPDIR at runtime. The takeover drops the already-landed Linux command rename plus unrelated perf/GPU sandbox changes from the original branch, and adds regression coverage for wrapper install, stale wrapper replacement, legacy symlink cleanup, argument forwarding, and env preservation. Co-authored-by: Emad Fussi <43019044+omd0@users.noreply.github.com>
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
const APPIMAGE_CLI_SCRIPT = [
|
|
'(async()=>{',
|
|
'try{',
|
|
'const path=require("path");',
|
|
'const appDir=process.env.APPDIR;',
|
|
'if(!appDir){console.error("Orca AppImage runtime did not set APPDIR.");process.exit(1);}',
|
|
'const cli=path.join(appDir,"resources","app.asar.unpacked","out","cli","index.js");',
|
|
'await Promise.resolve(require(cli).main(process.argv.slice(1)));',
|
|
'}catch(error){',
|
|
'console.error(error&&error.stack?error.stack:String(error));process.exit(1);',
|
|
'}',
|
|
'})();'
|
|
].join('')
|
|
|
|
export function buildAppImageCliWrapper(appImagePath: string): string {
|
|
// Why: AppImage mounts resources under a fresh FUSE path per launch, so the
|
|
// installed command must call the stable outer AppImage and resolve APPDIR.
|
|
return `#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
APPIMAGE=${quoteShell(appImagePath)}
|
|
if [ ! -f "$APPIMAGE" ]; then
|
|
echo "Orca AppImage not found at $APPIMAGE" >&2
|
|
echo "If you moved the AppImage, re-run CLI registration from Orca Settings." >&2
|
|
exit 1
|
|
fi
|
|
export ORCA_NODE_OPTIONS="\${NODE_OPTIONS-}"
|
|
export ORCA_NODE_REPL_EXTERNAL_MODULE="\${NODE_REPL_EXTERNAL_MODULE-}"
|
|
unset NODE_OPTIONS
|
|
unset NODE_REPL_EXTERNAL_MODULE
|
|
# Why: AppImage mount paths change on each launch; $APPDIR is the runtime mount.
|
|
ELECTRON_RUN_AS_NODE=1 exec "$APPIMAGE" -e ${quoteShell(APPIMAGE_CLI_SCRIPT)} -- "$@"
|
|
`
|
|
}
|
|
|
|
function quoteShell(value: string): string {
|
|
return `'${value.replaceAll("'", `'"'"'`)}'`
|
|
}
|