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. 9
      scripts/fileview/load/render.js
  7. 13
      scripts/fileview/load/sort.js
  8. 9
      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. // and load the index.html of the app.
mainWindow.maximize(); mainWindow.maximize();
await mainWindow.loadFile('index.html'); await mainWindow.loadFile('index.html');
mainWindow.removeMenu(); //mainWindow.removeMenu();
// Open the DevTools. // Open the DevTools.
// mainWindow.webContents.openDevTools() // 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 extensions = require("../../../json/extensions.json");
const getsize = require("../../fileview/filesize"); 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 dir = window.kade.cpath;
let ldir = fs.readdirSync(dir); let ldir = fs.readdirSync(dir);
@ -37,6 +38,6 @@ module.exports = () => {
ofile.sizeString = ''; ofile.sizeString = '';
ofile.dir = true; ofile.dir = true;
} }
window.kade.cdir.push(ofile); load.push(ofile);
} }
}; };

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

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

@ -1,26 +1,27 @@
module.exports = (mode) => { module.exports = (mode, check=false) => {
mode = mode || window.kade.sort; mode = mode || window.kade.sort;
let ts = check ? window.kade.chdir : window.kade.cdir;
switch (mode) { switch (mode) {
case 'Name': case 'Name':
window.kade.cdir.sort((a, b) => { ts.sort((a, b) => {
a = a.name.toLowerCase(); a = a.name.toLowerCase();
b = b.name.toLowerCase(); b = b.name.toLowerCase();
return a > b ? 1 : a < b ? -1 : 0; return a > b ? 1 : a < b ? -1 : 0;
}); });
break; break;
case 'Date': case 'Date':
window.kade.cdir.sort((a, b) => a.lastModified - b.lastModified); ts.sort((a, b) => a.lastModified - b.lastModified);
break; break;
case 'Type': case 'Type':
window.kade.cdir.sort((a, b) => { ts.sort((a, b) => {
a = a.type.toLowerCase(); a = a.type.toLowerCase();
b = b.type.toLowerCase(); b = b.type.toLowerCase();
return a > b ? 1 : a < b ? -1 : 0; return a > b ? 1 : a < b ? -1 : 0;
}); });
break; break;
case 'Size': case 'Size':
window.kade.cdir.sort((a, b) => a.size - b.size); ts.sort((a, b) => a.size - b.size);
break; 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'); 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(); document.getElementById('files').remove();
let files = document.createElement('div'); let files = document.createElement('div');
files.className = 'files'; files.className = 'files';
@ -19,10 +20,12 @@ module.exports = (newPath) => {
temp.className = 'nosel'; temp.className = 'nosel';
fh.appendChild(temp); fh.appendChild(temp);
}); });
if (options.resetNav) {
document.getElementById('header-nav').remove(); document.getElementById('header-nav').remove();
let nav = document.createElement('div'); let nav = document.createElement('div');
nav.setAttribute('id', 'header-nav'); nav.setAttribute('id', 'header-nav');
document.getElementById('controls').appendChild(nav); document.getElementById('controls').appendChild(nav);
window.scrollTo(0, 0); }
loadDir(newPath); if (options.scroll) {window.scrollTo(0, 0);}
loadDir(newPath, options);
}; };

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

Loading…
Cancel
Save