diff --git a/app/css/launcher.css b/app/css/native_app.css similarity index 54% rename from app/css/launcher.css rename to app/css/native_app.css index ce05f76..02834b1 100644 --- a/app/css/launcher.css +++ b/app/css/native_app.css @@ -1,17 +1,15 @@ body { - margin: .1rem; - padding: .1rem; + margin: 0rem; + padding: 0rem; /*border: solid thin pink;*/ -} - -.btn_no_case { - text-transform: none; + margin-bottom: 1rem; /* This is for the bottom status bar. */ } body > .container { /* allow the container directly under body to be 100% wide*/ /*max-width: 100%;*/ - margin: 0rem; - padding: 0rem; + + margin: .1rem; + padding: .1rem; /*border: solid thin pink;*/ } @@ -22,6 +20,36 @@ body > .container > .row { /* allow the container directly under body to be 100% padding: .1rem; } +.app_status_bar { + position: fixed; + bottom: 0; + width: 100%; + margin: 0 0; + padding: 0 .5rem; + background: #eee; +} + +.app_status_bar:hover { + font-size: 2.5rem; +} + +.app_network_status { + + background: #eee; +} + +.app_datetime { + float: right; +} + +.app_warning { + background: yellow; +} + +.btn_no_case { + text-transform: none; +} + /* .btn-info { background: green; @@ -42,3 +70,30 @@ mynewcolor:#77cccc; @include button-outline-variant($mynewcolor, #222222, lighten($mynewcolor,5%), $mynewcolor); } */ + + +.filename { + /* + margin-left: .1rem; + padding-left: .1rem; + */ +} + +.menu_session_code, .detail_session_code { + margin-left: .1rem; + padding-left: .1rem; + font-size: .5em; +} + +.session_detail>h2 { + background-color: #F7F7F7; + /*border-bottom: solid .1rem black;*/ +} + +.detail_session_code { + margin-left: .1rem; + padding-left: .1rem; + font-size: .5em; +} + + diff --git a/app/css/style.css b/app/css/style.css index 7f02d62..166c0dc 100644 --- a/app/css/style.css +++ b/app/css/style.css @@ -1,3 +1,5 @@ + + .bd-placeholder-img { font-size: 1.125rem; text-anchor: middle; @@ -45,26 +47,4 @@ justify-content: center; } -.filename { - /* - margin-left: .1rem; - padding-left: .1rem; - */ -} -.menu_session_code, .detail_session_code { - margin-left: .1rem; - padding-left: .1rem; - font-size: .5em; -} - -.session_detail>h2 { - background-color: #F7F7F7; - /*border-bottom: solid .1rem black;*/ -} - -.detail_session_code { - margin-left: .1rem; - padding-left: .1rem; - font-size: .5em; -} diff --git a/app/index.html b/app/index.html index 325afff..482e03e 100644 --- a/app/index.html +++ b/app/index.html @@ -17,7 +17,7 @@ - + @@ -58,22 +58,25 @@
-
+
Reset Launcher
-
- Network Status -
+
- - +
+ + Network Status + + datetime +
+ @@ -108,7 +111,7 @@ - + @@ -124,8 +127,9 @@ let event_id = app_config.event_id; let event_location_id = app_config.event_location_id; + /* ***** **** *** ** * ### * ** *** **** ***** */ - // Start set display options + // Start of set display options const display_session_codes = app_config.display_session_codes; @@ -138,9 +142,11 @@ // End of set display options + /* ***** **** *** ** * ### * ** *** **** ***** */ // Start of API section + const api_token_loop_interval = app_config.api_token_loop_interval; let api_update_period = app_config.idb_event_location_check_period; let api_update_datetime = Date.now(); @@ -189,27 +195,31 @@ update_event_file_ui = true; } - var api_token_loop = setInterval(function() { + var api_token_loop = setInterval(async function() { if (app_online && api_update_datetime < Date.now()) { - let api_temporary_token = api_token_request_async(axios, secret_key) + //let api_temporary_token_result = api_token_request_async(axios, secret_key) + api_temporary_token = await api_token_request_async(axios, secret_key) .then(function (result) { if (result) { console.log('Setting temporary API token to axios Authorization header: '+result); axios.defaults.headers.common['Authorization'] = `Token ${result}`; - api_temporary_token = result; + //api_temporary_token = result; console.log('Axios headers have been set.'); axios_headers_set = true; api_update_datetime = Date.now() + api_update_period; + return result; } else { console.log('The temporary API token appears to have failed. Are we actually online? Setting the app to offline mode.'); console.log(navigator.onLine); app.currently_offline(); + return false; } }) .catch(function (error) { console.log('Something went wrong while trying to request a temporary API token.'); console.log(error); + return false; }); } else if (app_online) { //console.log('Currently online, but not asking for a new temporary token yet.'); @@ -218,11 +228,14 @@ } }, api_token_loop_interval); + // End of API section + /* ***** **** *** ** * ### * ** *** **** ***** */ // Start of IDB section + let idb_name = app_config.idb_name; if (window.indexedDB) { @@ -391,26 +404,6 @@ console.log('Something went wrong rendering session records.'); console.log(error); }); - /* - let render_event_presentation_records_result = await render_event_presentation_records(); - let render_event_presenter_records_result = await render_event_presenter_records(); - let render_event_file_records_result = await render_event_file_records(); - */ - /* - setTimeout(async function(){ - //let render_event_session_records_result = await render_event_session_records(); - let render_event_presentation_records_result = await render_event_presentation_records(); - let render_event_presenter_records_result = await render_event_presenter_records(); - let render_event_file_records_result = await render_event_file_records(); - //index_launcher_sessions('btn_view_session'); - }, 1000); - */ - //let render_event_presentation_records_result = await render_event_presentation_records(); - //setTimeout(function(){ let render_event_presentation_records_result = render_event_presentation_records(); }, 3000); - //let render_event_presenter_records_result = render_event_presenter_records(); - //setTimeout(function(){ let render_event_presenter_records_result = render_event_presenter_records(); }, 4000); - //let render_event_file_records_result = render_event_file_records(); - //setTimeout(function(){ let render_event_file_records_result = render_event_file_records(); }, 5000); } else { console.log('One or more of the IDB tables has 0 records.'); } @@ -421,45 +414,13 @@ } }, open_tables_loop_interval); - /* - var use_cached_data_render_loop = setInterval(async function() { - console.log('*** Update Render Loop ***'); - if (idb_tables_opened) { - if (update_event_ui) { - let render_event_records_result = render_event_records(); - update_event_ui = false; - } - if (update_event_location_ui) { - let render_event_location_records_result = render_event_location_records(); - update_event_location_ui = false; - } - if (update_event_session_ui) { - let render_event_session_records_result = render_event_session_records(); - update_event_session_ui = false; - } - if (update_event_presentation_ui) { - let render_event_presentation_records_result = await render_event_presentation_records(); - update_event_presentation_ui = false; - } - if (update_event_presenter_ui) { - let render_event_presenter_records_result = await render_event_presenter_records(); - update_event_presenter_ui = false; - } - if (update_event_file_ui) { - let render_event_file_records_result = await render_event_file_records(); - update_event_file_ui = false; - } - } - }, use_cached_data_render_loop_interval); - */ - var update_idb_loop = setInterval(async function() { //console.log('FLAG: axios_headers_set='+axios_headers_set); //console.log('FLAG: idb_tables_opened='+idb_tables_opened); if (app_online && axios_headers_set && idb_tables_opened) { if (idb_event_check_datetime < Date.now()) { - console.log('**** *** ** * Time to check events'); + console.log('**** *** ** * Time to check events * ** *** ****'); let v2_account_events = await v2_get_account_events(axios, account_id) .then(function (response) { for (var i in response) { @@ -477,7 +438,7 @@ } if (idb_event_location_check_datetime < Date.now()) { - console.log('**** *** ** * Time to check event locations'); + console.log('**** *** ** * Time to check event locations * ** *** ****'); let v2_event_locations = await v2_get_event_locations(axios, event_id); for (var i in v2_event_locations) { tbl_event_location.setItem(v2_event_locations[i].id.toString(), v2_event_locations[i]); @@ -488,7 +449,7 @@ } if (idb_event_session_check_datetime < Date.now()) { - console.log('**** *** ** * Time to check event sessions'); // All event sessions, not just location specific. + console.log('**** *** ** * Time to check event sessions * ** *** ****'); // All event sessions, not just location specific. let v2_event_sessions = await v2_get_event_sessions(axios, event_id); // Was v2_get_event_location_sessions //tbl_event_session.clear(); for (var i in v2_event_sessions) { @@ -500,7 +461,7 @@ } if (idb_event_presentation_check_datetime < Date.now()) { - console.log('**** *** ** * Time to check event location presentations'); + console.log('**** *** ** * Time to check event location presentations * ** *** ****'); let v2_event_presentations = await v2_get_event_location_presentations(axios, event_location_id); for (var i in v2_event_presentations) { tbl_event_presentation.setItem(v2_event_presentations[i].id.toString(), v2_event_presentations[i]); @@ -511,7 +472,7 @@ } if (idb_event_presenter_check_datetime < Date.now()) { - console.log('**** *** ** * Time to check event location presenters'); + console.log('**** *** ** * Time to check event location presenters * ** *** ****'); let v2_event_presenters = await v2_get_event_location_presenters(axios, event_location_id); for (var i in v2_event_presenters) { tbl_event_presenter.setItem(v2_event_presenters[i].id.toString(), v2_event_presenters[i]); @@ -523,7 +484,7 @@ } if (idb_event_file_check_datetime < Date.now()) { - console.log('**** *** ** * Time to check event location files'); + console.log('**** *** ** * Time to check event location files * ** *** ****'); let v2_event_files = await v2_get_event_files(axios, event_id); for (var i in v2_event_files) { @@ -550,10 +511,22 @@ tbl_event_file.setItem(v2_event_location_files_presenters[i].id.toString(), v2_event_location_files_presenters[i]); } - run_check_file_cache = true; // Set to true so that the local file cache will be checked against the updated event files + //run_check_file_cache = true; // Set to true so that the local file cache will be checked against the updated event files idb_event_file_check_datetime = Date.now() + idb_event_file_check_period; let render_event_file_records_result = await render_event_file_records(); // NOTE: v2 idb to ui + + let check_file_cache_result = app.check_file_cache() + .then(function (result) { + if (result) { + console.log('Cached files have now been updated.'); + } else { + console.log('Cached files were not updated.'); + } + + }); + + //update_event_file_ui = true; } @@ -571,6 +544,7 @@ // End of IDB section + /* ***** **** *** ** * ### * ** *** **** ***** */ // Start of cached file section @@ -582,7 +556,7 @@ var check_file_cache_loop = setInterval(async function() { if (run_check_file_cache) { console.log('FLAG: check_file_cache='+run_check_file_cache); - check_file_cache_result = idb.check_file_cache(); + check_file_cache_result = app.check_file_cache(); check_file_cache_result.then(function (response) { console.log('Cached files have now been updated.'); @@ -596,7 +570,7 @@ // End of cached file section - + /* ***** **** *** ** * ### * ** *** **** ***** */ var check_initial_online_status = setInterval(async function() { @@ -619,8 +593,17 @@ } clearInterval(check_initial_online_status); + }, 500); + + + + let status_clock = setInterval(function() { + //https://date-fns.org/v1.30.1/docs/format + let datetime_string = dateFns.format(new Date(), 'dddd, Do h:mm:ss A'); //dddd, Do hh:mm:ss A + document.getElementById('app_datetime').innerHTML = datetime_string; }, 1000); + diff --git a/app/js/app_api.js b/app/js/app_api.js index e165d43..6cccb5b 100644 --- a/app/js/app_api.js +++ b/app/js/app_api.js @@ -5,28 +5,29 @@ async function api_token_request_async(axios, secret_key) { console.log('Already waiting on an API token request. Not starting another until finished.'); return false; } else { + waiting_on_api_token = true; + const url = '/api_token_request'; + + let data = { secret_key: secret_key }; + + const result = await axios.post(url, data) + .then(function (response) { + //console.log(response); + const api_temporary_token = response.data.temporary_token; + //console.log('API Temporary Token: '+temporary_token); + return api_temporary_token; + }) + .catch(function (error) { + console.error(error); + return false; + }); + + waiting_on_api_token = false; + return result; } - waiting_on_api_token = true; - const url = '/api_token_request'; - - let data = { secret_key: secret_key }; - - const result = await axios.post(url, data) - .then(function (response) { - //console.log(response); - const api_temporary_token = response.data.temporary_token; - //console.log('API Temporary Token: '+temporary_token); - return api_temporary_token; - }) - .catch(function (error) { - console.error(error); - return false; - }); - - waiting_on_api_token = false; - return result; + return false; } diff --git a/app/js/module_app.js b/app/js/module_app.js index 09ac018..fe1455d 100644 --- a/app/js/module_app.js +++ b/app/js/module_app.js @@ -2,6 +2,7 @@ const os = require('os'); const path = require('path'); const fs = require('fs'); +const { ipcRenderer } = require('electron'); exports.load_config = function () { console.log('CWD: '+process.cwd()); @@ -67,24 +68,70 @@ exports.load_config = function () { return config; } + +exports.check_file_cache = async function () { + console.log('**** *** ** * FUNCTION: check_file_cache * ** *** ****'); + console.log('Checking the local file cache against the remote server.'); + + if (api_base_url && api_temporary_token) { + tbl_event_file.iterate(function(file_value, key, iteration) { + //if (file_value.event_location_id == event_location_id) { + //console.log('f: ('+file_value.event_file_id+') '+file_value.event_file_filename+' ***') + + let file_id = file_value.id; // NOTE: This is the event_file.id or event_file_id. + let filename = file_value.hosted_file_hash_sha256+'.file'; + + let save_path = path.join(host_file_cache_path, filename); + //console.log(save_path); + + if (fs.existsSync(save_path)) { + //console.log('Local file already exists: '+save_path); + } else { + console.log('File not found locally. Downloading file: '+save_path); + let api_endpoint = '/event/file/'+file_id+'/download'; + ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // Must download file using main node.js thread. + } + }); + } else { + console.log('The api_base_url or api_temporary_token has not been set.'); + console.log(api_base_url); + console.log(api_temporary_token); + return false; + } + + return true; +} + + exports.currently_online = function() { //alert('You are currently online'); console.log('Currently online'); app_online = true; - document.getElementById('network_status1').classList.remove('btn-warning'); - document.getElementById('network_status1').classList.add('btn-success'); - document.getElementById('network_status1').innerHTML = ' Currently Online'; - //document.getElementById('network_status1').innerHTML('Currently Online'); + //document.getElementById('app_network_status').classList.remove('alert-info'); + //document.getElementById('app_network_status').classList.remove('warning'); + //document.getElementById('app_network_status').classList.remove('alert-warning'); + //document.getElementById('app_network_status').classList.add('success'); + //document.getElementById('app_network_status').classList.add('alert-success'); + document.getElementById('app_network_status').classList.remove('app_warning'); + //document.getElementById('app_network_status').classList.add('d-none'); + document.getElementById('app_network_status').innerHTML = ' Currently Online'; + //document.getElementById('app_network_status').innerHTML('Currently Online'); } + exports.currently_offline = function() { //alert('You are currently offline'); console.log('Currently offline'); app_online = false; - document.getElementById('network_status1').classList.remove('btn-success'); - document.getElementById('network_status1').classList.add('btn-warning'); - document.getElementById('network_status1').innerHTML = ' Currently Offline'; - //document.getElementById('network_status1').innerHTML('Currently Offline'); + //document.getElementById('app_network_status').classList.remove('alert-info'); + //document.getElementById('app_network_status').classList.remove('success'); + //document.getElementById('app_network_status').classList.remove('alert-success'); + //document.getElementById('app_network_status').classList.add('warning'); + //document.getElementById('app_network_status').classList.add('alert-warning'); + document.getElementById('app_network_status').classList.add('app_warning'); + //document.getElementById('app_network_status').classList.remove('d-none'); + document.getElementById('app_network_status').innerHTML = ' Currently Offline'; + //document.getElementById('app_network_status').innerHTML('Currently Offline'); } //window.addEventListener('online', currently_online); diff --git a/app/js/module_app_idb.js b/app/js/module_app_idb.js index 4bd3d3d..bcf0bc1 100644 --- a/app/js/module_app_idb.js +++ b/app/js/module_app_idb.js @@ -5,9 +5,15 @@ const fs = require('fs'); const { ipcRenderer } = require('electron'); exports.check_file_cache = async function () { + console.log('**** *** ** * FUNCTION: check_file_cache * ** *** ****'); console.log('Checking the local file cache against the remote server.'); - tbl_event_file.iterate(function(file_value, key, iteration) { - //if (file_value.event_location_id == event_location_id) { + console.log(api_base_url); + console.log(api_temporary_token); + + //console.log(save_path); + if (api_base_url && api_temporary_token) { + tbl_event_file.iterate(function(file_value, key, iteration) { + //if (file_value.event_location_id == event_location_id) { //console.log('f: ('+file_value.event_file_id+') '+file_value.event_file_filename+' ***') file_id = file_value.id; // NOTE: This is the event_file.id or event_file_id. @@ -22,8 +28,13 @@ exports.check_file_cache = async function () { let api_endpoint = '/event/file/'+file_id+'/download'; ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // Must download file using main node.js thread. } - //} - }); + }); + } else { + console.log('The api_base_url or api_temporary_token has not been set.'); + console.log(api_base_url); + console.log(api_temporary_token); + return false; + } return true; } diff --git a/index.js b/index.js index 34dba32..26957a5 100644 --- a/index.js +++ b/index.js @@ -93,6 +93,8 @@ app.on('activate', () => { ipcMain.on('download_file', (event, api_base_url, api_endpoint, api_temporary_token, save_path) => { + console.log('ipcMain on download_file: api_base_url='+api_base_url+' | api_temporary_token='+api_temporary_token); + console.log(api_temporary_token); console.log('ipcMain download and save file: '+api_endpoint+' -> '+save_path); axios.defaults.baseURL = api_base_url;