Clean up of code. Prep for simplify later.

This commit is contained in:
2023-06-03 01:34:55 -04:00
parent 5e04deab9c
commit 9a7b2b4089

101
index.js
View File

@@ -13,8 +13,8 @@ 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());
console.log(`OS: ${os.type()} ${process.getSystemVersion()}`);
// console.log(process.getSystemVersion());
let home_directory = require('os').homedir();
console.log('Home: '+home_directory);
@@ -27,56 +27,57 @@ let config_directory = 'OSIT/native_app';
let config_filename = 'ae_native_app_config.json';
let config_path = '';
let local_file_cache_path = null;
let host_file_temp_path = null;
let endpoints_in_progress = [];
/* Look for and load a JSON formatted config file. */
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_macos = 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 if (fs.existsSync(config_path_macos)) {
console.log('macOS config file path exists: '+config_path_macos);
config_path = config_path_macos;
} else {
console.log(`No config file found: ${config_path_default} or ${config_path_backup}`);
console.log(`No config file found: ${config_path_default} or ${config_path_macos}`);
config_path = '';
// fs.mkdirSync(local_file_cache_path, true);
// console.log('Config directory path created: '+local_file_cache_path);
// fs.mkdirSync(config_file_directory_path, true);
// console.log('Config directory path created: '+config_file_directory_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_path}`);
console.log(`Using config found on macOS: ${config_path}`);
} else if (os.platform == 'linux') {
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_linux_os = 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_linux_os)) {
console.log('Linux config file path exists: '+config_path_linux_os);
config_path = config_path_linux_os;
} 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}`);
console.log(`No config file found: ${config_path_default} or ${config_path_linux_os} or ${config_path_temp}`);
config_path = '';
}
// config_directory = path.join(home_directory, 'OSIT/native_app');
console.log(`Linux config directory: ${config_path}`);
console.log(`Using config found on Linux: ${config_path}`);
}
// 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:
Minimal configuration contains:
* conf_file_check_path = '~/OSIT/sync/admin_share/internal/ae_osit_app.default.conf'
* conf_file_check_path_backup = 'ae_osit_app.conf'
@@ -93,8 +94,35 @@ Minimal Contains:
* device_id = 'abcd1234'
*/
let local_file_cache_path = null;
let host_file_temp_path = null;
/*
Ask for permissions from macOS to use the microphone, screen, camera. The OS may delay actually asking for permission until the permission is actually attempted to be used. It may be worth doing a test attempt early on if access has not already been granted. -STI 2023-06-03
*/
if (os.type == 'Darwin') {
if (systemPreferences.getMediaAccessStatus('microphone') != 'granted') {
systemPreferences.askForMediaAccess('microphone');
} else {
console.log('Microphone access:', systemPreferences.getMediaAccessStatus('microphone'));
}
if (systemPreferences.getMediaAccessStatus('screen') != 'granted') {
systemPreferences.askForMediaAccess('screen');
} else {
console.log('Screen access:', systemPreferences.getMediaAccessStatus('screen'));
}
if (systemPreferences.getMediaAccessStatus('camera') != 'granted') {
systemPreferences.askForMediaAccess('camera');
} else {
console.log('Camera access:', systemPreferences.getMediaAccessStatus('camera'));
}
}
async function get_url_cfg() {
@@ -166,28 +194,6 @@ let new_config = get_url_cfg();
console.log(new_config);
let endpoints_in_progress = [];
if (os.type == 'Darwin') {
if (systemPreferences.getMediaAccessStatus('microphone') != 'granted') {
systemPreferences.askForMediaAccess('microphone');
} else {
console.log('Microphone access:', systemPreferences.getMediaAccessStatus('microphone'));
}
if (systemPreferences.getMediaAccessStatus('screen') != 'granted') {
systemPreferences.askForMediaAccess('screen');
} else {
console.log('Screen access:', systemPreferences.getMediaAccessStatus('screen'));
}
if (systemPreferences.getMediaAccessStatus('camera') != 'granted') {
systemPreferences.askForMediaAccess('camera');
} else {
console.log('Camera access:', systemPreferences.getMediaAccessStatus('camera'));
}
}
function createWindow () {
@@ -357,8 +363,7 @@ ipcMain.handle('download_file', async (event, api_base_url, api_endpoint, full_s
}
let current_datetime = new Date();
// In minutes. 5 minutes of no changes to the file content seems reasonable? Trying with 3 minutes 2022-10-12
// offset_minutes = 3;
// In minutes. After 5ish minutes of no changes to the file content seems reasonable? Tested with 3 minutes for multiple meetings and no noticable problem.
let offset_datetime = new Date(current_datetime.getTime() - offset_minutes*60000);
// console.log(`Times: ${current_datetime} ${offset_datetime} | File ${stats.mtime}`);