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

@@ -36,34 +36,57 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.registerShellHandlers = registerShellHandlers;
const electron_1 = require("electron");
const child_process_1 = require("child_process");
const fs = __importStar(require("fs"));
const os = __importStar(require("os"));
function registerShellHandlers() {
// Open a local directory in the OS File Manager
electron_1.ipcMain.handle('native:open-folder', async (event, folderPath) => {
console.log(`Native: Opening folder ${folderPath}`);
const error = await electron_1.shell.openPath(folderPath);
return { success: !error, error };
});
// Run a generic shell command (Whitelisted logic can be added here)
electron_1.ipcMain.handle('native:run-cmd', async (event, command) => {
console.log(`Native: Running command: ${command}`);
electron_1.ipcMain.handle('native:run-cmd', async (event, { cmd, timeout = 30000 }) => {
return new Promise((resolve) => {
(0, child_process_1.exec)(command, (error, stdout, stderr) => {
resolve({
success: !error,
stdout,
stderr,
error: error ? error.message : null
});
(0, child_process_1.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
electron_1.ipcMain.handle('native:launch-file', async (event, filePath) => {
console.log(`Native: Launching file: ${filePath}`);
if (!fs.existsSync(filePath)) {
return { success: false, error: 'File not found' };
electron_1.ipcMain.handle('native:run-cmd-sync', async (event, { cmd }) => {
try {
const stdout = (0, child_process_1.execSync)(cmd).toString();
return { success: true, stdout: stdout.trim() };
}
catch (error) {
return { success: false, error: error.message, stderr: error.stderr?.toString() };
}
});
electron_1.ipcMain.handle('native:run-osascript', async (event, script) => {
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) => {
(0, child_process_1.exec)(cmd, (error, stdout, stderr) => {
resolve({ success: !error, stdout: stdout.trim(), stderr: stderr.trim(), error: error ? error.message : null });
});
});
});
electron_1.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 {
(0, child_process_1.execSync)(cmd);
results.push({ name, success: true });
}
catch (e) {
results.push({ name, success: false, error: e.message });
}
}
return { success: true, results };
});
electron_1.ipcMain.handle('native:open-local-file-v2', async (event, filePath) => {
const error = await electron_1.shell.openPath(filePath);
return { success: !error, error };
});