From 946020a43af7568da7be0cf7511401bcf2b64baf Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 3 Dec 2021 23:22:29 -0700 Subject: [PATCH] IPC integration; custom keybinds --- json/shortcuts.json | 5 +++-- scripts/fileview/load/render.js | 1 + scripts/fileview/refresh.js | 1 + scripts/keybinds/handle.js | 9 --------- scripts/keybinds/handleKey.js | 14 ++++++++++++++ scripts/keybinds/process/devtool.js | 4 ++++ scripts/keybinds/process/handleIpc.js | 7 +++++++ scripts/keybinds/process/reload.js | 3 +++ scripts/keybinds/reload.js | 4 ---- scripts/renderer.js | 2 +- scripts/startup/preload.js | 7 +++++++ 11 files changed, 41 insertions(+), 16 deletions(-) delete mode 100644 scripts/keybinds/handle.js create mode 100644 scripts/keybinds/handleKey.js create mode 100644 scripts/keybinds/process/devtool.js create mode 100644 scripts/keybinds/process/handleIpc.js create mode 100644 scripts/keybinds/process/reload.js delete mode 100644 scripts/keybinds/reload.js diff --git a/json/shortcuts.json b/json/shortcuts.json index edac5e1..4382801 100644 --- a/json/shortcuts.json +++ b/json/shortcuts.json @@ -1,4 +1,5 @@ { - "ctrl+r": "reload", - "command+r": "reload" + "ctrl+r": "reload", + "command+r": "reload", + "ctrl+shift+i": "devtool" } \ No newline at end of file diff --git a/scripts/fileview/load/render.js b/scripts/fileview/load/render.js index 5d845a1..22aaa5c 100644 --- a/scripts/fileview/load/render.js +++ b/scripts/fileview/load/render.js @@ -56,6 +56,7 @@ module.exports = (dir) => { size.className = 'file-size'; size.innerHTML = file.sizeString; cfc.appendChild(size); + Array.from(cfc.children).forEach(el => el.classList.add('nosel')); num++; } diff --git a/scripts/fileview/refresh.js b/scripts/fileview/refresh.js index 095aa86..91beac4 100644 --- a/scripts/fileview/refresh.js +++ b/scripts/fileview/refresh.js @@ -16,6 +16,7 @@ module.exports = (newPath) => { let temp = document.createElement('p'); temp.innerHTML = k; temp.style = `flex-basis: ${headers[k]}%;`; + temp.className = 'nosel'; fh.appendChild(temp); }); document.getElementById('header-nav').remove(); diff --git a/scripts/keybinds/handle.js b/scripts/keybinds/handle.js deleted file mode 100644 index 0c69fa6..0000000 --- a/scripts/keybinds/handle.js +++ /dev/null @@ -1,9 +0,0 @@ -const mousetrap = require('../dep/mousetrap'); - -const binds = require('../../json/shortcuts.json'); - -module.exports = () => { - Object.keys(binds).forEach((bind) => { - mousetrap.bind(bind, require(`./${binds[bind]}.js`)); - }); -}; \ No newline at end of file diff --git a/scripts/keybinds/handleKey.js b/scripts/keybinds/handleKey.js new file mode 100644 index 0000000..9eb99f1 --- /dev/null +++ b/scripts/keybinds/handleKey.js @@ -0,0 +1,14 @@ +const mousetrap = require('../dep/mousetrap'); +const electron = require('electron'); const ipc = electron.ipcRenderer; + +const binds = require('../../json/shortcuts.json'); + +module.exports = () => { + const sendIpcMessage = (message) => { + ipc.sendSync('keybind', message); + }; + + Object.keys(binds).forEach((bind) => { + mousetrap.bind(bind, () => sendIpcMessage(binds[bind])); + }); +}; \ No newline at end of file diff --git a/scripts/keybinds/process/devtool.js b/scripts/keybinds/process/devtool.js new file mode 100644 index 0000000..8234087 --- /dev/null +++ b/scripts/keybinds/process/devtool.js @@ -0,0 +1,4 @@ +module.exports = (broswerWindow, app) => { + broswerWindow.webContents.openDevTools(); + return 'opened inspect element'; +}; \ No newline at end of file diff --git a/scripts/keybinds/process/handleIpc.js b/scripts/keybinds/process/handleIpc.js new file mode 100644 index 0000000..0952f84 --- /dev/null +++ b/scripts/keybinds/process/handleIpc.js @@ -0,0 +1,7 @@ +const {ipcMain: ipc} = require('electron'); + +module.exports = (browserWindow, app) => { + ipc.on('keybind', (event, arg) => { + try {event.returnValue = require(`./${arg}`)(browserWindow, app);} catch {} + }); +}; \ No newline at end of file diff --git a/scripts/keybinds/process/reload.js b/scripts/keybinds/process/reload.js new file mode 100644 index 0000000..361617e --- /dev/null +++ b/scripts/keybinds/process/reload.js @@ -0,0 +1,3 @@ +module.exports = (browserWindow, app) => { + browserWindow.reload(); +}; \ No newline at end of file diff --git a/scripts/keybinds/reload.js b/scripts/keybinds/reload.js deleted file mode 100644 index 2a81619..0000000 --- a/scripts/keybinds/reload.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = () => { - window.reload(); - console.log('e'); -}; \ No newline at end of file diff --git a/scripts/renderer.js b/scripts/renderer.js index d3bdade..ba82697 100644 --- a/scripts/renderer.js +++ b/scripts/renderer.js @@ -1,5 +1,5 @@ // This file is required by the index.html file and will -// be executed in the renderer process for that window. +// be executed in the process process for that window. // No Node.js APIs are available in this process because // `nodeIntegration` is turned off. Use `preload.js` to // selectively enable features needed in the rendering diff --git a/scripts/startup/preload.js b/scripts/startup/preload.js index 370ec68..1bac7e7 100644 --- a/scripts/startup/preload.js +++ b/scripts/startup/preload.js @@ -21,4 +21,11 @@ window.addEventListener('DOMContentLoaded', () => { if (window.kade.cl) {window.kade.cl.classList.remove('file-active');} }, 100); } + + require('../keybinds/handleKey')(); }); + +window.addEventListener('contextmenu', e => { + e.preventDefault(); + +}); \ No newline at end of file