Clean up and simplify the initial loading. This needs more testing.
This commit is contained in:
78
index.js
78
index.js
@@ -13,6 +13,9 @@ const process = require('process');
|
||||
//const url = require('url');
|
||||
// const usb = require('usb') // Compiled with an old version of Node.js
|
||||
|
||||
console.log(os.type());
|
||||
console.log(process.getSystemVersion());
|
||||
|
||||
let home_directory = require('os').homedir();
|
||||
console.log('Home: '+home_directory);
|
||||
|
||||
@@ -20,27 +23,79 @@ let tmp_directory = require('os').tmpdir();
|
||||
console.log('Temporary: '+tmp_directory);
|
||||
|
||||
// Set the config path for macOS or Linux
|
||||
let config_directory = null;
|
||||
let config_directory = 'OSIT/native_app';
|
||||
let config_filename = 'ae_native_app_config.json';
|
||||
let config_path = '';
|
||||
|
||||
if (os.platform == 'darwin') {
|
||||
let config_path_default = path.join(home_directory, config_directory, config_filename);
|
||||
let config_path_backup = path.join(home_directory, 'Library/Application Support/OSIT', config_filename);
|
||||
// let config_path_opt2 = path.join(home_directory, 'OSIT', config_filename);
|
||||
|
||||
if (fs.existsSync(config_path_default)) {
|
||||
console.log('Default config file path exists: '+config_path_default);
|
||||
config_path = config_path_default;
|
||||
} else if (fs.existsSync(config_path_backup)) {
|
||||
console.log('Backup config file path exists: '+config_path_backup);
|
||||
config_path = config_path_backup;
|
||||
} else {
|
||||
console.log(`No config file found: ${config_path_default} or ${config_path_backup}`);
|
||||
config_path = '';
|
||||
// fs.mkdirSync(local_file_cache_path, true);
|
||||
// console.log('Config directory path created: '+local_file_cache_path);
|
||||
}
|
||||
|
||||
// config_directory = path.join(home_directory, 'Library/Application Support/OSIT');
|
||||
config_directory = path.join(home_directory, 'OSIT/native_app');
|
||||
console.log('macOS config directory: '+config_directory);
|
||||
// config_directory = path.join(home_directory, 'OSIT/native_app');
|
||||
console.log(`macOS config directory: ${config_path}`);
|
||||
} else if (os.platform == 'linux') {
|
||||
config_directory = path.join(home_directory, '.config/OSIT');
|
||||
console.log('Linux config directory: '+config_directory);
|
||||
let config_path_default = path.join(home_directory, config_directory, config_filename);
|
||||
let config_path_backup = path.join(home_directory, '.config/OSIT', config_filename);
|
||||
let config_path_temp = path.join(home_directory, 'tmp/OSIT', config_filename);
|
||||
|
||||
if (fs.existsSync(config_path_default)) {
|
||||
console.log('Default config file path exists: '+config_path_default);
|
||||
config_path = config_path_default;
|
||||
} else if (fs.existsSync(config_path_backup)) {
|
||||
console.log('Backup config file path exists: '+config_path_backup);
|
||||
config_path = config_path_backup;
|
||||
} else if (fs.existsSync(config_path_temp)) {
|
||||
console.log('Temp config file path exists: '+config_path_temp);
|
||||
config_path = config_path_temp;
|
||||
} else {
|
||||
console.log(`No config file found: ${config_path_default} or ${config_path_backup} or ${config_path_temp}`);
|
||||
config_path = '';
|
||||
}
|
||||
|
||||
// config_directory = path.join(home_directory, 'OSIT/native_app');
|
||||
console.log(`Linux config directory: ${config_path}`);
|
||||
}
|
||||
|
||||
// let config_path = path.join(config_directory, 'config.json');
|
||||
let config_path = path.join(config_directory, 'ae_native_app_config.json');
|
||||
// let config_path = path.join(config_directory, config_filename);
|
||||
|
||||
let config = JSON.parse(fs.readFileSync(config_path));
|
||||
console.log('Config file read.', config);
|
||||
/*
|
||||
Minimal Contains:
|
||||
* conf_file_check_path = '~/OSIT/sync/admin_share/internal/ae_osit_app.default.conf'
|
||||
* conf_file_check_path_backup = 'ae_osit_app.conf'
|
||||
|
||||
* api_pref_use = 'local' or 'remote' or 'backup'
|
||||
* api_base_url_local = https://local-api.oneskyit.com
|
||||
* api_base_url_remote = https://api.oneskyit.com
|
||||
* api_base_url_backup = https://bak-api.oneskyit.com
|
||||
|
||||
* app_pref_use = 'local' or 'remote' or 'backup'
|
||||
* app_base_url_local = https://local-demo.oneskyit.com
|
||||
* app_base_url_remote = https://demo.oneskyit.com
|
||||
* app_base_url_backup = https://bak-demo.oneskyit.com
|
||||
|
||||
* device_id = 'abcd1234'
|
||||
*/
|
||||
|
||||
let local_file_cache_path = null;
|
||||
let host_file_temp_path = null;
|
||||
|
||||
console.log(os.type());
|
||||
console.log(process.getSystemVersion());
|
||||
|
||||
async function get_url_cfg() {
|
||||
let base_url = `${config.api_protocol}://${config.api_server}:${config.api_port}/${config.api_path}`;
|
||||
@@ -267,7 +322,7 @@ ipcMain.handle('import_config', async (event, config_data) => {
|
||||
// Download file to path
|
||||
// full_save_path should be the full path that includes the filename
|
||||
// Updated 2023-05-14
|
||||
ipcMain.handle('download_file', async (event, api_base_url, api_endpoint, full_save_path, hash=null, verify_hash=false, overwrite_existing=false) => {
|
||||
ipcMain.handle('download_file', async (event, api_base_url, api_endpoint, full_save_path, hash=null, verify_hash=false, overwrite_existing=false, offset_minutes=3) => {
|
||||
console.log('*** Electron IPC Main: download_file() ***');
|
||||
// console.log('ipcMain on download_file: api_base_url='+api_base_url+' | api_temporary_token='+api_temporary_token);
|
||||
// console.log('ipcMain on download_file: api_base_url='+api_base_url);
|
||||
@@ -302,7 +357,8 @@ ipcMain.handle('download_file', async (event, api_base_url, api_endpoint, full_s
|
||||
}
|
||||
|
||||
let current_datetime = new Date();
|
||||
let offset_minutes = 3; // In minutes. 5 minutes of no changes to the file content seems reasonable? Trying with 3 minutes 2022-10-12
|
||||
// In minutes. 5 minutes of no changes to the file content seems reasonable? Trying with 3 minutes 2022-10-12
|
||||
// offset_minutes = 3;
|
||||
let offset_datetime = new Date(current_datetime.getTime() - offset_minutes*60000);
|
||||
|
||||
// console.log(`Times: ${current_datetime} ${offset_datetime} | File ${stats.mtime}`);
|
||||
|
||||
12
package-lock.json
generated
12
package-lock.json
generated
@@ -595,9 +595,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/electron": {
|
||||
"version": "22.3.10",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-22.3.10.tgz",
|
||||
"integrity": "sha512-gh7PtSh+rfxHfM4dzPiEO+k1NRo07FvaK/jXG3HzuODrpTTEhC9rsE+AJGrTKQU6Nz7GorseMvnvs8PnUQPPTw==",
|
||||
"version": "22.3.11",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-22.3.11.tgz",
|
||||
"integrity": "sha512-4PW1rJRUckJUCxTXRJkzJ7qlGTZ8Qfwoke5aFlaGccmn/zViuE9iSCg9zqIx00rzsbF9R5j8j9V4tAqyqjjJRA==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
@@ -2527,9 +2527,9 @@
|
||||
}
|
||||
},
|
||||
"electron": {
|
||||
"version": "22.3.10",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-22.3.10.tgz",
|
||||
"integrity": "sha512-gh7PtSh+rfxHfM4dzPiEO+k1NRo07FvaK/jXG3HzuODrpTTEhC9rsE+AJGrTKQU6Nz7GorseMvnvs8PnUQPPTw==",
|
||||
"version": "22.3.11",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-22.3.11.tgz",
|
||||
"integrity": "sha512-4PW1rJRUckJUCxTXRJkzJ7qlGTZ8Qfwoke5aFlaGccmn/zViuE9iSCg9zqIx00rzsbF9R5j8j9V4tAqyqjjJRA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@electron/get": "^2.0.0",
|
||||
|
||||
Reference in New Issue
Block a user