mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-05-04 00:41:33 -07:00
feat: open texthooker from cli and tray
This commit is contained in:
+30
-1
@@ -831,8 +831,30 @@ export async function startOverlay(
|
||||
}
|
||||
}
|
||||
|
||||
export function launchTexthookerOnly(appPath: string, args: Args): never {
|
||||
export function openUrlInDefaultBrowser(url: string, logLevel: LogLevel): void {
|
||||
const target =
|
||||
process.platform === 'darwin'
|
||||
? { command: 'open', args: [url] }
|
||||
: process.platform === 'win32'
|
||||
? { command: 'cmd', args: ['/c', 'start', '', url] }
|
||||
: { command: 'xdg-open', args: [url] };
|
||||
const result = spawnSync(target.command, target.args, {
|
||||
stdio: 'ignore',
|
||||
env: process.env,
|
||||
windowsHide: true,
|
||||
});
|
||||
if (result.error) {
|
||||
log('warn', logLevel, `Failed to open browser for ${url}: ${result.error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function launchTexthookerOnly(
|
||||
appPath: string,
|
||||
args: Args,
|
||||
deps: { openBrowser?: (url: string) => void } = {},
|
||||
): never {
|
||||
const overlayArgs = ['--texthooker'];
|
||||
if (args.texthookerOpenBrowser) overlayArgs.push('--open-browser');
|
||||
if (args.logLevel !== 'info') overlayArgs.push('--log-level', args.logLevel);
|
||||
|
||||
log('info', args.logLevel, 'Launching texthooker mode...');
|
||||
@@ -840,6 +862,13 @@ export function launchTexthookerOnly(appPath: string, args: Args): never {
|
||||
if (result.error) {
|
||||
fail(`Failed to launch texthooker mode: ${result.error.message}`);
|
||||
}
|
||||
if (args.texthookerOpenBrowser && (result.status ?? 0) === 0) {
|
||||
const url = 'http://127.0.0.1:5174';
|
||||
const openBrowser =
|
||||
deps.openBrowser ??
|
||||
((browserUrl: string) => openUrlInDefaultBrowser(browserUrl, args.logLevel));
|
||||
openBrowser(url);
|
||||
}
|
||||
process.exit(result.status ?? 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user