diff --git a/packages/main/src/DataHubService.ts b/packages/main/src/DataHubService.ts index 5fb0bec..ffeb6f4 100644 --- a/packages/main/src/DataHubService.ts +++ b/packages/main/src/DataHubService.ts @@ -102,7 +102,6 @@ export const DataHubService = { p++; arcs = arcs.concat(arcs_page); } - console.log(arcs.length) return arcs; }, diff --git a/packages/main/src/InternetService.ts b/packages/main/src/InternetService.ts index 9d0bcf6..047a9c9 100644 --- a/packages/main/src/InternetService.ts +++ b/packages/main/src/InternetService.ts @@ -16,7 +16,15 @@ const default_header = { export const InternetService = { - getWebPageAsJson: (e,options): Promise => { + getWebPageAsJson: async (e,options): Promise => { + // check if server is available + try { + await net.resolveHost(options.host); + } catch(err) { + return new Promise((resolve,reject)=>resolve(null)); + } + + // get json data return new Promise( (resolve, reject) => { try { @@ -25,7 +33,7 @@ export const InternetService = { for(let h in header) request.setHeader(h,header[h]); - request.on('response', (response) => { + request.on('response', response => { if(response.statusCode===200){ let output = ''; response.on('data', chunk => { @@ -35,13 +43,11 @@ export const InternetService = { resolve(JSON.parse(output)); }); } else { - // console.error('response',response); resolve(null); } }) request.end() - } catch(err){ - console.error('catch',err); + }catch(err){ resolve(null); } } diff --git a/packages/main/src/LocalFileSystemService.ts b/packages/main/src/LocalFileSystemService.ts index f8dcdba..8dfcecc 100644 --- a/packages/main/src/LocalFileSystemService.ts +++ b/packages/main/src/LocalFileSystemService.ts @@ -1,4 +1,4 @@ -import { BrowserWindow, ipcMain, dialog, shell } from 'electron'; +import { app, BrowserWindow, ipcMain, dialog, shell } from 'electron'; import PATH from 'path'; import FS from 'fs'; import FSE from 'fs-extra' @@ -100,6 +100,18 @@ export const LocalFileSystemService = { } }, + readConfig: ()=>{ + const config = LocalFileSystemService.readFile(null,app.getPath('userData')+'/ARCitect.json'); + return JSON.parse(config) || {}; + }, + + writeConfig: (e,config)=>{ + LocalFileSystemService.writeFile(null,[ + app.getPath('userData')+'/ARCitect.json', + config + ]); + }, + readImage: async (e,path)=>{ try { const contents = FS.readFileSync(path_to_system(path)); @@ -220,7 +232,7 @@ export const LocalFileSystemService = { } catch {return false;} }, - remove: async (e,path)=>{ + remove: (e,path)=>{ try { FS.rmSync(path_to_system(path), {recursive:true,force:true}); return true; @@ -246,6 +258,8 @@ export const LocalFileSystemService = { ipcMain.handle('LocalFileSystemService.readDir', LocalFileSystemService.readDir); ipcMain.handle('LocalFileSystemService.readFile', LocalFileSystemService.readFile); ipcMain.handle('LocalFileSystemService.readImage', LocalFileSystemService.readImage); + ipcMain.handle('LocalFileSystemService.readConfig', LocalFileSystemService.readConfig); + ipcMain.handle('LocalFileSystemService.writeConfig', LocalFileSystemService.writeConfig); ipcMain.handle('LocalFileSystemService.enforcePath', LocalFileSystemService.enforcePath); ipcMain.handle('LocalFileSystemService.writeFile', LocalFileSystemService.writeFile); ipcMain.handle('LocalFileSystemService.selectDir', LocalFileSystemService.selectDir); diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index 0cb77b1..2069679 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts @@ -43,6 +43,19 @@ app.on('window-all-closed', () => { */ app.on('activate', restoreOrCreateWindow); +const initConfig = async ()=>{ + const userDataPath = app.getPath('userData'); + if(!fs.existsSync(userDataPath)) + fs.mkdirSync(userDataPath); + + for(let file of ['ARCitect.json','DataHubs.json']){ + const sourceFile = 'resources/'+file; + const destinationFile = userDataPath+'/'+file; + if (!fs.existsSync(destinationFile)) + fs.copyFileSync(sourceFile, destinationFile); + } +}; + const initCore = async () => { const PATH = require('path'); if(process.platform === 'win32'){ @@ -55,17 +68,11 @@ const initCore = async () => { } ipcMain.handle('CORE.getVersion', ()=>app.getVersion()); ipcMain.handle('CORE.getTempPath', ()=>app.getPath('temp')); - - const userDataPath = app.getPath('userData'); - if(!fs.existsSync(userDataPath)) - fs.mkdirSync(userDataPath); - - for(let file of ['ARCitect.json','DataHubs.json']){ - const sourceFile = 'resources/'+file; - const destinationFile = userDataPath+'/'+file; - if (!fs.existsSync(destinationFile)) - fs.copyFileSync(sourceFile, destinationFile); - } + ipcMain.handle('CORE.reset', ()=>{ + LocalFileSystemService.remove( null, app.getPath('userData') ); + initConfig(); + }); + initConfig(); } /** diff --git a/packages/renderer/src/App.vue b/packages/renderer/src/App.vue index 7ae8b5a..c7977a0 100644 --- a/packages/renderer/src/App.vue +++ b/packages/renderer/src/App.vue @@ -16,6 +16,7 @@ import GitHistoryView from './views/GitHistoryView.vue'; import SwateView from './views/SwateView.vue'; import ValidationView from './views/ValidationView.vue'; import StatusView from './views/StatusView.vue'; +import SettingsView from './views/SettingsView.vue'; import ConfirmationDialog from './dialogs/ConfirmationDialog.vue'; import GitDialog from './dialogs/GitDialog.vue'; @@ -43,7 +44,6 @@ const $q = useQuasar(); const iProps = reactive({ showToolbar: true, - toolbarMinimized: false, splitterModel: 300, error: false, error_text: '', @@ -131,7 +131,6 @@ const showHomeView = ()=>{ }; const messagePrompt = msg => { - console.log(msg); $q.dialog({ component: ConfirmationDialog, componentProps: { @@ -184,7 +183,7 @@ const test = async ()=>{ v-model='iProps.showToolbar' show-if-above - :mini="iProps.toolbarMinimized" + :mini="AppProperties.config.toolbarMinimized" :width="190" :breakpoint="500" @@ -257,13 +256,10 @@ const test = async ()=>{ Check on the status of nfdi4plants services - - Show or hide the help menu + + Modify ARCitect settings - - Show or hide tooltips - - + @@ -280,14 +276,14 @@ const test = async ()=>{ - + @@ -307,6 +303,7 @@ const test = async ()=>{ + diff --git a/packages/renderer/src/AppProperties.ts b/packages/renderer/src/AppProperties.ts index e68fd74..ae0f1a1 100644 --- a/packages/renderer/src/AppProperties.ts +++ b/packages/renderer/src/AppProperties.ts @@ -1,4 +1,4 @@ -import { reactive } from 'vue' +import { reactive, watch } from 'vue' const AppProperties: { STATES: any, @@ -19,20 +19,33 @@ const AppProperties: { VALIDATION: 700, STATUS: 800, + SETTINGS: 900, }, STATES_I: {}, state: 0, user: null, + datahub_hosts : [], datahub_hosts_msgs: {}, force_commit_update: 0, force_lfs_update: 0, - showHelp: false, - showTooltips: false + config: { + toolbarMinimized: false, + showHelp: false, + showTooltips: false, + swate_url: '' + }, + + read_config: async ()=>{ + const config = await window.ipc.invoke('LocalFileSystemService.readConfig'); + for(let key of Object.keys(config)){ + AppProperties.config[key] = config[key]; + } + } }); for(let k in AppProperties.STATES){ @@ -48,16 +61,39 @@ const get_datahubs = async ()=>{ path: '/api/v4/broadcast_messages', method: 'GET' }); - let contains_critical = false; - for(let msg of AppProperties.datahub_hosts_msgs[host]){ - const t = msg.message.toLowerCase(); - msg.critical = t.includes('maintenance') || t.includes('downtime'); - contains_critical = contains_critical || (msg.critical && msg.active); + + // if server is not reachable + if(AppProperties.datahub_hosts_msgs[host]===null){ + const temp = []; + temp.critical = true; + temp.push({ + message: 'Server Not Reachable', + critical: true, + active: true, + starts_at: new Date().toISOString() + }) + console.log(new Date().toISOString()) + AppProperties.datahub_hosts_msgs[host] = temp; + } else { + let contains_critical = false; + for(let msg of AppProperties.datahub_hosts_msgs[host]){ + const t = msg.message.toLowerCase(); + msg.critical = t.includes('maintenance') || t.includes('downtime'); + contains_critical = contains_critical || (msg.critical && msg.active); + } + AppProperties.datahub_hosts_msgs[host].critical = contains_critical; } - AppProperties.datahub_hosts_msgs[host].critical = contains_critical; } }; -get_datahubs(); +const init = async ()=>{ + await AppProperties.read_config(); + watch(AppProperties.config, ()=>{ + console.log('xxx') + window.ipc.invoke('LocalFileSystemService.writeConfig', JSON.stringify(AppProperties.config)); + }); + await get_datahubs(); +} +init(); export default AppProperties; diff --git a/packages/renderer/src/components/ViewItem.vue b/packages/renderer/src/components/ViewItem.vue index d150844..eea5759 100644 --- a/packages/renderer/src/components/ViewItem.vue +++ b/packages/renderer/src/components/ViewItem.vue @@ -3,8 +3,7 @@ export interface Props { label: String, caption: String, - icon: String, - fullWidth?: Boolean, + icon: String }; const props = defineProps(); @@ -27,10 +26,7 @@ const props = defineProps(); -
- -
-
+
diff --git a/packages/renderer/src/components/a_tooltip.vue b/packages/renderer/src/components/a_tooltip.vue index 414bbf9..a11d95c 100644 --- a/packages/renderer/src/components/a_tooltip.vue +++ b/packages/renderer/src/components/a_tooltip.vue @@ -3,7 +3,7 @@ import AppProperties from '../AppProperties.ts'; diff --git a/packages/renderer/src/views/DataHubView.vue b/packages/renderer/src/views/DataHubView.vue index 69ae9aa..f7a2621 100644 --- a/packages/renderer/src/views/DataHubView.vue +++ b/packages/renderer/src/views/DataHubView.vue @@ -135,7 +135,6 @@ const host_manually_set = ()=>{ icon="cloud_download" label="Download ARC" caption="Download ARCs from the nfdi4plants DataHUB" - :fullWidth="false" >
diff --git a/packages/renderer/src/views/SettingsView.vue b/packages/renderer/src/views/SettingsView.vue new file mode 100644 index 0000000..8b161a4 --- /dev/null +++ b/packages/renderer/src/views/SettingsView.vue @@ -0,0 +1,88 @@ + + + diff --git a/packages/renderer/src/views/StatusView.vue b/packages/renderer/src/views/StatusView.vue index 30186db..47ff1fa 100644 --- a/packages/renderer/src/views/StatusView.vue +++ b/packages/renderer/src/views/StatusView.vue @@ -12,7 +12,7 @@ const iProps = reactive({ const format_date = utc => { const format = x => ('00' + x).slice(-2); const d = new Date(Date.parse(utc)); - return `${format(d.getDate())}.${format(d.getMonth()+1)}.${d.getFullYear()} ${format(d.getHours())}:${format(d.getMinutes())}`; + return `${format(d.getDate())}.${format(d.getMonth()+1)}.${d.getFullYear()} - ${format(d.getHours())}:${format(d.getMinutes())}`; }; @@ -23,7 +23,6 @@ const format_date = utc => { icon="dns" label="Services" caption="Status of nfdi4plants Services" - :fullWidth="true" > { @@ -66,7 +64,7 @@ const format_date = utc => { No Messages diff --git a/packages/renderer/src/views/SwateView.vue b/packages/renderer/src/views/SwateView.vue index 323aab5..f8c1b01 100644 --- a/packages/renderer/src/views/SwateView.vue +++ b/packages/renderer/src/views/SwateView.vue @@ -125,8 +125,7 @@ const init = async ()=>{ iProps.loading = true; iProps.showTimeout = false; setTimeout(()=>iProps.showTimeout=true,4000); - iframe.value.setAttribute("src", "https://swate-alpha.nfdi4plants.org?is_swatehost=1&random="+SwateControlService.props.cacheNumber); - // iframe.value.setAttribute("src", "https://localhost:3000?is_swatehost=1&random="+SwateControlService.props.cacheNumber); + iframe.value.setAttribute("src", `${AppProperties.config.swate_url}?is_swatehost=1&random=${SwateControlService.props.cacheNumber}`); }; onMounted(() => { diff --git a/resources/ARCitect.json b/resources/ARCitect.json index 0db3279..928c0a7 100644 --- a/resources/ARCitect.json +++ b/resources/ARCitect.json @@ -1,3 +1,6 @@ { - + "toolbarMinimized": false, + "showHelp": false, + "showTooltips": false, + "swate_url": "https://swate-alpha.nfdi4plants.org" }