feat(bridge): implement presentation-aware handover and robust placeholder resolution

- Upgraded launch_from_cache to automatically trigger LibreOffice/AppleScript launchers after file copy.
- Hardened expandPath to resolve [home] and [tmp] placeholders anywhere in strings via global regex.
- Enhanced get-device-info telemetry to provide absolute home and tmp paths to the UI.
- Exposed native:launch-presentation in preload and implemented explicit LibreOffice (--impress) support on Linux.
This commit is contained in:
Scott Idem
2026-01-26 15:12:11 -05:00
parent e942b234c4
commit 083fc56337
5 changed files with 87 additions and 10 deletions

View File

@@ -1,6 +1,8 @@
import { ipcMain, shell } from 'electron';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { exec } from 'child_process';
import axios from 'axios';
import { expandPath } from './file_utils';
@@ -64,8 +66,43 @@ export function registerFileHandlers() {
const source = get_organized_hashed_path(cache_root, hash, hash_prefix_length);
const expanded_temp = expandPath(temp_root);
const target = path.join(expanded_temp, filename);
console.log(`Native: Launching from Cache -> ${filename}`);
if (!fs.existsSync(expanded_temp)) fs.mkdirSync(expanded_temp, { recursive: true });
// 1. Copy the file to temp folder with original name
fs.copyFileSync(source, target);
// 2. Determine file type
const ext = path.extname(filename).toLowerCase().replace('.', '');
const is_pres = ['pptx', 'ppt', 'key', 'pdf', 'odp'].includes(ext);
// 3. Optimized Launch (LibreOffice / AppleScript)
if (is_pres) {
if (os.platform() === 'linux') {
console.log(`Native: Launching LibreOffice (--impress) for ${target}`);
return new Promise((resolve) => {
exec(`libreoffice --impress "${target}"`, (err) => {
if (err) resolve({ success: false, error: err.message });
else resolve({ success: true });
});
});
}
if (os.platform() === 'darwin' && ext === 'key') {
console.log(`Native: Launching Keynote via AppleScript for ${target}`);
const script = `tell application "Keynote" to open POSIX file "${target}"`;
return new Promise((resolve) => {
exec(`osascript -e "${script.replace(/"/g, '\"')}"`, (err) => {
if (err) resolve({ success: false, error: err.message });
else resolve({ success: true });
});
});
}
}
// 4. Default Fallback
await shell.openPath(target);
return { success: true };
} catch (error: any) {