Enhance: Implement exhaustive background caching and recursive data loading

- Implemented aggressive room-wide background caching engine in LauncherBackgroundSync.svelte.
- Added inc_file_li and inc_all_file_li support to Event and Event Location object loaders for total room coverage.
- Switched to proven V1 download path (/hosted_file/) to resolve V3 CRUD binary delivery issues.
- Optimized Electron bridge with download locking and flat-hash storage matching legacy 'perfect' logic.
- Standardized all Electron IPC methods and parameters to snake_case.
- Added visual sync progress indicator for room caching status.
This commit is contained in:
Scott Idem
2026-01-23 16:30:03 -05:00
parent 683ea0394d
commit dc38c2c10c
10 changed files with 236 additions and 195 deletions

View File

@@ -1,123 +1,76 @@
/**
* Aether Electron Relay (V3)
* Maps legacy launcher commands to the modern Aether Native Bridge.
* Aether Native Bridge Relay (TypeScript)
* Standardizes communication between SvelteKit and the Electron Main process.
*/
const log_lvl = 1;
// Handle the standardized aetherNative bridge
const native = (typeof window !== 'undefined') ? (window as any).aetherNative : null;
/**
* Returns the native bridge if available.
*/
function getBridge() {
if (typeof window !== 'undefined' && (window as any).aetherNative) {
return (window as any).aetherNative;
}
return null;
export async function get_device_config(): Promise<any> {
if (!native) return null;
return await native.get_device_config();
}
/**
* Open a local directory in the OS File Manager.
*/
export async function open_folder(path: string) {
const bridge = getBridge();
if (!bridge) return { success: false, error: 'Native bridge not found' };
if (log_lvl) console.log(`Relay: Opening folder: ${path}`);
return await bridge.openFolder(path);
// --- File Operations ---
export async function check_hash_file_cache({ cache_root, hash }: { cache_root: string; hash: string }): Promise<boolean> {
if (!native) return false;
// Uses the specific bridge method instead of generic invoke
return await native.check_cache({ cache_root, hash });
}
/**
* Launch a file using the OS default application.
*/
export async function launch_file(path: string) {
const bridge = getBridge();
if (!bridge) return { success: false, error: 'Native bridge not found' };
if (log_lvl) console.log(`Relay: Launching file: ${path}`);
return await bridge.launchFile(path);
export async function download_to_cache({
url,
cache_root,
hash,
api_key,
account_id
}: {
url: string;
cache_root: string;
hash: string;
api_key: string;
account_id: string;
}): Promise<{ success: boolean; path?: string; error?: string }> {
if (!native) return { success: false, error: 'Native bridge not available' };
return await native.download_to_cache({ url, cache_root, hash, api_key, account_id });
}
/**
* Legacy compatibility alias for launch_file.
*/
export const open_local_file_v2 = async ({ file_path, filename }: { file_path: string, filename: string }) => {
return launch_file(`${file_path}/${filename}`);
};
/**
* Run a shell command.
*/
export async function run_cmd({ cmd, return_stdout = true }: { cmd: string, return_stdout?: boolean }) {
const bridge = getBridge();
if (!bridge) return { success: false, error: 'Native bridge not found' };
if (log_lvl) console.log(`Relay: Running command: ${cmd}`);
const result = await bridge.runCommand(cmd);
if (return_stdout) return result.stdout;
return result.success;
export async function launch_from_cache({
cache_root,
hash,
temp_root,
filename
}: {
cache_root: string;
hash: string;
temp_root: string;
filename: string;
}): Promise<{ success: boolean; error?: string }> {
if (!native) return { success: false, error: 'Native bridge not available' };
return await native.launch_from_cache({ cache_root, hash, temp_root, filename });
}
/**
* Legacy compatibility alias for run_cmd.
*/
export const run_cmd_sync = run_cmd;
// --- OS Operations ---
/**
* Kill specific processes by name.
*/
export async function kill_processes({ process_name_li = [] }: { process_name_li: string[] }) {
const bridge = getBridge();
if (!bridge) return { success: false, error: 'Native bridge not found' };
for (const name of process_name_li) {
if (log_lvl) console.log(`Relay: Killing process: ${name}`);
await bridge.runCommand(`pkill -f "${name}"`);
}
return true;
export async function open_folder(path: string): Promise<void> {
if (!native) return;
return await native.open_folder(path);
}
/**
* Check if a file hash exists in the local cache.
*/
export async function check_hash_file_cache({ cacheRoot, hash }: { cacheRoot: string, hash: string }) {
const bridge = getBridge();
if (!bridge) return false;
return await bridge.checkCache({ cacheRoot, hash });
export async function run_cmd({ cmd, return_stdout = false }: { cmd: string; return_stdout?: boolean }): Promise<string | boolean> {
if (!native) return false;
return await native.run_command({ cmd, return_stdout });
}
/**
* Download a file to the local cache.
*/
export async function download_to_cache({ url, cacheRoot, hash, apiKey }: { url: string, cacheRoot: string, hash: string, apiKey: string }) {
const bridge = getBridge();
if (!bridge) return { success: false, error: 'Native bridge not found' };
return await bridge.downloadToCache({ url, cacheRoot, hash, apiKey });
export async function run_cmd_sync({ cmd, return_stdout = false }: { cmd: string; return_stdout?: boolean }): Promise<string | boolean> {
if (!native) return false;
// Legacy mapping to the same command handler
return await native.run_command({ cmd, return_stdout });
}
/**
* Launch a file from the local cache (copies to temp first).
*/
export async function launch_from_cache({ cacheRoot, hash, tempRoot, filename }: { cacheRoot: string, hash: string, tempRoot: string, filename: string }) {
const bridge = getBridge();
if (!bridge) return { success: false, error: 'Native bridge not found' };
return await bridge.launchFromCache({ cacheRoot, hash, tempRoot, filename });
}
/**
* Get system/device info.
*/
export async function get_device_info() {
const bridge = getBridge();
if (!bridge) return null;
return await bridge.getDeviceConfig();
}
/**
* Placeholder for legacy AppleScript execution.
*/
export async function run_osascript({ cmd }: { cmd: string }) {
const bridge = getBridge();
if (!bridge) return null;
return await bridge.runCommand(`osascript -e '${cmd}'`);
}
// --- Compatibility Aliases (Legacy) ---
export const open_local_file_v2 = launch_from_cache;
export const get_device_info = get_device_config;
export const run_osascript = async ({ cmd }: { cmd: string }) => await run_cmd({ cmd: `osascript -e '${cmd}'` });
export const kill_processes = async ({ process_name }: { process_name: string }) => await run_cmd({ cmd: `pkill -f '${process_name}'` });