From 01746ec98d7f7da678328efd91ed64ec1d60de4f Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Sat, 16 Apr 2022 16:25:53 -0400 Subject: [PATCH] Work on launcher and config --- app/js/aether_native_app_v3.js | 13 ++++++++++++- config.json | 25 +++++++++++-------------- index.js | 22 +++++++++++++++++++--- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/app/js/aether_native_app_v3.js b/app/js/aether_native_app_v3.js index 7d11db4..067fb00 100644 --- a/app/js/aether_native_app_v3.js +++ b/app/js/aether_native_app_v3.js @@ -4,6 +4,7 @@ const path = require('path'); const fs = require('fs'); const { ipcRenderer } = require('electron'); +let config = null; exports.load_config = function () { console.log('*** Electron framework: load_config() ***'); @@ -15,11 +16,12 @@ exports.load_config = function () { let tmp_directory = require('os').tmpdir(); console.log('Temporary: '+tmp_directory); - let config = null; + // let config = null; let config_directory = null; let default_config_path = path.join(process.cwd(),'config.json.default'); let config_path = null; + // Set the config path for macOS or Linux if (os.platform == 'darwin') { config_directory = path.join(home_directory, 'Library/Application Support/OSIT'); console.log('macOS config directory: '+config_directory); @@ -28,6 +30,7 @@ exports.load_config = function () { console.log('Linux config directory: '+config_directory); } + // Look for the config file and copy the default if not found. if (fs.existsSync(config_directory)) { console.log('Config: '+config_directory); config_path = path.join(config_directory, 'config.json'); @@ -41,6 +44,7 @@ exports.load_config = function () { 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)) { console.log('Config path: '+config_path); console.log('Config file (config.json) found under '+config_directory+'.'); @@ -66,6 +70,13 @@ exports.load_config = function () { } else { //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); return config; } diff --git a/config.json b/config.json index 27e4430..59c4404 100644 --- a/config.json +++ b/config.json @@ -7,29 +7,24 @@ "event_presentation_id": null, "event_presenter_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_token_update_loop_interval": 120000, + "open_tables_loop_interval": 10, "update_idb_loop_interval": 10, "idb_to_launcher_loop_interval": 250, "update_render_loop_interval": 1000, "check_file_cache_loop_interval": 250, - "api_secret_key": "dFP6J9DVj9hUgIMn-fNIqg", + "use_local_api": true, "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_event_check_period": 120000, "idb_event_location_check_period": 90000, @@ -37,9 +32,11 @@ "idb_event_presentation_check_period": 90000, "idb_event_presenter_check_period": 60000, "idb_event_file_check_period": 30000, + "host_file_cache_path": "file_cache", "host_file_cache_check_period": 30000, "host_file_temp_path": "temp", + "display_arrangement": "mirror_and_extend", "display_builtin_resolution": "", "display_builtin_refresh": "", diff --git a/index.js b/index.js index 41633e2..bac30d4 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,8 @@ const process = require('process'); //const url = require('url'); // const usb = require('usb') // Compiled with an old version of Node.js +let config = null; + console.log(os.type()); 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 // full_save_path should be the full path that includes the filename // 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() ***'); 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['x-aether-api-key'] = 'dFP6J9DVj9hUgIMn-fNIqg'; // api_secret_key; - axios.defaults.headers.common['x-account-id'] = '_XY7DXtc9MY'; // account_id; + axios.defaults.headers.common['x-aether-api-key'] = config.api_secret_key; // 'dFP6J9DVj9hUgIMn-fNIqg'; // api_secret_key; + axios.defaults.headers.common['x-account-id'] = config.account_id; // '_XY7DXtc9MY'; // account_id; const url = api_endpoint;