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