Skip to content

Commit

Permalink
Allow removing files from open ARC 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Nov 15, 2023
1 parent dd43f9f commit 39f8ea4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
21 changes: 11 additions & 10 deletions packages/main/src/LocalFileSystemService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import FS from 'fs';
import FSE from 'fs-extra'
import chokidar from 'chokidar';
import util from 'util';
import os from 'os'

const changeListeners = {};
const changeListeners = new Map<string,chokidar.FSWatcher> ;

const path_to_arcitect = (path: string) => path.split(PATH.sep).join('/')
const path_to_system = (path: string) => path.split('/').join(PATH.sep)
Expand Down Expand Up @@ -104,20 +105,20 @@ export const LocalFileSystemService = {
registerChangeListener: async (e,path)=>{
path = path_to_system(path)

if(changeListeners[path])
if(changeListeners.has(path))
await LocalFileSystemService.unregisterChangeListener(null,path);

changeListeners[path] = chokidar.watch(path,{ignoreInitial:true});
const listener = chokidar.watch(path,{ignoreInitial:true, usePolling: os.platform()==='win32'});
changeListeners.set(path, listener);

const updatePath = path => {
const window = BrowserWindow.getAllWindows().find(w => !w.isDestroyed());
window.webContents.send('LocalFileSystemService.updatePath', path_to_arcitect(path));
window?.webContents.send('LocalFileSystemService.updatePath', path_to_arcitect(path));
};
const updateParentPath = path => {
updatePath( PATH.dirname(path) );
};

changeListeners[path]
listener
// .on('all', (event, path) => {
// // console.log(event,path);
// })
Expand All @@ -133,12 +134,12 @@ export const LocalFileSystemService = {
unregisterChangeListener: async (e,path)=>{
// console.log('ul',path)
path = path_to_system(path)
const watcher = changeListeners[path];
const watcher = changeListeners.get(path);
if(!watcher)
return;

await watcher.unwatch();
delete changeListeners[path];
await watcher.unwatch(path);
changeListeners.delete(path);
return;
},

Expand All @@ -158,7 +159,7 @@ export const LocalFileSystemService = {
FS.writeFileSync(path,data,options);
} catch (err) {
let window = BrowserWindow.getAllWindows().find(w => !w.isDestroyed());
window.webContents.send('CORE.MSG', err);
window?.webContents.send('CORE.MSG', err);
}
},

Expand Down
24 changes: 16 additions & 8 deletions packages/renderer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ const iProps = reactive({
const openLocalArc = async (path: string | null | void) =>{
if(!path) path = await window.ipc.invoke('LocalFileSystemService.selectDir', ['Select local ARC','Select local ARC']);
if(!path) return;
const isARC = await window.ipc.invoke('LocalFileSystemService.exists', path+'/isa.investigation.xlsx');
if(!isARC){
let isOpen = await ArcControlService.readARC(path);
if(!isOpen){
iProps.error_text = 'Invalid ARC format:<br>'+path;
iProps.error = true;
return;
}
AppProperties.state=AppProperties.STATES.HOME;
};
await ArcControlService.readARC(path);
const refreshLocalArc = async () =>{
let path = ArcControlService.props.arc_root;
let isOpen = await ArcControlService.readARC(path);
if(!isOpen){
iProps.error_text = 'Unable to find valid ARC at:<br>'+path;
iProps.error = true;
return;
}
AppProperties.state=AppProperties.STATES.HOME;
};
Expand Down Expand Up @@ -130,10 +139,9 @@ const test = async ()=>{
<q-separator />

<!--<ToolbarButton text='Upload ARC' icon='cloud_upload' requiresARC='true' @clicked='test()'></ToolbarButton>-->
<ToolbarButton text='Reset ARC' icon='autorenew' requiresARC @clicked='ArcControlService.readARC()'></ToolbarButton>
<ToolbarButton text='Refresh ARC' icon='autorenew' requiresARC @clicked='refreshLocalArc()'></ToolbarButton>
<ToolbarButton text='Versions' icon='update' requiresARC @clicked='AppProperties.state=AppProperties.STATES.GIT'></ToolbarButton>
<ToolbarButton text='Explorer' icon='folder_open' requiresARC @clicked='ArcControlService.openArcInExplorer()'></ToolbarButton>

<q-separator />


Expand Down Expand Up @@ -169,9 +177,9 @@ const test = async ()=>{
:limits='[300,Infinity]'
>
<template v-slot:before>
<q-scroll-area class='fit' style="height: 100%;">
<ArcTreeView @openArc='openLocalArc'></ArcTreeView>
</q-scroll-area>
<q-scroll-area class='fit' style="flex-grow: 1;">
<ArcTreeView @openArc='openLocalArc'></ArcTreeView>
</q-scroll-area>
</template>

<template v-slot:after>
Expand Down
2 changes: 0 additions & 2 deletions packages/renderer/src/AppProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const AppProperties = reactive({

user: null,
path_sep: null,

arc_root: null
});

for(let k in AppProperties.STATES){
Expand Down
18 changes: 18 additions & 0 deletions packages/renderer/src/ArcControlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,29 @@ const ArcControlService = {

props: reactive(init),

closeARC: async() => {
ArcControlService.props.arc_root = null;
ArcControlService.props.busy = false;
ArcControlService.props.arc = null;
AppProperties.active_assay = null;
AppProperties.active_study = null;
AppProperties.state = 0;
return;
},

readARC: async (arc_root: string | void | null) =>{
if(!arc_root)
arc_root = ArcControlService.props.arc_root;
if(!arc_root)
return;

const isARC = await window.ipc.invoke('LocalFileSystemService.exists', arc_root+'/isa.investigation.xlsx');

if (!isARC) {
ArcControlService.closeARC();
return false;
}

ArcControlService.props.busy = true;

const xlsx_files = await window.ipc.invoke('LocalFileSystemService.getAllXLSX', arc_root);
Expand All @@ -44,6 +61,7 @@ const ArcControlService = {
ArcControlService.props.arc_root = arc_root;
ArcControlService.props.busy = false;
console.log(arc);
return true;
},

writeARC: async (arc_root,filter,arc)=>{
Expand Down
4 changes: 2 additions & 2 deletions packages/renderer/src/views/ArcTreeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,9 @@ onUnmounted( ()=>{window.ipc.off('LocalFileSystemService.updatePath', updatePath

<template>
<div class='q-pa-md'>
<div class='text-h6 text-grey-7' style="font-size:0.9em;border-bottom:0.1em solid #ccc;line-height:1em;padding:0 0 0.7em 0;">{{(props.root.replace(' ', '&nbsp;') || '').split('/').join(' /&nbsp;')}}</div>
<div v-if="ArcControlService.props.arc" class='text-h6 text-grey-7' style="font-size:0.9em;border-bottom:0.1em solid #ccc;line-height:1em;padding:0 0 0.7em 0;">{{(props.root.replace(' ', '&nbsp;') || '').split('/').join(' /&nbsp;')}}</div>
<q-tree
v-if="ArcControlService.props.arc"
ref='arcTree'
:nodes="props.nodes"
node-key="id"
Expand All @@ -366,7 +367,6 @@ onUnmounted( ()=>{window.ipc.off('LocalFileSystemService.updatePath', updatePath
<!--<q-icon name="account_tree" size="15em" style='color:#ccc' />-->
<q-icon name="find_in_page" size="15em" style='color:#ccc' v-on:click='emit("openArc")' />
</div>

</div>
</template>

Expand Down

0 comments on commit 39f8ea4

Please sign in to comment.