Fix: Finalize Phase 3 OS interactions and telemetry bridge
- Implemented get_device_info for OS/Network telemetry. - Added run_cmd_sync using execSync for blocking-style commands. - Implemented kill_processes (plural) to support multiple process termination. - Standardized open_local_file_v2 and all bridge methods to snake_case. - Synchronized preload and main handlers with SvelteKit relay expectations.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { app, BrowserWindow, ipcMain } from 'electron';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { loadSeedConfig } from './config_loader';
|
||||
import { fetchFullConfig } from './api_client';
|
||||
import { registerShellHandlers } from './shell_handlers';
|
||||
@@ -11,7 +12,6 @@ let cachedSeed: SeedConfig | null = null;
|
||||
let cachedFullConfig: any = null;
|
||||
|
||||
async function createWindow() {
|
||||
// 1. Initial Load of Configs
|
||||
cachedSeed = await loadSeedConfig();
|
||||
if (cachedSeed) {
|
||||
cachedFullConfig = await fetchFullConfig(cachedSeed);
|
||||
@@ -28,59 +28,57 @@ async function createWindow() {
|
||||
},
|
||||
});
|
||||
|
||||
// Determine target URL based on hydrated config
|
||||
let targetUrl = 'http://demo.localhost:5173';
|
||||
|
||||
if (cachedFullConfig && cachedFullConfig.native_device) {
|
||||
const device = cachedFullConfig.native_device;
|
||||
const eventId = device.event_id_random || device.event_id;
|
||||
const locationId = device.event_location_id_random || device.event_location_id || '';
|
||||
const host = device.app_base_url || 'demo.localhost:5173';
|
||||
|
||||
const useHost = (host.includes('localhost')) ? host : 'demo.localhost:5173';
|
||||
|
||||
targetUrl = `http://${useHost}/events/${eventId}/launcher/${locationId}`;
|
||||
}
|
||||
|
||||
console.log(`Launcher: Navigating to ${targetUrl}`);
|
||||
|
||||
mainWindow.loadURL(targetUrl).catch(() => {
|
||||
console.warn(`Failed to load ${targetUrl}. Falling back to dev-demo...`);
|
||||
mainWindow?.loadURL('https://dev-demo.oneskyit.com/');
|
||||
});
|
||||
|
||||
mainWindow.on('closed', () => {
|
||||
mainWindow = null;
|
||||
});
|
||||
mainWindow.on('closed', () => { mainWindow = null; });
|
||||
}
|
||||
|
||||
// Register OS-level handlers
|
||||
registerShellHandlers();
|
||||
registerFileHandlers();
|
||||
|
||||
app.on('ready', createWindow);
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
if (process.platform !== 'darwin') app.quit();
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
if (mainWindow === null) {
|
||||
createWindow();
|
||||
if (mainWindow === null) createWindow();
|
||||
});
|
||||
|
||||
ipcMain.handle('get-seed-config', async () => cachedSeed || await loadSeedConfig());
|
||||
ipcMain.handle('get-device-config', async () => cachedFullConfig);
|
||||
ipcMain.handle('get-jwt', async () => null);
|
||||
|
||||
ipcMain.handle('get-device-info', async () => {
|
||||
const interfaces = os.networkInterfaces();
|
||||
const addresses: string[] = [];
|
||||
for (const name of Object.keys(interfaces)) {
|
||||
for (const net of interfaces[name]!) {
|
||||
if (net.family === 'IPv4' && !net.internal) {
|
||||
addresses.push(net.address);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// IPC Handlers
|
||||
ipcMain.handle('get-seed-config', async () => {
|
||||
return cachedSeed || await loadSeedConfig();
|
||||
});
|
||||
|
||||
ipcMain.handle('get-device-config', async () => {
|
||||
return cachedFullConfig;
|
||||
});
|
||||
|
||||
ipcMain.handle('get-jwt', async () => {
|
||||
return null;
|
||||
return {
|
||||
platform: os.platform(),
|
||||
release: os.release(),
|
||||
arch: os.arch(),
|
||||
hostname: os.hostname(),
|
||||
cpus: os.cpus().length,
|
||||
total_mem: os.totalmem(),
|
||||
free_mem: os.freemem(),
|
||||
ip_addresses: addresses
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user