More robust loading
This commit is contained in:
114
index.js
114
index.js
@@ -30,7 +30,7 @@ if (os.platform == 'darwin') {
|
||||
}
|
||||
|
||||
// let config_path = path.join(config_directory, 'config.json');
|
||||
let config_path = path.join(config_directory, 'aether_native_app_config.json');
|
||||
let config_path = path.join(config_directory, 'ae_native_app_config.json');
|
||||
|
||||
let config = JSON.parse(fs.readFileSync(config_path));
|
||||
console.log('Config file read.', config);
|
||||
@@ -41,6 +41,75 @@ 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}`;
|
||||
|
||||
let axios_api = axios.create({
|
||||
baseURL: base_url,
|
||||
timeout: 60000, // in milliseconds; 60000 = 60 seconds
|
||||
/* other custom settings */
|
||||
});
|
||||
// axios_api.defaults.headers = config['headers'];
|
||||
|
||||
// axios.defaults.baseURL = `${config.api_protocol}://${config.api_server}:${config.api_port}/${config.api_path}`;
|
||||
axios_api.defaults.headers.common['Access-Control-Allow-Origin'] = config.access_control_allow_origin; // '*'; // app_config.access_control_allow_origin;
|
||||
axios_api.defaults.headers.common['content-type'] = 'application/json';
|
||||
axios_api.defaults.headers.common['x-aether-api-key'] = config.api_secret_key;
|
||||
axios_api.defaults.headers.common['x-account-id'] = config.account_id;
|
||||
|
||||
let event_device_id = 'dbgMWS3KEHE';
|
||||
let endpoint = `/event/device/${event_device_id}`;
|
||||
|
||||
let params = {'event_device_code': 'asdf'};
|
||||
|
||||
let response_data_promise = await axios_api.get(
|
||||
endpoint,
|
||||
{
|
||||
params: params,
|
||||
onDownloadProgress: (progressEvent) => {
|
||||
let percent_completed = Math.round(
|
||||
(progressEvent.loaded * 100) / progressEvent.total
|
||||
);
|
||||
console.log('GET Data Timestamp:', progressEvent.timeStamp, 'Total:', progressEvent.total, 'Loaded:', progressEvent.loaded, 'Percent Completed', percent_completed);
|
||||
|
||||
// temp_get_object_percent_completed = percent_completed;
|
||||
}
|
||||
}
|
||||
)
|
||||
.then(function (response) {
|
||||
console.log(`Response: ${response}`);
|
||||
|
||||
let return_data = response.data['data'];
|
||||
if (Array.isArray(return_data)) {
|
||||
console.log(`Data result is an array/list. Array length: ${return_data.length}`);
|
||||
} else {
|
||||
console.log(`Data result is a dictionary/object, not an array/list.`);
|
||||
}
|
||||
return return_data;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(`Base URL: ${base_url} | Endpoint: ${endpoint}`);
|
||||
|
||||
console.log('Error Message:', error.message); // Is this needed here or below in the in the else portion???
|
||||
if (error.response) {
|
||||
console.log(`Response Status: ${error.response.status}; Status Text: ${error.response.statusText}`);
|
||||
} else {
|
||||
console.log('Error:', error);
|
||||
}
|
||||
|
||||
if (error.response && error.response.status === 404) {
|
||||
return null; // Returning null since there were no results
|
||||
}
|
||||
return false; // Returning false since something may have gone wrong. Also more in line with what the API returns.
|
||||
});
|
||||
|
||||
return response_data_promise;
|
||||
}
|
||||
|
||||
let new_config = get_url_cfg();
|
||||
console.log(new_config);
|
||||
|
||||
|
||||
let endpoints_in_progress = [];
|
||||
|
||||
|
||||
@@ -88,19 +157,32 @@ function createWindow () {
|
||||
|
||||
// win.webContents.session.clearStorageData(['filesystem']); // Does this do anything???
|
||||
|
||||
// and load the index.html of the app.
|
||||
if (config.native_app_js_css_option == '' || config.native_app_js_css_option == 'default') {
|
||||
// native_app_which_html = 'default', 'path', 'url'
|
||||
// 'default' (internal) is within the bundled native app
|
||||
// 'path' (external to app) is a file path on the host, probably under the home directory
|
||||
// 'url' is over HTTPS, maybe onsite or offsite
|
||||
|
||||
// Load the index.html of the app
|
||||
if (config.native_app_which_html == '' || config.native_app_which_html == 'default') {
|
||||
win.loadFile('app/index.html');
|
||||
} else if (config.native_app_js_css_option == 'primary') {
|
||||
win.loadFile('app/index_primary.html');
|
||||
} else if (config.native_app_js_css_option == 'development_internal') {
|
||||
win.loadFile('app/index_development_internal.html');
|
||||
} else if (config.native_app_js_css_option == 'development_localhost') {
|
||||
win.loadFile('app/index_development_localhost.html');
|
||||
} else if (config.native_app_js_css_option == 'onsite') {
|
||||
win.loadFile('app/index_onsite.html');
|
||||
} else if (config.native_app_js_css_option == 'onsite_5000') {
|
||||
win.loadFile('app/index_onsite_5000.html');
|
||||
} else if (config.native_app_which_html == 'path') {
|
||||
let index_path = 'index.html';
|
||||
|
||||
if (config.native_app_index_path) {
|
||||
index_path = config.native_app_index_path.replace('[home]', home_directory);
|
||||
} else {
|
||||
index_path = path.join(home_directory, 'OSIT/native_app/app/index.html');
|
||||
}
|
||||
win.loadFile(index_path);
|
||||
} else if (config.native_app_which_html == 'url') {
|
||||
let index_url = 'http://localhost/index.html';
|
||||
|
||||
if (config.native_app_index_url) {
|
||||
index_url = native_app_index_url;
|
||||
} else {
|
||||
index_url = 'https://app.oneskyit.com/native/index.html';
|
||||
}
|
||||
win.loadURL(index_url);
|
||||
} else {
|
||||
win.loadFile('app/index.html');
|
||||
}
|
||||
@@ -182,7 +264,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 2022-10-12
|
||||
// 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) => {
|
||||
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);
|
||||
@@ -196,8 +278,8 @@ ipcMain.handle('download_file', async (event, api_base_url, api_endpoint, full_s
|
||||
axios.defaults.baseURL = api_base_url;
|
||||
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'] = config.api_secret_key; // 'dFP6J9DVj9hUgIMn-fNIqg'; // api_secret_key;
|
||||
axios.defaults.headers.common['x-account-id'] = config.account_id; // '_XY7DXtc9MY'; // account_id;
|
||||
axios.defaults.headers.common['x-aether-api-key'] = config.api_secret_key;
|
||||
axios.defaults.headers.common['x-account-id'] = config.account_id;
|
||||
|
||||
const url = api_endpoint;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user