Clean up of launcher and added new Node and Electron functions

This commit is contained in:
Scott Idem
2022-05-06 14:50:52 -04:00
parent 98bd835342
commit 4c65d9dc42
5 changed files with 131 additions and 18 deletions

View File

@@ -100,13 +100,16 @@
console.log(api_secret_key);
let api_temporary_token = null;
let api_base_url = null;
let api_server_base_url = app_config.api_server_base_url; // null;
let api_server_base_url_bak = app_config.api_server_base_url_bak;
let app_server_base_url = app_config.app_server_base_url;
// let file_base_url = app_config.file_server_base_url;
if (app_config.use_local_api) {
api_base_url = app_config.api_local_base_url; // 'http://api.localhost:5001'
} else {
api_base_url = app_config.api_remote_base_url; // 'https://api.oneskyit.com'
}
// if (app_config.use_local_api) {
// api_server_base_url = app_config.api_local_base_url; // 'http://api.localhost:5001'
// } else {
// api_server_base_url = app_config.api_remote_base_url; // 'https://api.oneskyit.com'
// }
/* ***** **** *** ** * ### * ** *** **** ***** */

View File

@@ -2,8 +2,12 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
const child_process = require('child_process');
const { ipcRenderer } = require('electron');
// import psList from 'ps-list';
// const ps_list = require('ps-list');
let home_directory = require('os').homedir();
console.log('Home: '+home_directory);
@@ -77,13 +81,26 @@ exports.load_config = function () {
//close();
}
config.home_directory = home_directory; // From the OS platform
config.tmp_directory = tmp_directory; // From the OS platform
config.host_file_cache_path = config.host_file_cache_path.replace('[home]', home_directory);
config.host_file_cache_path = config.host_file_cache_path.replace('[tmp]', tmp_directory);
console.log(config.host_file_cache_path);
// if (fs.existsSync(config.host_file_cache_path)) {
// } else {
// fs.mkdirSync(config.host_file_cache_path);
// console.log(`Host file cache directory created: ${config.host_file_cache_path}`);
// }
config.host_file_temp_path = config.host_file_temp_path.replace('[home]', home_directory);
config.host_file_temp_path = config.host_file_temp_path.replace('[tmp]', tmp_directory);
console.log(config.host_file_temp_path);
// if (fs.existsSync(config.host_file_temp_path)) {
// } else {
// fs.mkdirSync(config.host_file_temp_path);
// console.log(`Host file temp directory created: ${config.host_file_temp_path}`);
// }
let import_config_to_ipc_result = ipcRenderer.invoke('import_config', config).then((result) => {
console.log('IPC import config finished');
@@ -97,7 +114,7 @@ exports.load_config = function () {
// Check for local file
// Updated 2022-03-10
// Updated 2022-05-06
exports.check_local_file = async function ({local_file_path, filename}) {
console.log('*** Electron framework export: check_local_file() ***');
// console.log('Check for local file');
@@ -116,7 +133,7 @@ exports.check_local_file = async function ({local_file_path, filename}) {
// Check local hash file cache
// Updated 2022-03-09
// Updated 2022-05-06
exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
console.log('*** Electron framework export: check_hash_file_cache() ***');
// console.log('Check local hash file cache');
@@ -124,7 +141,15 @@ exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
let hash_filename = `${hash}.file`;
let hash_file_cache_path = path.join(host_file_cache_path, hash_filename);
let subdirectory = hash_filename.substring(0,2);
let subdirectory_path = path.join(host_file_cache_path, subdirectory);
if (fs.existsSync(subdirectory_path)) {
} else {
console.log(`Hashed file subdirectory not found in cache: ${subdirectory_path}`);
return false;
}
let hash_file_cache_path = path.join(subdirectory_path, hash_filename);
// console.log(hash_file_cache_path);
if (fs.existsSync(hash_file_cache_path)) {
@@ -138,7 +163,7 @@ exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
// Download hash file to cache
// Updated 2022-03-09
// Updated 2022-05-06
exports.download_hash_file_to_cache = async function ({host_file_cache_path, event_file_id=null, hash=null}) {
console.log('*** Electron framework export: download_hash_file_to_cache() ***');
// console.log('Download hash file to cache');
@@ -147,7 +172,16 @@ exports.download_hash_file_to_cache = async function ({host_file_cache_path, eve
let endpoint = `/event/file/${event_file_id}/download`;
let hash_filename = `${hash}.file`;
let hash_file_cache_path = path.join(host_file_cache_path, hash_filename);
let subdirectory = hash_filename.substring(0,2);
let subdirectory_path = path.join(host_file_cache_path, subdirectory);
if (fs.existsSync(subdirectory_path)) {
} else {
fs.mkdirSync(subdirectory_path);
console.log(`Subdirectory directory created: ${subdirectory_path}`);
}
let hash_file_cache_path = path.join(subdirectory_path, hash_filename);
// console.log(hash_file_cache_path);
let download_file_result = await ipcRenderer.invoke('download_file', api_base_url, endpoint, hash_file_cache_path).then((result) => {
@@ -169,13 +203,21 @@ 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-09
// Updated 2022-05-06
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');
console.log(`Host File Cache Path: ${host_file_cache_path}; Hash: ${hash}; Host File Temp Path: ${host_file_temp_path}; Filename: ${filename}`);
let open_hash_file_to_temp_result = await ipcRenderer.invoke('open_hash_file_to_temp', host_file_cache_path, hash, host_file_temp_path, filename).then((result) => {
let subdirectory = hash.substring(0,2);
let subdirectory_path = path.join(host_file_cache_path, subdirectory);
if (fs.existsSync(subdirectory_path)) {
} else {
console.log(`Hashed file subdirectory not found in cache: ${subdirectory_path}`);
return false;
}
let open_hash_file_to_temp_result = await ipcRenderer.invoke('open_hash_file_to_temp', subdirectory_path, hash, host_file_temp_path, filename).then((result) => {
console.log('IPC open hash file to temp finished');
console.log(result);
return true;
@@ -384,7 +426,36 @@ exports.check_file_cache_and_open_local_file = async function ({host_file_cache_
return open_local_file_result;
})
}
// Kill processes
// Updated 2022-05-06
exports.kill_processes = async function ({process_name = null}) {
console.log('*** Electron framework export: kill_processes() ***');
console.log(process_name); // process_name or grep pattern
let command = `pkill ${process_name}`;
child_process.exec(command, (err, stdout, stdin) => {
if (err) throw err;
console.log(stdout);
});
console.log('Killed processes?');
// let command = `ps -aux | grep ${process_name}`;
// child_process.exec(command, (err, stdout, stdin) => {
// if (err) throw err;
// console.log(stdout);
// });
// console.log(await psList());
// console.log(await ps_list());
// let signal = 'SIGTERM'; // 'SIGTERM', 'SIGINT', 'SIGHUP'
// process.kill(pid, signal);
// process.kill(pid, 0); // Special case test if process exists
return true;
}

View File

@@ -9,7 +9,16 @@
"event_location_code": "",
"event_session_id": "",
"api_secret_key": "XXXXXX",
"api_secret_key": "ABCD1234XYZ",
"api_server_base_url": "http://dev-api.oneskyit.local:5005",
"app_server_base_url": "http://dev-demo.oneskyit.local:5000",
"file_server_base_url": "",
"api_server_base_url_bak": "https://dev-api.oneskyit.com",
"app_server_base_url_bak": "https://dev-demo.oneskyit.com",
"file_server_base_url_bak": "",
"api_remote_base_url": "https://dev-fastapi.oneskyit.com",
"api_local_base_url": "http://dev-fastapi.oneskyit.local:5005",
"access_control_allow_origin": "*",

34
package-lock.json generated
View File

@@ -1,18 +1,20 @@
{
"name": "aether_app_native",
"version": "3.0.0",
"version": "3.1.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "aether_app_native",
"version": "3.0.0",
"version": "3.1.0",
"license": "ISC",
"dependencies": {
"axios": "^0.26.0",
"child_process": "^1.0.2",
"fs": "0.0.1-security",
"os": "^0.1.1",
"path": "^0.12.7"
"path": "^0.12.7",
"ps-list": "^8.1.0"
},
"devDependencies": {
"electron": "^17.4.0",
@@ -293,6 +295,11 @@
"node": ">=8"
}
},
"node_modules/child_process": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/child_process/-/child_process-1.0.2.tgz",
"integrity": "sha1-sffn/HPSXn/R1FWtyU4UODAYK1o="
},
"node_modules/chromium-pickle-js": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/chromium-pickle-js/-/chromium-pickle-js-0.2.0.tgz",
@@ -1635,6 +1642,17 @@
"dev": true,
"optional": true
},
"node_modules/ps-list": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/ps-list/-/ps-list-8.1.0.tgz",
"integrity": "sha512-NoGBqJe7Ou3kfQxEvDzDyKGAyEgwIuD3YrfXinjcCmBRv0hTld0Xb71hrXvtsNPj7HSFATfemvzB8PPJtq6Yag==",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
@@ -2279,6 +2297,11 @@
}
}
},
"child_process": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/child_process/-/child_process-1.0.2.tgz",
"integrity": "sha1-sffn/HPSXn/R1FWtyU4UODAYK1o="
},
"chromium-pickle-js": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/chromium-pickle-js/-/chromium-pickle-js-0.2.0.tgz",
@@ -3348,6 +3371,11 @@
"dev": true,
"optional": true
},
"ps-list": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/ps-list/-/ps-list-8.1.0.tgz",
"integrity": "sha512-NoGBqJe7Ou3kfQxEvDzDyKGAyEgwIuD3YrfXinjcCmBRv0hTld0Xb71hrXvtsNPj7HSFATfemvzB8PPJtq6Yag=="
},
"pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",

View File

@@ -13,9 +13,11 @@
"license": "ISC",
"dependencies": {
"axios": "^0.26.0",
"child_process": "^1.0.2",
"fs": "0.0.1-security",
"os": "^0.1.1",
"path": "^0.12.7"
"path": "^0.12.7",
"ps-list": "^8.1.0"
},
"devDependencies": {
"electron": "^17.4.0",