Working on opening local files

This commit is contained in:
Scott Idem
2022-03-10 18:19:35 -05:00
parent f0bf184a4a
commit 437b9af482
5 changed files with 136 additions and 10 deletions

View File

@@ -173,6 +173,39 @@
z-index: 500;
}
.event_launcher_status {
outline: dashed thin red;
margin: .1em .4em;
padding: .0em;
position: fixed;
bottom: 0;
right: 0;
/* width: 12em; */
z-index: 500;
display: flex;
flex-direction: row;
/* flex-wrap: nowrap; */
justify-content: center;
align-items: center;
align-content: center;
font-size: .7em;
}
.event_launcher_status:hover {
font-size: 1.1em;
font-weight: bold;
}
.event_launcher_status > .network_status {
margin: .2em .2em;
}
.event_launcher_status > .current_datetime {
margin: .2em .2em;
}
.event_launcher_main_content header.event_session_about {

View File

@@ -71,6 +71,25 @@ exports.load_config = function () {
}
// Check for local file
// Updated 2022-03-10
exports.check_local_file = async function ({local_file_path, filename}) {
console.log('*** Electron framework export: check_local_file() ***');
console.log('Check for local file');
console.log(`Local File Path: ${local_file_path}; Filename: ${filename}`);
let 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}`);
return true;
} else {
return false;
}
}
// Check local hash file cache
// Updated 2022-03-09
exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
@@ -84,13 +103,15 @@ exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
// console.log(hash_file_cache_path);
if (fs.existsSync(hash_file_cache_path)) {
console.log(`Hashed file cache already exists: ${hash_file_cache_path}`);
console.log(`Hashed file exists in cache: ${hash_file_cache_path}`);
return true;
} else {
console.log(`Hashed file not found in cache: ${hash_file_cache_path}`);
return false;
}
}
// Download hash file to cache
// Updated 2022-03-09
exports.download_hash_file_to_cache = async function ({host_file_cache_path, event_file_id=null, hash=null}) {
@@ -121,8 +142,9 @@ exports.download_hash_file_to_cache = async function ({host_file_cache_path, eve
}
}
// Open cached hash file after copying to temp directory
// Updated 2022-03-07
// Updated 2022-03-09
exports.open_hash_file_to_temp = async function ({host_file_cache_path, hash, host_file_temp_path, filename}) {
console.log('*** Electron framework export: open_hash_file_to_temp() ***');
console.log('Open cached hash file after copying to temp directory');
@@ -149,6 +171,40 @@ exports.open_hash_file_to_temp = async function ({host_file_cache_path, hash, ho
}
// Open local file
// Updated 2022-03-10
exports.open_local_file = async function ({local_file_path, filename}) {
console.log('*** Electron framework export: open_local_file() ***');
console.log('Open local file');
console.log(`Local File Path: ${local_file_path}; Filename: ${filename}`);
// let 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}`);
// // return true;
// } else {
// return false;
// }
let open_local_file_result = await ipcRenderer.invoke('open_local_file', local_file_path, filename).then((result) => {
console.log('IPC open local file finished');
console.log(result);
return true;
})
console.log(open_local_file_result);
console.log('End: open_local_file()');
if (open_local_file_result) {
console.log('File opened successfully');
return true;
} else {
console.log('File was not opened successfully');
return false;
}
}

View File

@@ -0,0 +1 @@
launcher reset

1
app/static/test.txt Normal file
View File

@@ -0,0 +1 @@
test txt

View File

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