LightRefresh, fs dir watch/refresh

toast
Kit Kasune 3 years ago
parent 2b3662e337
commit 6064f44a62
  1. 2
      main.js
  2. 14
      scripts/fileview/checkdir.js
  3. 5
      scripts/fileview/lightrefresh.js
  4. 5
      scripts/fileview/load/load.js
  5. 4
      scripts/fileview/load/loaddir.js
  6. 19
      scripts/fileview/load/render.js
  7. 13
      scripts/fileview/load/sort.js
  8. 17
      scripts/fileview/refresh.js
  9. 20
      scripts/startup/preload.js

@ -22,7 +22,7 @@ async function createWindow () {
// and load the index.html of the app.
mainWindow.maximize();
await mainWindow.loadFile('index.html');
mainWindow.removeMenu();
//mainWindow.removeMenu();
// Open the DevTools.
// mainWindow.webContents.openDevTools()

@ -0,0 +1,14 @@
const load = require('./load/load');
const sort = require('./load/sort');
const lightRefresh = require("./lightrefresh");
module.exports = () => {
if (!window.kade.cpath.length || !window.kade.cdir.length) {return;}
window.kade.chdir = [];
load(true);
sort(undefined, true);
if (JSON.stringify(window.kade.cdir) !== JSON.stringify(window.kade.chdir)) {
//console.log('Detected directory updates.', JSON.stringify(window.kade.cdir), JSON.stringify(window.kade.chdir));
lightRefresh();
}
};

@ -0,0 +1,5 @@
const refresh = require('./refresh');
module.exports = (newPath, customOptions) => {
return refresh(newPath || window.kade.cpath, customOptions || {animate: false, resetNav: false, scroll: false});
};

@ -8,7 +8,8 @@ const trimext = require("../../../json/trimext.json");
const extensions = require("../../../json/extensions.json");
const getsize = require("../../fileview/filesize");
module.exports = () => {
module.exports = (check=false) => {
let load = check ? window.kade.chdir : window.kade.cdir;
let dir = window.kade.cpath;
let ldir = fs.readdirSync(dir);
@ -37,6 +38,6 @@ module.exports = () => {
ofile.sizeString = '';
ofile.dir = true;
}
window.kade.cdir.push(ofile);
load.push(ofile);
}
};

@ -2,11 +2,11 @@ const load = require('./load');
const sort = require('./sort');
const render = require('./render');
module.exports = (dir) => {
module.exports = (dir, options) => {
window.kade.cpath = dir;
window.kade.cdir = [];
load();
sort();
render();
render(undefined, options);
};

@ -1,9 +1,8 @@
const loadHierarchy = require("../hierarchy");
const isOverflowing = require('../../dep/overflowing');
const refresh = require("../refresh");
module.exports = (dir) => {
module.exports = (dir, options) => {
const refresh = require("../refresh");
let cdir = dir || window.kade.cdir;
@ -13,7 +12,7 @@ module.exports = (dir) => {
const exp = document.getElementById('files');
let cfc = document.createElement("div");
cfc.className = 'file';
cfc.classList.add('rise');
if (options.animate) {cfc.classList.add('rise');}
cfc.onclick = function () {
window.kade.elc = true;
if (cfc.classList.contains('file-active')) {if (file.dir) {refresh(`${window.kade.cpath}\\${file.name}`);}}
@ -27,11 +26,13 @@ module.exports = (dir) => {
if (window.kade.cl) {window.kade.cl.classList.remove('file-active');}
window.kade.cl = cfc;
};
cfc.style = `animation-delay: ${num * .03}s`;
cfc.onanimationend = () => {
cfc.style = '';
cfc.classList.remove('rise');
};
if (options.animate) {
cfc.style = `animation-delay: ${num * .03}s`;
cfc.onanimationend = () => {
cfc.style = '';
cfc.classList.remove('rise');
};
}
exp.appendChild(cfc);
let im = document.createElement('img');
im.src = file.icon;
@ -67,5 +68,5 @@ module.exports = (dir) => {
num++;
}
loadHierarchy();
if (options.resetNav) {loadHierarchy();}
};

@ -1,26 +1,27 @@
module.exports = (mode) => {
module.exports = (mode, check=false) => {
mode = mode || window.kade.sort;
let ts = check ? window.kade.chdir : window.kade.cdir;
switch (mode) {
case 'Name':
window.kade.cdir.sort((a, b) => {
ts.sort((a, b) => {
a = a.name.toLowerCase();
b = b.name.toLowerCase();
return a > b ? 1 : a < b ? -1 : 0;
});
break;
case 'Date':
window.kade.cdir.sort((a, b) => a.lastModified - b.lastModified);
ts.sort((a, b) => a.lastModified - b.lastModified);
break;
case 'Type':
window.kade.cdir.sort((a, b) => {
ts.sort((a, b) => {
a = a.type.toLowerCase();
b = b.type.toLowerCase();
return a > b ? 1 : a < b ? -1 : 0;
});
break;
case 'Size':
window.kade.cdir.sort((a, b) => a.size - b.size);
ts.sort((a, b) => a.size - b.size);
break;
}
if (!window.kade.ascend) {window.kade.cdir.reverse();}
if (!window.kade.ascend) {ts.reverse();}
};

@ -2,7 +2,8 @@ const loadDir = require('./load/loaddir');
const headers = require('../../json/headers.json');
module.exports = (newPath) => {
module.exports = (newPath, options={animate:true,scroll:true,resetNav:true}) => {
['animate', 'scroll', 'resetNav'].forEach(k => {if (typeof options[k] === 'undefined') {options[k] = true;}});
document.getElementById('files').remove();
let files = document.createElement('div');
files.className = 'files';
@ -19,10 +20,12 @@ module.exports = (newPath) => {
temp.className = 'nosel';
fh.appendChild(temp);
});
document.getElementById('header-nav').remove();
let nav = document.createElement('div');
nav.setAttribute('id', 'header-nav');
document.getElementById('controls').appendChild(nav);
window.scrollTo(0, 0);
loadDir(newPath);
if (options.resetNav) {
document.getElementById('header-nav').remove();
let nav = document.createElement('div');
nav.setAttribute('id', 'header-nav');
document.getElementById('controls').appendChild(nav);
}
if (options.scroll) {window.scrollTo(0, 0);}
loadDir(newPath, options);
};

@ -2,15 +2,18 @@ const os = require('os');
const setButtons = require('./setbuttons');
const hideContext = require('../contextmenu/hidecontext');
const lightRefresh = require('../fileview/lightrefresh');
const checkDir = require('../fileview/checkdir');
window.addEventListener('DOMContentLoaded', () => {
window.kade = {};
window.kade.elc = false;
window.kade.cpath = '';
window.kade.sort = 'Name';
window.kade.ascend = true;
window.kade.context = false;
window.kade = {
elc: false,
cpath: '',
sort: 'Name',
ascend: true,
context: false,
chdir: []
};
const startDir = `${os.homedir}\\Desktop`;
@ -27,6 +30,9 @@ window.addEventListener('DOMContentLoaded', () => {
document.getElementById('ctx').style.display = 'none';
window.kade.refreshInterval = setInterval(lightRefresh, 180000);
window.kade.checkDirInterval = setInterval(checkDir, 5000);
require('../keybinds/handleKey')();
});

Loading…
Cancel
Save