Working on opening local files
This commit is contained in:
39
index.js
39
index.js
@@ -203,8 +203,8 @@ ipcMain.handle('open_hash_file_to_temp', async (event, host_file_cache_path, has
|
||||
}
|
||||
|
||||
if (fs.existsSync(full_cache_file_path)) {
|
||||
console.log('Hashed file cache exists: '+full_cache_file_path);
|
||||
console.log('Copying file to temp: '+open_temp_file_path);
|
||||
console.log(`Hashed file exists in cache: ${full_cache_file_path}`);
|
||||
console.log(`Copying file to temp: ${open_temp_file_path}`);
|
||||
try {
|
||||
await fs.copyFileSync(full_cache_file_path, open_temp_file_path);
|
||||
} catch (error) {
|
||||
@@ -215,6 +215,7 @@ ipcMain.handle('open_hash_file_to_temp', async (event, host_file_cache_path, has
|
||||
// console.log('Creating file link: '+open_temp_file_path);
|
||||
// fs.linkSync(full_cache_file_path, open_temp_file_path);
|
||||
} else {
|
||||
console.log(`Hashed file not found in cache: ${full_cache_file_path}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -230,3 +231,37 @@ ipcMain.handle('open_hash_file_to_temp', async (event, host_file_cache_path, has
|
||||
// return 'Return from Electron IPC Main open_hash_file_to_temp()';
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
ipcMain.handle('open_local_file', async (event, local_file_path, filename, use_cwd=true) => {
|
||||
console.log('*** Electron IPC Main: open_local_file() ***');
|
||||
console.log('ipcMain on open_local_file');
|
||||
console.log(`ipcMain open local file from directory: ${local_file_path}/${filename}`);
|
||||
|
||||
let full_local_file_path = null;
|
||||
|
||||
if (use_cwd) {
|
||||
full_local_file_path = path.join(process.cwd(), local_file_path, filename);
|
||||
console.log(full_local_file_path);
|
||||
} else {
|
||||
full_local_file_path = path.join(local_file_path, filename);
|
||||
console.log(full_local_file_path);
|
||||
}
|
||||
|
||||
if (fs.existsSync(full_local_file_path)) {
|
||||
console.log(`Local file exists: ${full_local_file_path}`);
|
||||
} else {
|
||||
console.log(`Local file not found: ${full_local_file_path}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
await shell.openPath(full_local_file_path);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log('End: Electron IPC Main: open_local_file()');
|
||||
return true;
|
||||
});
|
||||
Reference in New Issue
Block a user