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:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { ae_loc, ae_api } from '$lib/stores/ae_stores';
|
||||
import { events_slct } from '$lib/stores/ae_events_stores';
|
||||
import { events_slct, events_sess } from '$lib/stores/ae_events_stores';
|
||||
import { events_func } from '$lib/ae_events_functions';
|
||||
import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||
import { db_events } from '$lib/ae_events/db_events';
|
||||
@@ -35,7 +35,21 @@
|
||||
let is_syncing = false;
|
||||
let show_monitor = $state(false);
|
||||
|
||||
onMount(() => {
|
||||
onMount(async () => {
|
||||
// 1. Initial hydration of native metadata (Phase 5)
|
||||
if ($ae_loc.is_native) {
|
||||
try {
|
||||
const info = await native.get_device_info();
|
||||
if (info) {
|
||||
$ae_loc.home_directory = info.home_directory;
|
||||
$ae_loc.tmp_directory = info.tmp_directory;
|
||||
if (log_lvl) console.log('Sync: Native OS metadata hydrated.', { home: info.home_directory });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Sync: Metadata hydration FAILED:', err);
|
||||
}
|
||||
}
|
||||
|
||||
const dev = $ae_loc.native_device || {};
|
||||
|
||||
// Load timings from device config
|
||||
@@ -107,6 +121,7 @@
|
||||
|
||||
missing_count++;
|
||||
currently_syncing = file_obj.filename;
|
||||
$events_sess.launcher.sync_stats.currently_syncing = currently_syncing;
|
||||
|
||||
const url = `${$ae_api.base_url}/hosted_file/${file_obj.hosted_file_id}/download?return_file=true&filename=${encodeURIComponent(file_obj.filename)}`;
|
||||
const result = await native.download_to_cache({
|
||||
@@ -119,10 +134,19 @@
|
||||
}
|
||||
sync_stats.cached = cached_count;
|
||||
sync_stats.missing = missing_count;
|
||||
|
||||
// Sync to shared store
|
||||
$events_sess.launcher.sync_stats = {
|
||||
total: sync_stats.total,
|
||||
cached: sync_stats.cached,
|
||||
missing: sync_stats.missing,
|
||||
currently_syncing: null
|
||||
};
|
||||
} catch (err) {
|
||||
console.error('Sync Engine Error:', err);
|
||||
} finally {
|
||||
currently_syncing = null;
|
||||
$events_sess.launcher.sync_stats.currently_syncing = null;
|
||||
is_syncing = false;
|
||||
}
|
||||
}
|
||||
@@ -137,6 +161,7 @@
|
||||
|
||||
if (!device_id) {
|
||||
if (log_lvl) console.warn('Sync: Heartbeat skipped, no device_id found in $ae_loc.native_device.');
|
||||
$events_sess.launcher.heartbeat_info.status = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -149,8 +174,8 @@
|
||||
}
|
||||
|
||||
const update_payload: any = {
|
||||
// Use standard toISOString() for unambiguous UTC on server
|
||||
heartbeat: new Date().toISOString()
|
||||
// Use standard SQL format YYYY-MM-DD HH:mm:ss for MySQL compatibility
|
||||
heartbeat: ae_util.iso_datetime_formatter(new Date(), 'datetime_iso')
|
||||
};
|
||||
|
||||
if (info) {
|
||||
@@ -177,9 +202,14 @@
|
||||
});
|
||||
|
||||
last_heartbeat = new Date().toLocaleTimeString();
|
||||
$events_sess.launcher.heartbeat_info = {
|
||||
last_timestamp: last_heartbeat,
|
||||
status: 'success'
|
||||
};
|
||||
if (log_lvl > 1) console.log('Sync: Device heartbeat SUCCESS.');
|
||||
} catch (err) {
|
||||
console.error('Sync: Device heartbeat FAILED:', err);
|
||||
$events_sess.launcher.heartbeat_info.status = 'error';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user