A lot of clean up!!!
@@ -3,8 +3,8 @@ body {
|
||||
height: 100%;
|
||||
max-height: 100%; */
|
||||
|
||||
margin: .1em;
|
||||
padding: .1em;
|
||||
/* margin: .1em;
|
||||
padding: .1em; */
|
||||
}
|
||||
|
||||
section#Main-Body {
|
||||
@@ -16,13 +16,13 @@ section#Main-Body {
|
||||
}
|
||||
|
||||
section#Main-Nav-Menu {
|
||||
min-height: 100%;
|
||||
/* min-height: 100%;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
max-height: 100%; */
|
||||
}
|
||||
|
||||
section#Main-Content {
|
||||
min-height: 100%;
|
||||
/* min-height: 100%;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
max-height: 100%; */
|
||||
}
|
||||
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
108
app/index.html
@@ -24,32 +24,34 @@
|
||||
<link rel="stylesheet" href="http://demo.oneskyit.local:5000/static/svelte/build/aether_css_variables.css">
|
||||
<!-- <link rel="stylesheet" href="https://lci.oneskyit.com/static/svelte/build/aether_utilities.css"> -->
|
||||
<link rel="stylesheet" href="http://demo.oneskyit.local:5000/static/svelte/build/aether_utilities.css">
|
||||
<!-- <link rel="stylesheet" href="https://lci.oneskyit.com/static/svelte/build/aether_elements.css"> -->
|
||||
<link rel="stylesheet" href="http://demo.oneskyit.local:5000/static/svelte/build/aether_elements.css">
|
||||
<!-- <link rel="stylesheet" href="https://lci.oneskyit.com/static/css/aether_system.css"> -->
|
||||
<link rel="stylesheet" href="http://demo.oneskyit.local:5000/static/css/aether_system.css">
|
||||
<!-- <link rel="stylesheet" href="http://demo.oneskyit.local:5000/static/css/aether_system.css"> -->
|
||||
<!-- <link rel="stylesheet" href="https://lci.oneskyit.com/static/svelte/build/aether_modules_core.css"> -->
|
||||
<link rel="stylesheet" href="http://demo.oneskyit.local:5000/static/svelte/build/aether_modules_core.css">
|
||||
|
||||
<!-- <link rel="stylesheet" href="https://lci.oneskyit.com/static/svelte/build/aether_layout_v5_root.css"> -->
|
||||
<link rel="stylesheet" href="http://demo.oneskyit.local:5000/static/svelte/build/aether_layout_v5_root.css">
|
||||
<!-- <link rel="stylesheet" href="https://lci.oneskyit.com/static/svelte/build/aether_layout_v5_system.css"> -->
|
||||
<link rel="stylesheet" href="http://demo.oneskyit.local:5000/static/svelte/build/aether_layout_v5_system.css">
|
||||
|
||||
<!-- <link href="https://lci.oneskyit.com/static/svelte/build/bundle.css" rel="stylesheet"> -->
|
||||
<link href="http://demo.oneskyit.local:5000/static/svelte/build/bundle.css" rel="stylesheet">
|
||||
<!-- <link href="https://lci.oneskyit.com/static/svelte/build/reloading.css" rel="stylesheet"> -->
|
||||
<link href="http://demo.oneskyit.local:5000/static/svelte/build/reloading.css" rel="stylesheet">
|
||||
|
||||
<!-- <link href="https://lci.oneskyit.com/static/svelte/build/base_style_grid_layout_v3.css" rel="stylesheet"> -->
|
||||
<link href="http://demo.oneskyit.local:5000/static/svelte/build/base_style_grid_layout_v3.css" rel="stylesheet">
|
||||
<!-- <link href="https://lci.oneskyit.com/static/svelte/build/base_style_grid_theme_v3.css" rel="stylesheet"> -->
|
||||
<link href="http://demo.oneskyit.local:5000/static/svelte/build/base_style_grid_theme_v3.css" rel="stylesheet">
|
||||
|
||||
<!-- <link href="https://lci.oneskyit.com/static/svelte/build/event_launcher.css" rel="stylesheet"> -->
|
||||
<link href="http://demo.oneskyit.local:5000/static/svelte/build/event.css" rel="stylesheet">
|
||||
<link href="http://demo.oneskyit.local:5000/static/svelte/build/event_launcher.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="css/aether_native_app_v3.css">
|
||||
<link rel="stylesheet" href="css/aether_app_native_v3.css">
|
||||
|
||||
<style>
|
||||
</style>
|
||||
<!-- Cascading Style Sheets (CSS) end -->
|
||||
|
||||
<!-- JavaScript (JS) start -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.22.0/axios.min.js" integrity="sha512-m2ssMAtdCEYGWXQ8hXVG4Q39uKYtbfaJL5QMTbhl2kc6vYyubrKHhr6aLLXW4ITeXSywQLn1AhsAaqrJl8Acfg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.1.2/axios.min.js" integrity="sha512-bHeT+z+n8rh9CKrSrbyfbINxu7gsBmSHlDCb3gUF1BjmjDzKhoKspyB71k0CIRBSjE5IVQiMMVBgCWjF60qsvA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
|
||||
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
|
||||
|
||||
@@ -63,9 +65,9 @@
|
||||
<!-- <script src="js/app_idb.js"></script> -->
|
||||
|
||||
<script>
|
||||
const app = require('./js/aether_native_app_v3');
|
||||
let app_config = app.load_config();
|
||||
console.log('Native App Config:', app_config);
|
||||
const native_app = require('./js/aether_app_native_v4');
|
||||
let native_app_config = native_app.load_config();
|
||||
console.log('Native App Config:', native_app_config);
|
||||
|
||||
// BEGIN: Environment constants set by server when rendering HTML
|
||||
document.aether = {
|
||||
@@ -81,7 +83,7 @@
|
||||
// END: Environment constants set by server when rendering HTML
|
||||
|
||||
// BEGIN: Content constants set by server when rendering HTML
|
||||
const page_for = {"event": app_config.event_id, "event_device": app_config.event_device_id, "event_location": app_config.event_location_id, "event_session": app_config.event_session_id}; // Simple key value like object
|
||||
const page_for = {"event": native_app_config.event_id, "event_device": native_app_config.event_device_id, "event_location": native_app_config.event_location_id, "event_session": native_app_config.event_session_id}; // Simple key value like object
|
||||
console.log('Page For:', page_for);
|
||||
// END: Content constants set by server when rendering HTML
|
||||
|
||||
@@ -90,7 +92,7 @@
|
||||
const client_person_jwt = {}; // Future use
|
||||
const client_user_jwt = {}; // Future use
|
||||
|
||||
let client_account_id = app_config.account_id;
|
||||
let client_account_id = native_app_config.account_id;
|
||||
console.log(client_account_id);
|
||||
|
||||
// END: Client constants set by server when rendering HTML
|
||||
@@ -99,17 +101,17 @@
|
||||
// END: Other constants set by server when rendering HTML
|
||||
|
||||
let page = {}
|
||||
page['page_for'] = { 'event': app_config.event_id, 'event_device': app_config.event_device_id, 'event_location': app_config.event_location_id, "event_session": app_config.event_session_id }; // Simple key value like object;
|
||||
page['page_for'] = { 'event': native_app_config.event_id, 'event_device': native_app_config.event_device_id, 'event_location': native_app_config.event_location_id, "event_session": native_app_config.event_session_id }; // Simple key value like object;
|
||||
// page['current_url_root'] = 'http://demo.oneskyit.local:5000/';
|
||||
// page['current_url_full_path'] = '/event/pjrcghqwert/launcher/x7uFNCMEdOI?';
|
||||
document.aether.page = page;
|
||||
|
||||
document.aether.client = {"account_id": app_config.account_id, "site_id": app_config.site_id, "site_domain_id": app_config.site_domain_id, "person_id": null, "user_id": null, "order_cart_id_random": null, "super_check": false, "manager_check": false, "administrator_check": false, "support_check": false, "assistant_check": false, "trusted_check": false, "verified_check": false, "provisional_check": false, "public_check": false, "user_check": false, "logged_in_check": false, "person_check": false, "authenticated_check": false, "anonymous_check": true, "person_group": null, "user_group": null, "orders_closed_count": 0, "order_count": 0, "app_mode": "native"};
|
||||
document.aether.client = {"account_id": native_app_config.account_id, "site_id": native_app_config.site_id, "site_domain_id": native_app_config.site_domain_id, "person_id": null, "user_id": null, "order_cart_id_random": null, "super_check": false, "manager_check": false, "administrator_check": false, "support_check": false, "assistant_check": false, "trusted_check": false, "verified_check": false, "provisional_check": false, "public_check": false, "user_check": false, "logged_in_check": false, "person_check": false, "authenticated_check": false, "anonymous_check": true, "person_group": null, "user_group": null, "orders_closed_count": 0, "order_count": 0, "app_mode": "native"};
|
||||
|
||||
document.aether.cfg = {};
|
||||
document.aether.cfg.app = {"name": "One Sky IT's Aether Native App DEV", "version": "3.5 DEV", "email": null, "env": null, "mode": "native", "host_file_cache_path": app_config.host_file_cache_path, "host_file_temp_path": app_config.host_file_temp_path};
|
||||
document.aether.cfg.api = {"protocol": app_config.api_protocol, "server": app_config.api_server, "port": app_config.api_port, "path": app_config.api_path, "secret_key": app_config.api_secret_key, "base_url": null, "temporary_token": {"token": null, "expire_on": null}, "protocol_backup": app_config.api_protocol_backup, "server_backup": app_config.api_server_backup, "port_backup": app_config.api_port_backup, "path_backup": app_config.api_path_backup, "secret_key_backup": app_config.api_secret_key_backup, "base_url_backup": null, "temporary_token_backup": {"token": null, "expire_on": null}};
|
||||
document.aether.cfg.idb = {"name": app_config.idb_name};
|
||||
document.aether.cfg.app = {"name": "One Sky IT's Aether Native App DEV", "version": "3.5 DEV", "email": null, "env": null, "mode": "native", "local_file_cache_path": native_app_config.local_file_cache_path, "host_file_temp_path": native_app_config.host_file_temp_path};
|
||||
document.aether.cfg.api = {"protocol": native_app_config.api_protocol, "server": native_app_config.api_server, "port": native_app_config.api_port, "path": native_app_config.api_path, "secret_key": native_app_config.api_secret_key, "base_url": null, "temporary_token": {"token": null, "expire_on": null}, "protocol_backup": native_app_config.api_protocol_backup, "server_backup": native_app_config.api_server_backup, "port_backup": native_app_config.api_port_backup, "path_backup": native_app_config.api_path_backup, "secret_key_backup": native_app_config.api_secret_key_backup, "base_url_backup": null, "temporary_token_backup": {"token": null, "expire_on": null}};
|
||||
document.aether.cfg.idb = {"name": native_app_config.idb_name};
|
||||
|
||||
|
||||
|
||||
@@ -120,41 +122,41 @@
|
||||
// const app_mode = 'native'; // null, 'default', 'native', 'onsite'
|
||||
|
||||
|
||||
// let event_id = app_config.event_id;
|
||||
// let event_device_id = app_config.event_device_id;
|
||||
// let event_location_id = app_config.event_location_id;
|
||||
// let event_id = native_app_config.event_id;
|
||||
// let event_device_id = native_app_config.event_device_id;
|
||||
// let event_location_id = native_app_config.event_location_id;
|
||||
|
||||
// const host_file_cache_path = app_config.host_file_cache_path; // 'file_cache/'
|
||||
// console.log(host_file_cache_path);
|
||||
// const host_file_temp_path = app_config.host_file_temp_path; // 'temp/'
|
||||
// const local_file_cache_path = native_app_config.local_file_cache_path; // 'file_cache/'
|
||||
// console.log(local_file_cache_path);
|
||||
// const host_file_temp_path = native_app_config.host_file_temp_path; // 'temp/'
|
||||
// console.log(host_file_temp_path);
|
||||
|
||||
// let idb_name = app_config.idb_name;
|
||||
// let idb_name = native_app_config.idb_name;
|
||||
|
||||
// BEGIN: API section
|
||||
|
||||
// const access_control_allow_origin = app_config.access_control_allow_origin;
|
||||
// const api_secret_key = app_config.api_secret_key;
|
||||
// const access_control_allow_origin = native_app_config.access_control_allow_origin;
|
||||
// const api_secret_key = native_app_config.api_secret_key;
|
||||
// console.log(api_secret_key);
|
||||
// let api_temporary_token = null;
|
||||
|
||||
// let api_base_url = app_config.api_base_url; // null;
|
||||
// let api_base_url_bak = app_config.api_base_url_bak;
|
||||
// let app_server_base_url = app_config.app_server_base_url;
|
||||
// let file_base_url = app_config.file_server_base_url;
|
||||
// let api_base_url = native_app_config.api_base_url; // null;
|
||||
// let api_base_url_bak = native_app_config.api_base_url_bak;
|
||||
// let app_server_base_url = native_app_config.app_server_base_url;
|
||||
// let file_base_url = native_app_config.file_server_base_url;
|
||||
|
||||
// if (app_config.use_local_api) {
|
||||
// api_base_url = app_config.api_local_base_url; // 'http://api.localhost:5001'
|
||||
// if (native_app_config.use_local_api) {
|
||||
// api_base_url = native_app_config.api_local_base_url; // 'http://api.localhost:5001'
|
||||
// } else {
|
||||
// api_base_url = app_config.api_remote_base_url; // 'https://api.oneskyit.com'
|
||||
// api_base_url = native_app_config.api_remote_base_url; // 'https://api.oneskyit.com'
|
||||
// }
|
||||
|
||||
/* ***** **** *** ** * ### * ** *** **** ***** */
|
||||
|
||||
let app_online = false;
|
||||
//let app_use_cached_data = true;
|
||||
window.addEventListener('online', app.currently_online);
|
||||
window.addEventListener('offline', app.currently_offline);
|
||||
window.addEventListener('online', native_app.currently_online);
|
||||
window.addEventListener('offline', native_app.currently_offline);
|
||||
|
||||
/* ***** **** *** ** * ### * ** *** **** ***** */
|
||||
|
||||
@@ -167,24 +169,36 @@
|
||||
|
||||
</head>
|
||||
|
||||
<body class="body_container">
|
||||
|
||||
<body id="Body-Container" class="body_container">
|
||||
|
||||
<section id="System-Nav-Menu">Site-Nav-Menu</section>
|
||||
<section id="Site-Header">Site-Header</section>
|
||||
<section id="Site-Nav-Menu">Site-Nav-Menu</section>
|
||||
|
||||
<section id="System-Notifications">System-Notifications (and Site-Notifications)</section><!-- and what would be Site-Notifications-->
|
||||
<div id="Site-Container">
|
||||
|
||||
<section id="Main-Body" class="main_template_content svelte_target event_launcher_main">
|
||||
</section>
|
||||
<section id="Site-Header">Site-Header</section>
|
||||
|
||||
<nav id="Site-Nav-Menu">Site-Nav-Menu</nav>
|
||||
|
||||
<section id="Notifications">
|
||||
<section id="System-Notifications">System-Notifications (and Site-Notifications)</section><!-- and what would be Site-Notifications-->
|
||||
|
||||
</section>
|
||||
|
||||
<section id="Main-Body" class="main_template_content svelte_target event_launcher_main Side-Main-Nav-Menu">
|
||||
<section id="Main-Nav-Menu"></section>
|
||||
<main id="Main-Content"></main>
|
||||
</section>
|
||||
|
||||
<section id="Site-Footer">Site-Footer</section>
|
||||
|
||||
</div>
|
||||
|
||||
<section id="Site-Modals"></section>
|
||||
|
||||
<section id="Site-Footer">Site-Footer</section>
|
||||
<section id="System-Footer">Site-Footer</section>
|
||||
|
||||
<section id="System-Debug">System-Debug</section>
|
||||
|
||||
|
||||
</body>
|
||||
<!-- JavaScript (JS) start -->
|
||||
|
||||
@@ -201,7 +215,7 @@
|
||||
|
||||
|
||||
// BEGIN: Load IDB section
|
||||
// let idb_name = app_config.idb_name;
|
||||
// let idb_name = native_app_config.idb_name;
|
||||
|
||||
// let tbl_event = null;
|
||||
// let tbl_event_location = null;
|
||||
|
||||
@@ -118,13 +118,13 @@ exports.load_config = function () {
|
||||
config.app_root_path = config.app_root_path.replace('[tmp]', tmp_directory);
|
||||
console.log(config.app_root_path);
|
||||
|
||||
config.host_file_cache_path = config.host_file_cache_path.replace('[home]', home_directory);
|
||||
config.host_file_cache_path = config.host_file_cache_path.replace('[tmp]', tmp_directory);
|
||||
console.log(config.host_file_cache_path);
|
||||
// if (fs.existsSync(config.host_file_cache_path)) {
|
||||
config.local_file_cache_path = config.local_file_cache_path.replace('[home]', home_directory);
|
||||
config.local_file_cache_path = config.local_file_cache_path.replace('[tmp]', tmp_directory);
|
||||
console.log(config.local_file_cache_path);
|
||||
// if (fs.existsSync(config.local_file_cache_path)) {
|
||||
// } else {
|
||||
// fs.mkdirSync(config.host_file_cache_path);
|
||||
// console.log(`Host file cache directory created: ${config.host_file_cache_path}`);
|
||||
// fs.mkdirSync(config.local_file_cache_path);
|
||||
// console.log(`Host file cache directory created: ${config.local_file_cache_path}`);
|
||||
// }
|
||||
|
||||
config.host_file_temp_path = config.host_file_temp_path.replace('[home]', home_directory);
|
||||
@@ -170,15 +170,15 @@ exports.check_local_file = async function ({local_file_path, filename}) {
|
||||
// Used by Svelte Event Launcher
|
||||
// NOTE: Trying to replace this with something directly in the Svelte app part. 2022-10-11
|
||||
// Updated 2022-05-06
|
||||
exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
|
||||
exports.check_hash_file_cache = async function ({local_file_cache_path, hash}) {
|
||||
// console.log('*** Electron framework export: check_hash_file_cache() ***');
|
||||
// console.log('Check local hash file cache');
|
||||
console.log(`*** Electron framework export: check_hash_file_cache() *** Host File Cache Path: ${host_file_cache_path}; Hash: ${hash}`);
|
||||
console.log(`*** Electron framework export: check_hash_file_cache() *** Host File Cache Path: ${local_file_cache_path}; Hash: ${hash}`);
|
||||
|
||||
let hash_filename = `${hash}.file`;
|
||||
|
||||
let subdirectory = hash_filename.substring(0,2);
|
||||
let subdirectory_path = path.join(host_file_cache_path, subdirectory);
|
||||
let subdirectory_path = path.join(local_file_cache_path, subdirectory);
|
||||
if (fs.existsSync(subdirectory_path)) {
|
||||
} else {
|
||||
console.log(`Hashed file subdirectory not found in cache: ${subdirectory_path}`);
|
||||
@@ -201,17 +201,17 @@ exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
|
||||
// Download hash file to cache
|
||||
// Used by Svelte Event Launcher
|
||||
// Updated 2022-05-06
|
||||
exports.download_hash_file_to_cache = async function ({api_base_url, host_file_cache_path, event_file_id=null, hash=null}) {
|
||||
exports.download_hash_file_to_cache = async function ({api_base_url, local_file_cache_path, event_file_id=null, hash=null}) {
|
||||
// console.log('*** Electron framework export: download_hash_file_to_cache() ***');
|
||||
// console.log('Download hash file to cache');
|
||||
console.log(`*** Electron framework export: download_hash_file_to_cache() *** Base URL: ${api_base_url}; Host File Cache Path: ${host_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
console.log(`*** Electron framework export: download_hash_file_to_cache() *** Base URL: ${api_base_url}; Host File Cache Path: ${local_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
|
||||
let endpoint = `/event/file/${event_file_id}/download`;
|
||||
|
||||
let hash_filename = `${hash}.file`;
|
||||
|
||||
let subdirectory = hash_filename.substring(0,2);
|
||||
let subdirectory_path = path.join(host_file_cache_path, subdirectory);
|
||||
let subdirectory_path = path.join(local_file_cache_path, subdirectory);
|
||||
if (fs.existsSync(subdirectory_path)) {
|
||||
} else {
|
||||
fs.mkdirSync(subdirectory_path);
|
||||
@@ -241,9 +241,12 @@ exports.download_hash_file_to_cache = async function ({api_base_url, host_file_c
|
||||
if (result) {
|
||||
console.log('IPC download file process finished successfully');
|
||||
return true;
|
||||
} else {
|
||||
console.log('IPC Download Result:', result);
|
||||
} else if (result == null) {
|
||||
console.log('IPC Download Result (file not found?):', result);
|
||||
return null;
|
||||
} else {
|
||||
console.log('IPC Download Result (file being downloaded or something went wrong):', result);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
// console.log(`!!!DONE WITH DOWNLOAD FILE HANDLER!!! exports.download_hash_file_to_cache(); Base URL: ${api_base_url}`);
|
||||
@@ -256,13 +259,13 @@ exports.download_hash_file_to_cache = async function ({api_base_url, host_file_c
|
||||
// Used by Svelte Event Launcher
|
||||
// NOTE: Trying to replace this with something directly in the Svelte app part. 2022-10-11
|
||||
// Updated 2022-05-06
|
||||
exports.open_hash_file_to_temp = async function ({host_file_cache_path, hash, host_file_temp_path, filename}) {
|
||||
exports.open_hash_file_to_temp = async function ({local_file_cache_path, hash, host_file_temp_path, filename}) {
|
||||
console.log('*** Electron framework export: open_hash_file_to_temp() ***');
|
||||
// console.log('Open cached hash file after copying to temp directory');
|
||||
console.log(`Host File Cache Path: ${host_file_cache_path}; Hash: ${hash}; Host File Temp Path: ${host_file_temp_path}; Filename: ${filename}`);
|
||||
console.log(`Host File Cache Path: ${local_file_cache_path}; Hash: ${hash}; Host File Temp Path: ${host_file_temp_path}; Filename: ${filename}`);
|
||||
|
||||
let subdirectory = hash.substring(0,2);
|
||||
let subdirectory_path = path.join(host_file_cache_path, subdirectory);
|
||||
let subdirectory_path = path.join(local_file_cache_path, subdirectory);
|
||||
if (fs.existsSync(subdirectory_path)) {
|
||||
} else {
|
||||
console.log(`Hashed file subdirectory not found in cache: ${subdirectory_path}`);
|
||||
@@ -275,7 +278,7 @@ exports.open_hash_file_to_temp = async function ({host_file_cache_path, hash, ho
|
||||
return true;
|
||||
})
|
||||
|
||||
// let result = await ipcRenderer.send('open_local_file', host_file_cache_path, hash, host_file_temp_path, filename);
|
||||
// let result = await ipcRenderer.send('open_local_file', local_file_cache_path, hash, host_file_temp_path, filename);
|
||||
// console.log(result);
|
||||
|
||||
console.log(open_hash_file_to_temp_result);
|
||||
@@ -329,16 +332,16 @@ exports.open_local_file = async function ({local_file_path, filename}) {
|
||||
|
||||
// // Check local file cache and download from server if needed.
|
||||
// // Updated 2022-03-09
|
||||
// // exports.check_file_cache = async function ({host_file_cache_path, event_file_id, hash}) {
|
||||
// exports.check_file_cache = async function ({api_base_url, host_file_cache_path, event_file_id, hash}) {
|
||||
// // exports.check_file_cache = async function ({local_file_cache_path, event_file_id, hash}) {
|
||||
// exports.check_file_cache = async function ({api_base_url, local_file_cache_path, event_file_id, hash}) {
|
||||
// console.log('*** Electron framework export: check_file_cache() ***');
|
||||
// // console.log('Check local file cache and download from server if needed.');
|
||||
// console.log(`Host File Cache Path: ${host_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
// console.log(`Host File Cache Path: ${local_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
|
||||
// // NOTE: event_file_id is the event_file.id_random or event_file.event_file_id_random
|
||||
// let hash_filename = hash+'.file';
|
||||
|
||||
// let save_path = path.join(host_file_cache_path, hash_filename);
|
||||
// let save_path = path.join(local_file_cache_path, hash_filename);
|
||||
// console.log(save_path);
|
||||
|
||||
// if (fs.existsSync(save_path)) {
|
||||
@@ -385,15 +388,15 @@ exports.open_local_file = async function ({local_file_path, filename}) {
|
||||
|
||||
// Check local file cache and download from server if needed. Must use IPC to Main to download file. Set a Promise to wait for download_file_reply.
|
||||
// Updated 2022-03-09
|
||||
async function check_file_cache({api_base_url, host_file_cache_path, event_file_id, hash}) {
|
||||
async function check_file_cache({api_base_url, local_file_cache_path, event_file_id, hash}) {
|
||||
console.log('*** Electron framework: check_file_cache() ***');
|
||||
// console.log('Check local file cache and download from server if needed.');
|
||||
console.log(`Host File Cache Path: ${host_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
console.log(`Host File Cache Path: ${local_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
|
||||
// NOTE: event_file_id is the event_file.id_random or event_file.event_file_id_random
|
||||
let hash_filename = hash+'.file';
|
||||
|
||||
let save_path = path.join(host_file_cache_path, hash_filename);
|
||||
let save_path = path.join(local_file_cache_path, hash_filename);
|
||||
console.log(save_path);
|
||||
|
||||
if (fs.existsSync(save_path)) {
|
||||
@@ -440,16 +443,16 @@ async function check_file_cache({api_base_url, host_file_cache_path, event_file_
|
||||
|
||||
// IPC to Main: Open local file cache if available. Copy to temp directory with given filename first.
|
||||
// Updated 2022-03-09
|
||||
async function open_local_file({host_file_cache_path, hash, host_file_temp_path, filename}) {
|
||||
async function open_local_file({local_file_cache_path, hash, host_file_temp_path, filename}) {
|
||||
console.log('*** Electron framework: open_local_file() ***');
|
||||
// console.log('Open local file cache if available. Copy to temp directory with given filename first.');
|
||||
console.log(`Host File Cache Path: ${host_file_cache_path}; Hash: ${hash}; Host File Temp Path: ${host_file_temp_path}; Filename: ${filename}`);
|
||||
console.log(`Host File Cache Path: ${local_file_cache_path}; Hash: ${hash}; Host File Temp Path: ${host_file_temp_path}; Filename: ${filename}`);
|
||||
|
||||
console.log(host_file_cache_path);
|
||||
console.log(local_file_cache_path);
|
||||
console.log(hash);
|
||||
console.log(filename);
|
||||
|
||||
let result = await ipcRenderer.send('open_local_file', host_file_cache_path, hash, host_file_temp_path, filename);
|
||||
let result = await ipcRenderer.send('open_local_file', local_file_cache_path, hash, host_file_temp_path, filename);
|
||||
console.log(result);
|
||||
|
||||
return true;
|
||||
@@ -457,15 +460,15 @@ async function open_local_file({host_file_cache_path, hash, host_file_temp_path,
|
||||
|
||||
|
||||
// No longer needed? Not referenced as of 2022-10-11
|
||||
exports.check_file_cache_and_open_local_file = async function ({host_file_cache_path, event_file_id, hash, host_file_temp_path, filename}) {
|
||||
exports.check_file_cache_and_open_local_file = async function ({local_file_cache_path, event_file_id, hash, host_file_temp_path, filename}) {
|
||||
console.log('*** Electron framework: check_file_cache_and_open_local_file() ***');
|
||||
console.log('Checking the local file cache against the remote server and then opening the local file.');
|
||||
|
||||
let check_file_cache_result = check_file_cache({host_file_cache_path: host_file_cache_path, event_file_id: event_file_id, hash: hash});
|
||||
let check_file_cache_result = check_file_cache({local_file_cache_path: local_file_cache_path, event_file_id: event_file_id, hash: hash});
|
||||
console.log(check_file_cache_result);
|
||||
|
||||
if (check_file_cache_result) {
|
||||
let open_local_file_result = open_local_file({host_file_cache_path: host_file_cache_path, hash: hash, host_file_temp_path: host_file_temp_path, filename: filename});
|
||||
let open_local_file_result = open_local_file({local_file_cache_path: local_file_cache_path, hash: hash, host_file_temp_path: host_file_temp_path, filename: filename});
|
||||
console.log(open_local_file_result);
|
||||
|
||||
return open_local_file_result;
|
||||
@@ -474,7 +477,7 @@ exports.check_file_cache_and_open_local_file = async function ({host_file_cache_
|
||||
ipcRenderer.once('download_file_reply', function(event, response){
|
||||
console.log(response);
|
||||
|
||||
let open_local_file_result = open_local_file({host_file_cache_path: host_file_cache_path, hash: hash, host_file_temp_path: host_file_temp_path, filename: filename});
|
||||
let open_local_file_result = open_local_file({local_file_cache_path: local_file_cache_path, hash: hash, host_file_temp_path: host_file_temp_path, filename: filename});
|
||||
console.log(open_local_file_result);
|
||||
|
||||
return open_local_file_result;
|
||||
875
app/js/aether_app_native_v4.js
Normal file
@@ -0,0 +1,875 @@
|
||||
'use strict';
|
||||
/* This should only contain functions that can not be pulled easily into Svelte */
|
||||
/*
|
||||
Exported functions in use:
|
||||
* load_config()
|
||||
* check_hash_file_cache()
|
||||
* download_hash_file_to_cache()
|
||||
* open_hash_file_to_temp()
|
||||
* open_local_file()
|
||||
* kill_processes()
|
||||
* run_osascript()
|
||||
* run_cmd()
|
||||
* get_device_info
|
||||
|
||||
Local functions in use:
|
||||
* open_local_file()
|
||||
*/
|
||||
|
||||
const child_process = require('child_process');
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
const fs_promises = require('node:fs/promises');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
// import psList from 'ps-list';
|
||||
// const ps_list = require('ps-list');
|
||||
|
||||
let home_directory = require('os').homedir();
|
||||
console.log('Home: '+home_directory);
|
||||
|
||||
let tmp_directory = require('os').tmpdir();
|
||||
console.log('Temporary: '+tmp_directory);
|
||||
|
||||
let config = null;
|
||||
|
||||
exports.load_config = function () {
|
||||
console.log('*** Aether App Native export: load_config() ***');
|
||||
|
||||
let cwd = process.cwd();
|
||||
console.log(`CWD: ${cwd}`);
|
||||
|
||||
try {
|
||||
if (cwd == '/') {
|
||||
cwd = home_directory;
|
||||
}
|
||||
let directory_list = fs_promises.readdir(cwd).then(function (read_dir_result) {
|
||||
console.log('CWD Contents:', read_dir_result);
|
||||
// for (let file of read_dir_result) {
|
||||
// console.log(file);
|
||||
// }
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
// let home_directory = require('os').homedir();
|
||||
// console.log('Home: '+home_directory);
|
||||
|
||||
// let tmp_directory = require('os').tmpdir();
|
||||
// console.log('Temporary: '+tmp_directory);
|
||||
|
||||
// let config = null;
|
||||
let config_directory = null;
|
||||
// let default_config_path = path.join(process.cwd(),'config.json.default');
|
||||
let default_config_path = 'config.json.default';
|
||||
console.log(default_config_path);
|
||||
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);
|
||||
} else if (os.platform == 'linux') {
|
||||
config_directory = path.join(home_directory, '.config/OSIT');
|
||||
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 directory found: '+config_directory);
|
||||
} else {
|
||||
fs.mkdirSync(config_directory);
|
||||
console.log('Config directory created: '+config_directory);
|
||||
|
||||
//default_config_path = path.join(process.cwd(),'config.json.default');
|
||||
// config_path = path.join(config_directory, 'config.json');
|
||||
// fs.copyFileSync(default_config_path, config_path);
|
||||
// console.log('Default config file copied: '+config_directory);
|
||||
}
|
||||
|
||||
config_path = path.join(config_directory, 'config.json');
|
||||
|
||||
// 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 file (config.json) found under ${config_directory}`);
|
||||
} else if (!fs.existsSync(config_path) && fs.existsSync(default_config_path)) {
|
||||
fs.copyFileSync(default_config_path, config_path);
|
||||
console.log('Default config file copied: '+config_directory);
|
||||
|
||||
// config = JSON.parse(fs.readFileSync(config_path));
|
||||
// console.log('Config file read.');
|
||||
} else if (fs.existsSync(path.join(cwd, 'config.json'))) {
|
||||
//fs.copyFileSync(default_config_path, config_path);
|
||||
//console.log('Default config file copied: '+config_directory);
|
||||
|
||||
console.log(`Config file (config.json) not found under ${config_directory}. Using config in CWD. ${cwd}`);
|
||||
config_path = path.join(cwd, 'config.json');
|
||||
|
||||
console.log(`Config file (config.json) not found under ${config_directory}. Using config in CWD. ${cwd}`);
|
||||
let found_config_path = path.join(cwd, 'config.json');
|
||||
|
||||
fs.copyFileSync(found_config_path, config_path);
|
||||
console.log(`Found config file copied: ${config_directory}`);
|
||||
} else if (fs.existsSync(path.join(cwd, 'config.json.default'))) {
|
||||
console.log(`Config file (config.json) not found under ${config_directory} or CWD. Using default config in CWD. ${cwd}`);
|
||||
default_config_path = path.join(cwd, 'config.json.default');
|
||||
|
||||
fs.copyFileSync(default_config_path, config_path);
|
||||
console.log(`Default config file copied: ${config_directory}`);
|
||||
} else {
|
||||
console.log('Can not find a config file.');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
config = JSON.parse(fs.readFileSync(config_path));
|
||||
console.log('Config file read.');
|
||||
|
||||
config.home_directory = home_directory; // From the OS platform
|
||||
config.tmp_directory = tmp_directory; // From the OS platform
|
||||
|
||||
config.app_root_path = config.app_root_path.replace('[home]', home_directory);
|
||||
config.app_root_path = config.app_root_path.replace('[tmp]', tmp_directory);
|
||||
console.log(config.app_root_path);
|
||||
|
||||
config.local_file_cache_path = config.local_file_cache_path.replace('[home]', home_directory);
|
||||
config.local_file_cache_path = config.local_file_cache_path.replace('[tmp]', tmp_directory);
|
||||
console.log(config.local_file_cache_path);
|
||||
if (fs.existsSync(config.local_file_cache_path)) {
|
||||
} else {
|
||||
fs.mkdirSync(config.local_file_cache_path);
|
||||
console.log(`Host file cache directory created: ${config.local_file_cache_path}`);
|
||||
}
|
||||
|
||||
config.host_file_temp_path = config.host_file_temp_path.replace('[home]', home_directory);
|
||||
config.host_file_temp_path = config.host_file_temp_path.replace('[tmp]', tmp_directory);
|
||||
console.log(config.host_file_temp_path);
|
||||
if (fs.existsSync(config.host_file_temp_path)) {
|
||||
} else {
|
||||
fs.mkdirSync(config.host_file_temp_path);
|
||||
console.log(`Host file temp directory created: ${config.host_file_temp_path}`);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
// Check for local file
|
||||
// Updated 2022-05-06
|
||||
exports.check_local_file = async function ({local_file_path, filename}) {
|
||||
console.log('*** Electron framework export: check_local_file() ***');
|
||||
// console.log('Check for local file');
|
||||
console.log(`Local File Path: ${local_file_path}; Filename: ${filename}`);
|
||||
|
||||
let full_local_file_path = path.join(local_file_path, filename);
|
||||
console.log(full_local_file_path);
|
||||
|
||||
if (fs.existsSync(full_local_file_path)) {
|
||||
console.log(`Local file exists: ${full_local_file_path}`);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check local hash file cache
|
||||
// Used by Svelte Event Launcher
|
||||
// NOTE: Trying to replace this with something directly in the Svelte app part. 2022-10-11
|
||||
// Updated 2022-05-06
|
||||
exports.check_hash_file_cache = async function ({local_file_cache_path, hash}) {
|
||||
// console.log('*** Electron framework export: check_hash_file_cache() ***');
|
||||
// console.log('Check local hash file cache');
|
||||
console.log(`*** Electron framework export: check_hash_file_cache() *** Host File Cache Path: ${local_file_cache_path}; Hash: ${hash}`);
|
||||
|
||||
let hash_filename = `${hash}.file`;
|
||||
|
||||
let subdirectory = hash_filename.substring(0,2);
|
||||
let subdirectory_path = path.join(local_file_cache_path, subdirectory);
|
||||
if (fs.existsSync(subdirectory_path)) {
|
||||
} else {
|
||||
console.log(`Hashed file subdirectory not found in cache: ${subdirectory_path}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
let hash_file_cache_path = path.join(subdirectory_path, hash_filename);
|
||||
// console.log(hash_file_cache_path);
|
||||
|
||||
if (fs.existsSync(hash_file_cache_path)) {
|
||||
// console.log(`Hashed file exists in cache: ${hash_file_cache_path}`);
|
||||
return true;
|
||||
} else {
|
||||
console.log(`Hashed file not found in cache: ${hash_file_cache_path}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check local hash file cache
|
||||
// Used by Svelte Event Launcher
|
||||
// Updated 2022-10-12
|
||||
exports.check_hash_file_cache_v2 = async function ({local_file_cache_path, hash, verify_hash=false}) {
|
||||
console.log('*** Aether App Native export: check_hash_file_cache_v2() ***');
|
||||
console.log(`Local File Cache Path: ${local_file_cache_path}; Hash: ${hash}`);
|
||||
|
||||
if (fs.existsSync(local_file_cache_path)) {
|
||||
} else {
|
||||
// This should not happen. The directory needs to be created.
|
||||
console.log(`Cache directory for hashed files was not found: ${local_file_cache_path}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
let hash_filename = `${hash}.file`;
|
||||
|
||||
let hash_subdirectory = hash_filename.substring(0,2);
|
||||
let subdirectory_path = path.join(local_file_cache_path, hash_subdirectory);
|
||||
|
||||
if (fs.existsSync(subdirectory_path)) {
|
||||
} else {
|
||||
// This should not happen. The subdirectory needs to be created.
|
||||
console.log(`Hashed file subdirectory not found in cache directory: ${subdirectory_path}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
let full_cached_hash_path = path.join(subdirectory_path, hash_filename);
|
||||
|
||||
if (fs.existsSync(full_cached_hash_path)) {
|
||||
// console.log(`Hashed file exists in cache: ${full_cached_hash_path}`);
|
||||
|
||||
if (verify_hash) {
|
||||
const file_buffer = fs.readFileSync(full_cached_hash_path);
|
||||
const file_hash_sha256 = crypto.createHash('sha256');
|
||||
file_hash_sha256.update(file_buffer);
|
||||
|
||||
const file_hash_sha256_check = file_hash_sha256.digest('hex');
|
||||
if (file_hash_sha256_check == hash) {
|
||||
console.log('File hash match', file_hash_sha256_check);
|
||||
} else {
|
||||
// This should only happen if the file is actively being downloaded or it is corrupt.
|
||||
console.log('File hash does not match', file_hash_sha256_check);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
console.log(`Hashed file not found in cache: ${full_cached_hash_path}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Download hash file to cache
|
||||
// Used by Svelte Event Launcher
|
||||
// Updated 2022-05-06
|
||||
exports.download_hash_file_to_cache = async function ({api_base_url, local_file_cache_path, event_file_id=null, hash=null}) {
|
||||
// console.log('*** Electron framework export: download_hash_file_to_cache() ***');
|
||||
// console.log('Download hash file to cache');
|
||||
console.log(`*** Electron framework export: download_hash_file_to_cache() *** Base URL: ${api_base_url}; Host File Cache Path: ${local_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
|
||||
let endpoint = `/event/file/${event_file_id}/download`;
|
||||
|
||||
let hash_filename = `${hash}.file`;
|
||||
|
||||
let subdirectory = hash_filename.substring(0,2);
|
||||
let subdirectory_path = path.join(local_file_cache_path, subdirectory);
|
||||
if (fs.existsSync(subdirectory_path)) {
|
||||
} else {
|
||||
fs.mkdirSync(subdirectory_path);
|
||||
console.log(`Subdirectory directory created: ${subdirectory_path}`);
|
||||
}
|
||||
|
||||
let hash_file_cache_path = path.join(subdirectory_path, hash_filename);
|
||||
if (fs.existsSync(hash_file_cache_path)) {
|
||||
if (check_hash) {
|
||||
const file_buffer = fs.readFileSync(hash_file_cache_path);
|
||||
const file_hash_sha256 = crypto.createHash('sha256');
|
||||
file_hash_sha256.update(file_buffer);
|
||||
|
||||
const file_hash_sha256_check = file_hash_sha256.digest('hex');S
|
||||
if (file_hash_sha256_check == hash) {
|
||||
console.log('File hash match', file_hash_sha256_check);
|
||||
return true;
|
||||
} else {
|
||||
// This should only happen if the file is actively being downloaded or it is corrupt.
|
||||
console.log('File hash does not match', file_hash_sha256_check);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// console.log(`!!!ABOUT TO CALL DOWNLOAD FILE HANDLER!!! exports.download_hash_file_to_cache(); Base URL: ${api_base_url}`);
|
||||
let download_file_result = await ipcRenderer.invoke('download_file', api_base_url, endpoint, hash_file_cache_path).then((result) => {
|
||||
if (result) {
|
||||
console.log('IPC download file process finished successfully');
|
||||
return true;
|
||||
} else if (result == null) {
|
||||
console.log('IPC Download Result (file not found?):', result);
|
||||
return null;
|
||||
} else {
|
||||
console.log('IPC Download Result (file being downloaded or something went wrong):', result);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
// console.log(`!!!DONE WITH DOWNLOAD FILE HANDLER!!! exports.download_hash_file_to_cache(); Base URL: ${api_base_url}`);
|
||||
|
||||
return download_file_result;
|
||||
}
|
||||
|
||||
|
||||
// Download hash file to cache
|
||||
// Used by Svelte Event Launcher
|
||||
// Updated 2022-10-12
|
||||
exports.download_hash_file_to_cache_v2 = async function ({api_base_url, local_file_cache_path, event_file_id=null, hash=null, verify_hash=true, overwrite_existing=false}) {
|
||||
console.log('*** Aether App Native export: download_hash_file_to_cache_v2() ***');
|
||||
console.log(`Base URL: ${api_base_url}; Host File Cache Path: ${local_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
|
||||
if (fs.existsSync(local_file_cache_path)) {
|
||||
} else {
|
||||
// This should not happen. The directory needs to be created.
|
||||
console.log(`Cache directory for hashed files was not found: ${local_file_cache_path}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
let endpoint = `/event/file/${event_file_id}/download`;
|
||||
|
||||
let hash_filename = `${hash}.file`;
|
||||
|
||||
let hash_subdirectory = hash_filename.substring(0,2);
|
||||
let subdirectory_path = path.join(local_file_cache_path, hash_subdirectory);
|
||||
|
||||
if (fs.existsSync(subdirectory_path)) {
|
||||
} else {
|
||||
fs.mkdirSync(subdirectory_path);
|
||||
console.log(`Hashed file subdirectory directory created in cache directory: ${subdirectory_path}`);
|
||||
}
|
||||
|
||||
let full_cached_hash_path = path.join(subdirectory_path, hash_filename);
|
||||
|
||||
if (fs.existsSync(full_cached_hash_path)) {
|
||||
console.log(`Hashed file exists in cache: ${full_cached_hash_path}`);
|
||||
|
||||
if (verify_hash) {
|
||||
const file_buffer = fs.readFileSync(full_cached_hash_path);
|
||||
const file_hash_sha256 = crypto.createHash('sha256');
|
||||
file_hash_sha256.update(file_buffer);
|
||||
|
||||
const file_hash_sha256_check = file_hash_sha256.digest('hex');
|
||||
if (file_hash_sha256_check == hash) {
|
||||
// console.log('File hash match', file_hash_sha256_check);
|
||||
if (overwrite_existing) {
|
||||
console.log('Going to overwrite the existing file even though the hash matches.');
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// This should only happen if the file is actively being copied or it is corrupt.
|
||||
console.log('File hash does not match', file_hash_sha256_check);
|
||||
if (overwrite_existing) {
|
||||
console.log('Going to overwrite the existing file because the hash does not match.');
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let download_file_result = await ipcRenderer.invoke('download_file', api_base_url, endpoint, full_cached_hash_path, hash, verify_hash, overwrite_existing).then((result) => {
|
||||
if (result) {
|
||||
console.log('IPC download file process finished successfully');
|
||||
return true;
|
||||
} else if (result == null) {
|
||||
console.log('IPC Download Result (file not found?):', result);
|
||||
return null;
|
||||
} else {
|
||||
console.log('IPC Download Result (file being downloaded or something went wrong):', result);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return download_file_result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Open cached hash file after copying to temp directory
|
||||
// Used by Svelte Event Launcher
|
||||
// NOTE: Trying to replace this with something directly in the Svelte app part. 2022-10-11
|
||||
// Updated 2022-05-06
|
||||
exports.open_hash_file_to_temp = async function ({local_file_cache_path, hash, host_file_temp_path, filename}) {
|
||||
console.log('*** Electron framework export: open_hash_file_to_temp() ***');
|
||||
// console.log('Open cached hash file after copying to temp directory');
|
||||
console.log(`Host File Cache Path: ${local_file_cache_path}; Hash: ${hash}; Host File Temp Path: ${host_file_temp_path}; Filename: ${filename}`);
|
||||
|
||||
let subdirectory = hash.substring(0,2);
|
||||
let subdirectory_path = path.join(local_file_cache_path, subdirectory);
|
||||
if (fs.existsSync(subdirectory_path)) {
|
||||
} else {
|
||||
console.log(`Hashed file subdirectory not found in cache: ${subdirectory_path}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
let open_hash_file_to_temp_result = await ipcRenderer.invoke('open_hash_file_to_temp', subdirectory_path, hash, host_file_temp_path, filename).then((result) => {
|
||||
console.log('IPC open hash file to temp finished');
|
||||
console.log(result);
|
||||
return true;
|
||||
})
|
||||
|
||||
// let result = await ipcRenderer.send('open_local_file', local_file_cache_path, hash, host_file_temp_path, filename);
|
||||
// console.log(result);
|
||||
|
||||
console.log(open_hash_file_to_temp_result);
|
||||
console.log('End: open_hash_file_to_temp()');
|
||||
if (open_hash_file_to_temp_result) {
|
||||
console.log('File opened successfully');
|
||||
return true;
|
||||
} else {
|
||||
console.log('File was not opened successfully');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Open cached hash file after copying to temp directory
|
||||
// Used by Svelte Event Launcher
|
||||
// Updated 2022-10-12
|
||||
exports.open_hash_file_to_temp_v2 = async function ({local_file_cache_path, hash, host_file_temp_path, filename, verify_hash=true}) {
|
||||
console.log('*** Aether App Native export: open_hash_file_to_temp_v2() ***');
|
||||
console.log(`Local File Cache Path: ${local_file_cache_path}; Hash: ${hash}; Local File Temp Path: ${host_file_temp_path}; Filename: ${filename}`);
|
||||
|
||||
// console.log('Process: Check local hash file cache, Download hash file to cache, and Open cached hash file after copying to temp directory');
|
||||
|
||||
if (fs.existsSync(local_file_cache_path)) {
|
||||
} else {
|
||||
// This should not happen. The directory needs to be created.
|
||||
console.log(`Cache directory for hashed files was not found: ${local_file_cache_path}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
let hash_filename = `${hash}.file`;
|
||||
|
||||
let hash_subdirectory = hash_filename.substring(0,2);
|
||||
let subdirectory_path = path.join(local_file_cache_path, hash_subdirectory);
|
||||
|
||||
if (fs.existsSync(subdirectory_path)) {
|
||||
} else {
|
||||
// This should not happen. The subdirectory needs to be created.
|
||||
console.log(`Hashed file subdirectory not found in cache directory: ${subdirectory_path}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
let full_cached_hash_path = path.join(subdirectory_path, hash_filename);
|
||||
|
||||
if (fs.existsSync(full_cached_hash_path)) {
|
||||
console.log(`Hashed file exists in cache: ${full_cached_hash_path}`);
|
||||
|
||||
if (verify_hash) {
|
||||
const file_buffer = fs.readFileSync(full_cached_hash_path);
|
||||
const file_hash_sha256 = crypto.createHash('sha256');
|
||||
file_hash_sha256.update(file_buffer);
|
||||
|
||||
const file_hash_sha256_check = file_hash_sha256.digest('hex');
|
||||
if (file_hash_sha256_check == hash) {
|
||||
// console.log('File hash match', file_hash_sha256_check);
|
||||
} else {
|
||||
// This should only happen if the file is actively being downloaded or it is corrupt.
|
||||
console.log('File hash does not match', file_hash_sha256_check);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log(`Hashed file not found in cache: ${full_cached_hash_path}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
let local_file_cache_path_w_sub = subdirectory_path; // I need to go back and clean up the variable names related file directory and file paths.
|
||||
// NOTE: Setting check_hash to false since by default it was checked above.
|
||||
let open_hash_file_to_temp_result = await ipcRenderer.invoke('open_hash_file_to_temp', local_file_cache_path_w_sub, hash, host_file_temp_path, filename, verify_hash=false).then((result) => {
|
||||
console.log('IPC open hash file to temp finished');
|
||||
if (result) {
|
||||
console.log('Local hash file was opened from temp directory.');
|
||||
return result;
|
||||
} else {
|
||||
console.log('Local hash file was not opened from the temp directory. Something went wrong.');
|
||||
console.log(result);
|
||||
return false;
|
||||
}
|
||||
})
|
||||
|
||||
// let result = await ipcRenderer.send('open_local_file', local_file_cache_path, hash, host_file_temp_path, filename);
|
||||
// console.log(result);
|
||||
|
||||
// console.log(open_hash_file_to_temp_result);
|
||||
// console.log('End: open_hash_file_to_temp()');
|
||||
// if (open_hash_file_to_temp_result) {
|
||||
// console.log('File opened successfully');
|
||||
// return true;
|
||||
// } else {
|
||||
// console.log('File was not opened successfully');
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// let open_hash_file_to_temp_result = await ipcRenderer.invoke('open_hash_file_to_temp', subdirectory_path, hash, host_file_temp_path, filename).then((result) => {
|
||||
// console.log('IPC open hash file to temp finished');
|
||||
// if (result) {
|
||||
// console.log('Local hash file was opened from temp directory.');
|
||||
// return result;
|
||||
// } else {
|
||||
// console.log('Local hash file was not opened from the temp directory. Something went wrong.');
|
||||
// console.log(result);
|
||||
// return false;
|
||||
// }
|
||||
// })
|
||||
|
||||
return open_hash_file_to_temp_result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Open local file
|
||||
// Used by Svelte Event Launcher
|
||||
// NOTE: Trying to replace this with something directly in the Svelte app part. 2022-10-11
|
||||
// Updated 2022-03-10
|
||||
exports.open_local_file = async function ({local_file_path, filename}) {
|
||||
console.log('*** Electron framework export: open_local_file() ***');
|
||||
// console.log('Open local file');
|
||||
console.log(`Local File Path: ${local_file_path}; Filename: ${filename}`);
|
||||
|
||||
// let full_local_file_path = path.join(local_file_path, filename);
|
||||
// console.log(full_local_file_path);
|
||||
|
||||
// if (fs.existsSync(full_local_file_path)) {
|
||||
// console.log(`Local file exists: ${full_local_file_path}`);
|
||||
// // return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
let open_local_file_result = await ipcRenderer.invoke('open_local_file', local_file_path, filename).then((result) => {
|
||||
console.log('IPC open local file finished');
|
||||
console.log(result);
|
||||
return true;
|
||||
})
|
||||
|
||||
console.log(open_local_file_result);
|
||||
console.log('End: open_local_file()');
|
||||
if (open_local_file_result) {
|
||||
console.log('File opened successfully');
|
||||
return true;
|
||||
} else {
|
||||
console.log('File was not opened successfully');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// // Check local file cache and download from server if needed.
|
||||
// // Updated 2022-03-09
|
||||
// // exports.check_file_cache = async function ({local_file_cache_path, event_file_id, hash}) {
|
||||
// exports.check_file_cache = async function ({api_base_url, local_file_cache_path, event_file_id, hash}) {
|
||||
// console.log('*** Electron framework export: check_file_cache() ***');
|
||||
// // console.log('Check local file cache and download from server if needed.');
|
||||
// console.log(`Host File Cache Path: ${local_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
|
||||
// // NOTE: event_file_id is the event_file.id_random or event_file.event_file_id_random
|
||||
// let hash_filename = hash+'.file';
|
||||
|
||||
// let save_path = path.join(local_file_cache_path, hash_filename);
|
||||
// console.log(save_path);
|
||||
|
||||
// if (fs.existsSync(save_path)) {
|
||||
// console.log('Hashed file cache already exists: '+save_path);
|
||||
// return true;
|
||||
// } else {
|
||||
// console.log('Hashed file not found in local cache. Downloading file: '+save_path);
|
||||
// let endpoint = `/event/file/${event_file_id}/download`;
|
||||
// let result = await ipcRenderer.send('download_file', api_base_url, endpoint, save_path); // Must download file using main node.js thread.
|
||||
// console.log(result);
|
||||
|
||||
// return new Promise((resolve, reject) => {
|
||||
// ipcRenderer.once('download_file_reply', function(event, response){
|
||||
// console.log(response);
|
||||
// return response;
|
||||
// })
|
||||
// resolve(true);
|
||||
// });
|
||||
|
||||
// // await ipcRenderer.once('download_file_reply', function(event, response){
|
||||
// // console.log(response);
|
||||
// // return response;
|
||||
// // });
|
||||
|
||||
// // result.then(function (response) {
|
||||
// // console.log('Downloaded!!!???');
|
||||
// // return true;
|
||||
// // }).catch(function (error) {
|
||||
// // console.log(error);
|
||||
// // return false;
|
||||
// // });
|
||||
|
||||
// // return result;
|
||||
|
||||
// // console.log(result);
|
||||
// // if (result) {
|
||||
// // return true;
|
||||
// // } else {
|
||||
// // return false;
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// Check local file cache and download from server if needed. Must use IPC to Main to download file. Set a Promise to wait for download_file_reply.
|
||||
// Updated 2022-03-09
|
||||
async function check_file_cache({api_base_url, local_file_cache_path, event_file_id, hash}) {
|
||||
console.log('*** Electron framework: check_file_cache() ***');
|
||||
// console.log('Check local file cache and download from server if needed.');
|
||||
console.log(`Host File Cache Path: ${local_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
|
||||
// NOTE: event_file_id is the event_file.id_random or event_file.event_file_id_random
|
||||
let hash_filename = hash+'.file';
|
||||
|
||||
let save_path = path.join(local_file_cache_path, hash_filename);
|
||||
console.log(save_path);
|
||||
|
||||
if (fs.existsSync(save_path)) {
|
||||
console.log('Hashed file cache already exists: '+save_path);
|
||||
return true;
|
||||
} else {
|
||||
console.log('Hashed file not found in local cache. Downloading file: '+save_path);
|
||||
let endpoint = `/event/file/${event_file_id}/download`;
|
||||
let result = await ipcRenderer.send('download_file', api_base_url, endpoint, save_path); // Must download file using main node.js thread.
|
||||
console.log(result);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once('download_file_reply', function(event, response){
|
||||
console.log(response);
|
||||
return response;
|
||||
})
|
||||
resolve(true);
|
||||
});
|
||||
|
||||
// await ipcRenderer.once('download_file_reply', function(event, response){
|
||||
// console.log(response);
|
||||
// return response;
|
||||
// });
|
||||
|
||||
// result.then(function (response) {
|
||||
// console.log('Downloaded!!!???');
|
||||
// return true;
|
||||
// }).catch(function (error) {
|
||||
// console.log(error);
|
||||
// return false;
|
||||
// });
|
||||
|
||||
// return result;
|
||||
|
||||
// console.log(result);
|
||||
// if (result) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// IPC to Main: Open local file cache if available. Copy to temp directory with given filename first.
|
||||
// Updated 2022-03-09
|
||||
async function open_local_file({local_file_cache_path, hash, host_file_temp_path, filename}) {
|
||||
console.log('*** Electron framework: open_local_file() ***');
|
||||
// console.log('Open local file cache if available. Copy to temp directory with given filename first.');
|
||||
console.log(`Host File Cache Path: ${local_file_cache_path}; Hash: ${hash}; Host File Temp Path: ${host_file_temp_path}; Filename: ${filename}`);
|
||||
|
||||
console.log(local_file_cache_path);
|
||||
console.log(hash);
|
||||
console.log(filename);
|
||||
|
||||
let result = await ipcRenderer.send('open_local_file', local_file_cache_path, hash, host_file_temp_path, filename);
|
||||
console.log(result);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// No longer needed? Not referenced as of 2022-10-11
|
||||
exports.check_file_cache_and_open_local_file = async function ({local_file_cache_path, event_file_id, hash, host_file_temp_path, filename}) {
|
||||
console.log('*** Electron framework: check_file_cache_and_open_local_file() ***');
|
||||
console.log('Checking the local file cache against the remote server and then opening the local file.');
|
||||
|
||||
let check_file_cache_result = check_file_cache({local_file_cache_path: local_file_cache_path, event_file_id: event_file_id, hash: hash});
|
||||
console.log(check_file_cache_result);
|
||||
|
||||
if (check_file_cache_result) {
|
||||
let open_local_file_result = open_local_file({local_file_cache_path: local_file_cache_path, hash: hash, host_file_temp_path: host_file_temp_path, filename: filename});
|
||||
console.log(open_local_file_result);
|
||||
|
||||
return open_local_file_result;
|
||||
}
|
||||
|
||||
ipcRenderer.once('download_file_reply', function(event, response){
|
||||
console.log(response);
|
||||
|
||||
let open_local_file_result = open_local_file({local_file_cache_path: local_file_cache_path, hash: hash, host_file_temp_path: host_file_temp_path, filename: filename});
|
||||
console.log(open_local_file_result);
|
||||
|
||||
return open_local_file_result;
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// Kill processes
|
||||
// Updated 2022-05-07
|
||||
exports.kill_processes = async function ({process_name = null}) {
|
||||
console.log('*** Electron framework export: kill_processes() ***');
|
||||
console.log(process_name); // process_name or grep pattern
|
||||
|
||||
let cmd = '';
|
||||
if (os.platform == 'darwin') {
|
||||
// cmd = `osascript -e 'quit app "${process_name}" saving no'`;
|
||||
cmd = `osascript -e 'quit application "${process_name}" saving no'`;
|
||||
} else {
|
||||
cmd = `pkill ${process_name}`;
|
||||
}
|
||||
|
||||
child_process.exec(cmd, (err, stdout, stdin) => {
|
||||
// if (err) throw err;
|
||||
if (err) console.log(err);
|
||||
console.log(stdout);
|
||||
});
|
||||
console.log(`Killed processes matching ${process_name}`);
|
||||
|
||||
if (os.platform == 'darwin') {
|
||||
if (process_name == 'Parallels:Acrobat Reader') {
|
||||
// Regular expression: (Parallels).*(Acrobat Reader)
|
||||
// This will find any process with Parallels and Acrobat Reader in the name
|
||||
cmd = `pkill -i -f '(Parallels).*(Acrobat Reader)'`;
|
||||
|
||||
child_process.exec(cmd, (err, stdout, stdin) => {
|
||||
if (err) throw err;
|
||||
console.log(stdout);
|
||||
});
|
||||
console.log('Killed Parallels Acrobat Reader process');
|
||||
}
|
||||
|
||||
if (process_name == 'Parallels:PowerPoint') {
|
||||
// Regular expression: (Parallels).*(PowerPoint)
|
||||
// This will find any process with Parallels and PowerPoint in the name
|
||||
cmd = `pkill -i -f '(Parallels).*(PowerPoint)'`;
|
||||
|
||||
child_process.exec(cmd, (err, stdout, stdin) => {
|
||||
if (err) throw err;
|
||||
console.log(stdout);
|
||||
});
|
||||
console.log('Killed Parallels PowerPoint process');
|
||||
}
|
||||
}
|
||||
|
||||
// let signal = 'SIGTERM'; // 'SIGTERM', 'SIGINT', 'SIGHUP'
|
||||
// process.kill(pid, signal);
|
||||
// process.kill(pid, 0); // Special case test if process exists
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Run raw osascript
|
||||
// Updated 2022-05-07
|
||||
exports.run_osascript = async function ({cmd=null, interactive=false, language=null, flags='h', program_file=null}) {
|
||||
console.log('*** Electron framework export: run_osascript() ***');
|
||||
console.log(cmd);
|
||||
|
||||
if (os.platform == 'darwin') {
|
||||
} else {
|
||||
console.log('Not available for this platform. macOS (darwin) only.');
|
||||
return false;
|
||||
}
|
||||
|
||||
let osascript_str = '';
|
||||
|
||||
if (Array.isArray(cmd)) {
|
||||
console.log('List of cmd strings');
|
||||
let cmds_str = '';
|
||||
for (let i = 0; i < cmd.length; i++) {
|
||||
cmds_str += `-e '${cmd[i]}'`;
|
||||
}
|
||||
osascript_str = `osascript ${cmds_str}`
|
||||
|
||||
} else if (typeof cmd === 'string') {
|
||||
console.log('Single cmd string');
|
||||
osascript_str = `osascript -e '${cmd}'`;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (language) {
|
||||
console.log(`Language: ${language}`);
|
||||
osascript_str = `${osascript_str} -l ${language}`;
|
||||
}
|
||||
|
||||
if (flags) {
|
||||
console.log(`Flags: ${flags}`);
|
||||
osascript_str = `${osascript_str} -s ${flags}`;
|
||||
}
|
||||
|
||||
console.log(`OSA Script String: ${osascript_str}`);
|
||||
child_process.exec(osascript_str, (err, stdout, stdin) => {
|
||||
if (err) throw err;
|
||||
console.log(stdout);
|
||||
console.log(stdin);
|
||||
});
|
||||
|
||||
console.log('Finished');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Run raw command
|
||||
// Updated 2022-05-07
|
||||
exports.run_cmd = async function ({cmd=null}) {
|
||||
console.log('*** Electron framework export: run_cmd() ***');
|
||||
|
||||
console.log(`Command String: ${cmd}`);
|
||||
|
||||
child_process.exec(cmd, (err, stdout, stdin) => {
|
||||
if (err) throw err;
|
||||
console.log(stdout);
|
||||
console.log(stdin);
|
||||
});
|
||||
|
||||
console.log('Finished');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Run raw command
|
||||
// Updated 2022-05-25
|
||||
exports.get_device_info = async function () {
|
||||
console.log('*** Electron framework export: get_device_info() ***');
|
||||
|
||||
let data = {};
|
||||
data['arch'] = os.arch();
|
||||
data['hostname'] = os.hostname();
|
||||
data['cpus'] = os.cpus();
|
||||
data['freemem'] = os.freemem();
|
||||
data['totalmem'] = os.totalmem();
|
||||
data['loadavg'] = os.loadavg();
|
||||
data['networkInterfaces'] = os.networkInterfaces();
|
||||
data['platform'] = os.platform();
|
||||
data['release'] = os.release();
|
||||
data['uptime'] = os.uptime();
|
||||
data['version'] = os.version();
|
||||
|
||||
console.log(data);
|
||||
return data;
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.6 KiB |