refactor(native): localize OS hydration to Launcher module

- Removed detailed OS path hydration from root +layout.ts to keep it lean.
- Moved home/tmp directory hydration to LauncherBackgroundSync onMount.
- Fixed regex pattern bug in electron_relay.ts (/\[home\]/g).
- Ensures absolute paths are correctly generated within the Launcher module.
This commit is contained in:
Scott Idem
2026-01-26 14:34:15 -05:00
parent 32866f7911
commit 1a9630903d
2 changed files with 201 additions and 4 deletions

View File

@@ -1,3 +1,6 @@
import { get } from 'svelte/store';
import { ae_loc, ae_api, ae_sess, slct } from '$lib/stores/ae_stores';
/**
* electron_relay.ts
* TypeScript relay for Aether Native (Electron) Bridge.
@@ -64,4 +67,168 @@ export async function kill_processes({ process_name_li = [] }: { process_name_li
export async function open_local_file_v2(path: string) {
if (!native) return { success: false, error: 'Native bridge not available' };
return await native.open_local_file_v2(path);
}
/**
* Specialized Presentation Launcher (Phase 5)
* Handles platform-specific application selection (LibreOffice on Linux,
* PowerPoint/Keynote on macOS).
*/
export async function launch_presentation({
path,
app = 'default',
os = 'auto',
log_lvl = 0
}: {
path: string,
app?: 'default' | 'powerpoint' | 'keynote' | 'libreoffice',
os?: 'auto' | 'linux' | 'darwin' | 'win32',
log_lvl?: number
}) {
if (!native) return { success: false, error: 'Native bridge not available' };
// 1. Detect OS if set to auto
let platform = os;
if (platform === 'auto') {
const info = await get_device_info();
platform = info?.platform || 'linux';
}
// 2. Prefer the Native Bridge implementation (Atomic Copy-and-Launch)
// This delegates to the hardened logic in electron_native.js
if (native.launch_presentation) {
if (log_lvl) console.log('Relay: Using native.launch_presentation');
return await native.launch_presentation({ path, app, os_platform: platform });
}
// 3. Relay-side Fallback (Mock/Legacy)
// Manually resolve placeholders using all available context
const info = await get_device_info();
const loc = get(ae_loc);
// Attempt to find home/tmp from bridge info or local hydrated store
const home = info?.home_directory || loc.home_directory || loc.native_device?.home_directory || '';
const tmp = info?.tmp_directory || loc.tmp_directory || loc.native_device?.tmp_directory || '';
if (log_lvl) console.log('Relay Debug:', { home, tmp, raw_path: path });
// CRITICAL: Resolve all instances of placeholders using global regex (fixed pattern)
let cleaned_path = path;
if (home) cleaned_path = cleaned_path.replace(/\[home\]/g, home);
if (tmp) cleaned_path = cleaned_path.replace(/\[tmp\]/g, tmp);
if (log_lvl) console.log(`Relay Fallback: Resolving ${path} -> ${cleaned_path}`);
// If path still contains [home] or [tmp], it means we failed to resolve it.
// Stop here to prevent sending a broken path like /temp/... to the OS.
if (cleaned_path.includes('[home]') || cleaned_path.includes('[tmp]')) {
console.error('Relay Error: Could not resolve path placeholders. Home or Tmp directory unknown.', { home, tmp });
return { success: false, error: 'Could not resolve path placeholders' };
}
if (platform === 'linux') {
if (log_lvl) console.log(`Relay: Launching LibreOffice on Linux for path: ${cleaned_path}`);
return await run_cmd({ cmd: `libreoffice --impress "${cleaned_path}"` });
}
if (platform === 'darwin') {
if (app === 'keynote') {
return await run_osascript(`tell application "Keynote" to open POSIX file "${cleaned_path}"`);
}
return await open_local_file_v2(cleaned_path);
}
return await open_local_file_v2(cleaned_path);
}