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:
Scott Idem
2026-01-23 17:23:14 -05:00
parent f6875acc72
commit e942b234c4
11 changed files with 170 additions and 112 deletions

View File

@@ -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
};
});

View File

@@ -1,37 +1,60 @@
import { ipcMain, shell } from 'electron';
import { exec } from 'child_process';
import * as path from 'path';
import { exec, execSync } from 'child_process';
import * as fs from 'fs';
import * as os from 'os';
export function registerShellHandlers() {
// Open a local directory in the OS File Manager
ipcMain.handle('native:open-folder', async (event, folderPath: string) => {
console.log(`Native: Opening folder ${folderPath}`);
const error = await shell.openPath(folderPath);
return { success: !error, error };
});
// Run a generic shell command (Whitelisted logic can be added here)
ipcMain.handle('native:run-cmd', async (event, command: string) => {
console.log(`Native: Running command: ${command}`);
ipcMain.handle('native:run-cmd', async (event, { cmd, timeout = 30000 }) => {
return new Promise((resolve) => {
exec(command, (error, stdout, stderr) => {
resolve({
success: !error,
stdout,
stderr,
error: error ? error.message : null
});
exec(cmd, { timeout }, (error, stdout, stderr) => {
resolve({ success: !error, stdout: stdout.trim(), stderr: stderr.trim(), error: error ? error.message : null });
});
});
});
// Specific handler for launching a presentation file
ipcMain.handle('native:launch-file', async (event, filePath: string) => {
console.log(`Native: Launching file: ${filePath}`);
if (!fs.existsSync(filePath)) {
return { success: false, error: 'File not found' };
ipcMain.handle('native:run-cmd-sync', async (event, { cmd }) => {
try {
const stdout = execSync(cmd).toString();
return { success: true, stdout: stdout.trim() };
} catch (error: any) {
return { success: false, error: error.message, stderr: error.stderr?.toString() };
}
});
ipcMain.handle('native:run-osascript', async (event, script: string) => {
if (os.platform() !== 'darwin') return { success: false, error: 'AppleScript is only available on macOS' };
const escapedScript = script.replace(/"/g, '\"');
const cmd = `osascript -e "${escapedScript}"`;
return new Promise((resolve) => {
exec(cmd, (error, stdout, stderr) => {
resolve({ success: !error, stdout: stdout.trim(), stderr: stderr.trim(), error: error ? error.message : null });
});
});
});
ipcMain.handle('native:kill-processes', async (event, { process_name_li = [] }) => {
console.log(`Native: Killing processes -> `, process_name_li);
const results = [];
for (const name of process_name_li) {
const cmd = os.platform() === 'win32'
? `taskkill /F /IM ${name} /T`
: `pkill -f ${name}`;
try {
execSync(cmd);
results.push({ name, success: true });
} catch (e: any) {
results.push({ name, success: false, error: e.message });
}
}
return { success: true, results };
});
ipcMain.handle('native:open-local-file-v2', async (event, filePath: string) => {
const error = await shell.openPath(filePath);
return { success: !error, error };
});

View File

@@ -4,14 +4,15 @@ contextBridge.exposeInMainWorld('aetherNative', {
get_seed_config: () => ipcRenderer.invoke('get-seed-config'),
get_device_config: () => ipcRenderer.invoke('get-device-config'),
get_jwt: () => ipcRenderer.invoke('get-jwt'),
log: (message: string) => console.log('[Native Log]', message),
get_device_info: () => ipcRenderer.invoke('get-device-info'),
// Shell Handlers
open_folder: (path: string) => ipcRenderer.invoke('native:open-folder', path),
run_command: (args: any) => ipcRenderer.invoke('native:run-cmd', args),
launch_file: (path: string) => ipcRenderer.invoke('native:launch-file', path),
run_cmd: (args: any) => ipcRenderer.invoke('native:run-cmd', args),
run_cmd_sync: (args: any) => ipcRenderer.invoke('native:run-cmd-sync', args),
run_osascript: (script: string) => ipcRenderer.invoke('native:run-osascript', script),
kill_processes: (args: any) => ipcRenderer.invoke('native:kill-processes', args),
open_local_file_v2: (path: string) => ipcRenderer.invoke('native:open-local-file-v2', path),
// File/Cache Handlers
check_cache: (args: any) => ipcRenderer.invoke('native:check-cache', args),
download_to_cache: (args: any) => ipcRenderer.invoke('native:download-to-cache', args),
launch_from_cache: (args: any) => ipcRenderer.invoke('native:launch-from-cache', args),