Work on launcher and config

This commit is contained in:
Scott Idem
2022-04-16 16:25:53 -04:00
parent 4b28c16996
commit 01746ec98d
3 changed files with 42 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ const path = require('path');
const fs = require('fs'); const fs = require('fs');
const { ipcRenderer } = require('electron'); const { ipcRenderer } = require('electron');
let config = null;
exports.load_config = function () { exports.load_config = function () {
console.log('*** Electron framework: load_config() ***'); console.log('*** Electron framework: load_config() ***');
@@ -15,11 +16,12 @@ exports.load_config = function () {
let tmp_directory = require('os').tmpdir(); let tmp_directory = require('os').tmpdir();
console.log('Temporary: '+tmp_directory); console.log('Temporary: '+tmp_directory);
let config = null; // let config = null;
let config_directory = null; let config_directory = null;
let default_config_path = path.join(process.cwd(),'config.json.default'); let default_config_path = path.join(process.cwd(),'config.json.default');
let config_path = null; let config_path = null;
// Set the config path for macOS or Linux
if (os.platform == 'darwin') { if (os.platform == 'darwin') {
config_directory = path.join(home_directory, 'Library/Application Support/OSIT'); config_directory = path.join(home_directory, 'Library/Application Support/OSIT');
console.log('macOS config directory: '+config_directory); console.log('macOS config directory: '+config_directory);
@@ -28,6 +30,7 @@ exports.load_config = function () {
console.log('Linux config directory: '+config_directory); console.log('Linux config directory: '+config_directory);
} }
// Look for the config file and copy the default if not found.
if (fs.existsSync(config_directory)) { if (fs.existsSync(config_directory)) {
console.log('Config: '+config_directory); console.log('Config: '+config_directory);
config_path = path.join(config_directory, 'config.json'); config_path = path.join(config_directory, 'config.json');
@@ -41,6 +44,7 @@ exports.load_config = function () {
console.log('Default config file copied: '+config_directory); console.log('Default config file copied: '+config_directory);
} }
// Attempt to open the config file. The preferred location is based on the OS's config directory.
if (fs.existsSync(config_path)) { if (fs.existsSync(config_path)) {
console.log('Config path: '+config_path); console.log('Config path: '+config_path);
console.log('Config file (config.json) found under '+config_directory+'.'); console.log('Config file (config.json) found under '+config_directory+'.');
@@ -66,6 +70,13 @@ exports.load_config = function () {
} else { } else {
//close(); //close();
} }
let import_config_to_ipc_result = ipcRenderer.invoke('import_config', config).then((result) => {
console.log('IPC import config finished');
console.log(result);
return true;
})
//console.log(config); //console.log(config);
return config; return config;
} }

View File

@@ -7,29 +7,24 @@
"event_presentation_id": null, "event_presentation_id": null,
"event_presenter_id": null, "event_presenter_id": null,
"event_file_id": null, "event_file_id": null,
"api_secret_key": "dFP6J9DVj9hUgIMn-fNIqg",
"api_remote_base_url": "https://dev-fastapi.oneskyit.com",
"api_local_base_url": "http://dev-fastapi.oneskyit.local:5005",
"access_control_allow_origin": "*",
"api_auth_loop_interval": 100, "api_auth_loop_interval": 100,
"api_token_update_loop_interval": 120000, "api_token_update_loop_interval": 120000,
"open_tables_loop_interval": 10, "open_tables_loop_interval": 10,
"update_idb_loop_interval": 10, "update_idb_loop_interval": 10,
"idb_to_launcher_loop_interval": 250, "idb_to_launcher_loop_interval": 250,
"update_render_loop_interval": 1000, "update_render_loop_interval": 1000,
"check_file_cache_loop_interval": 250, "check_file_cache_loop_interval": 250,
"api_secret_key": "dFP6J9DVj9hUgIMn-fNIqg",
"use_local_api": true, "use_local_api": true,
"use_local_db": false, "use_local_db": false,
"api_remote_base_url": "https://dev-fastapi.oneskyit.com",
"api_local_base_url": "http://dev-fastapi.oneskyit.local:5005",
"access_control_allow_origin": "*",
"remote_db_server": "db.oneskyit.com",
"remote_db_port": "3306",
"remote_db_name": "onesky_ams_test",
"remote_db_username": "username_here",
"remote_db_password": "password_here",
"local_db_server": "db.oneskyit.local",
"local_db_port": "3306",
"local_db_name": "onesky_ams_test",
"local_db_username": "username_here",
"local_db_password": "password_here",
"idb_name": "osit", "idb_name": "osit",
"idb_event_check_period": 120000, "idb_event_check_period": 120000,
"idb_event_location_check_period": 90000, "idb_event_location_check_period": 90000,
@@ -37,9 +32,11 @@
"idb_event_presentation_check_period": 90000, "idb_event_presentation_check_period": 90000,
"idb_event_presenter_check_period": 60000, "idb_event_presenter_check_period": 60000,
"idb_event_file_check_period": 30000, "idb_event_file_check_period": 30000,
"host_file_cache_path": "file_cache", "host_file_cache_path": "file_cache",
"host_file_cache_check_period": 30000, "host_file_cache_check_period": 30000,
"host_file_temp_path": "temp", "host_file_temp_path": "temp",
"display_arrangement": "mirror_and_extend", "display_arrangement": "mirror_and_extend",
"display_builtin_resolution": "", "display_builtin_resolution": "",
"display_builtin_refresh": "", "display_builtin_refresh": "",

View File

@@ -11,6 +11,8 @@ const process = require('process');
//const url = require('url'); //const url = require('url');
// const usb = require('usb') // Compiled with an old version of Node.js // const usb = require('usb') // Compiled with an old version of Node.js
let config = null;
console.log(os.type()); console.log(os.type());
console.log(process.getSystemVersion()); console.log(process.getSystemVersion());
@@ -97,6 +99,20 @@ app.on('activate', () => {
}) })
// Import config data
// Updated 2022-04-16
ipcMain.handle('import_config', async (event, config_data) => {
console.log('*** Electron IPC Main: import_config() ***');
// console.log('ipcMain on download_file: api_base_url='+api_base_url+' | api_temporary_token='+api_temporary_token);
console.log('ipcMain on import_config:');
console.log(config_data);
config = config_data;
return true;
});
// Download file to path // Download file to path
// full_save_path should be the full path that includes the filename // full_save_path should be the full path that includes the filename
// Updated 2022-03-09 // Updated 2022-03-09
@@ -122,10 +138,10 @@ async function download_file(api_base_url, api_endpoint, full_save_path) {
console.log('*** node.js: download_file() ***'); console.log('*** node.js: download_file() ***');
axios.defaults.baseURL = api_base_url; axios.defaults.baseURL = api_base_url;
axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*'; // app_config.access_control_allow_origin; axios.defaults.headers.common['Access-Control-Allow-Origin'] = config.access_control_allow_origin; // '*'; // app_config.access_control_allow_origin;
axios.defaults.headers.common['content-type'] = 'application/json'; axios.defaults.headers.common['content-type'] = 'application/json';
axios.defaults.headers.common['x-aether-api-key'] = 'dFP6J9DVj9hUgIMn-fNIqg'; // api_secret_key; axios.defaults.headers.common['x-aether-api-key'] = config.api_secret_key; // 'dFP6J9DVj9hUgIMn-fNIqg'; // api_secret_key;
axios.defaults.headers.common['x-account-id'] = '_XY7DXtc9MY'; // account_id; axios.defaults.headers.common['x-account-id'] = config.account_id; // '_XY7DXtc9MY'; // account_id;
const url = api_endpoint; const url = api_endpoint;