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

@@ -44,21 +44,27 @@ const axios_1 = __importDefault(require("axios"));
const file_utils_1 = require("./file_utils");
let endpoints_in_progress = [];
function registerFileHandlers() {
function get_legacy_hashed_path(root, hash) {
return path.join((0, file_utils_1.expandPath)(root), `${hash}.file`);
// Flexible organization: [root]/[prefix_len-char-prefix]/[hash].file
function get_organized_hashed_path(root, hash, prefix_len = 2) {
const expanded_root = (0, file_utils_1.expandPath)(root);
const prefix = hash.substring(0, Math.max(1, Math.min(prefix_len, 8)));
const dir = path.join(expanded_root, prefix);
if (!fs.existsSync(dir))
fs.mkdirSync(dir, { recursive: true });
return path.join(dir, `${hash}.file`);
}
electron_1.ipcMain.handle('native:check-cache', async (event, { cache_root, hash }) => {
const full_path = get_legacy_hashed_path(cache_root, hash);
electron_1.ipcMain.handle('native:check-cache', async (event, { cache_root, hash, hash_prefix_length = 2 }) => {
const full_path = get_organized_hashed_path(cache_root, hash, hash_prefix_length);
return fs.existsSync(full_path);
});
electron_1.ipcMain.handle('native:download-to-cache', async (event, { url, cache_root, hash, api_key, account_id }) => {
const full_path = get_legacy_hashed_path(cache_root, hash);
electron_1.ipcMain.handle('native:download-to-cache', async (event, { url, cache_root, hash, api_key, account_id, hash_prefix_length = 2 }) => {
const full_path = get_organized_hashed_path(cache_root, hash, hash_prefix_length);
const tmp_path = `${full_path}.tmp`;
if (endpoints_in_progress.includes(url))
return { success: true, status: 'in_progress' };
if (fs.existsSync(full_path))
return { success: true, path: full_path, status: 'exists' };
console.log(`Native: Downloading ${hash} -> ${full_path}`);
console.log(`Native: Organized Download (${hash_prefix_length} chars) -> ${full_path}`);
try {
endpoints_in_progress.push(url);
const response = await (0, axios_1.default)({
@@ -87,9 +93,9 @@ function registerFileHandlers() {
endpoints_in_progress = endpoints_in_progress.filter(e => e !== url);
}
});
electron_1.ipcMain.handle('native:launch-from-cache', async (event, { cache_root, hash, temp_root, filename }) => {
electron_1.ipcMain.handle('native:launch-from-cache', async (event, { cache_root, hash, temp_root, filename, hash_prefix_length = 2 }) => {
try {
const source = get_legacy_hashed_path(cache_root, hash);
const source = get_organized_hashed_path(cache_root, hash, hash_prefix_length);
const expanded_temp = (0, file_utils_1.expandPath)(temp_root);
const target = path.join(expanded_temp, filename);
if (!fs.existsSync(expanded_temp))