-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
29 lines (24 loc) · 862 Bytes
/
preload.js
File metadata and controls
29 lines (24 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { ipcRenderer } = require('electron')
// This is our electron-only client-side JS code.
// We can only pre-load from filesystem from within Electron
const INPUT_LIST = 'input-list'
const INPUT_FILES = 'inputFiles'
// loadFiles - This will attempt to load the saved files used from last time.
const loadFiles = () => {
const inputFiles = JSON.parse(localStorage.getItem(INPUT_FILES))
if (!inputFiles) {
return
}
inputFiles.forEach(async filepath => {
const fileOutput = await ipcRenderer.invoke('readFile', filepath)
addToInput(INPUT_LIST, fileOutput)
})
}
const addToInput = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.value += text
document.getElementById(INPUT_LIST).dispatchEvent(new Event('input'))
}
window.addEventListener('DOMContentLoaded', () => {
loadFiles()
})