-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
22 lines (19 loc) · 953 Bytes
/
preload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const { contextBridge, ipcRenderer } = require('electron')
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const dependency of ['chrome', 'node', 'electron']) {
replaceText(`${dependency}-version`, process.versions[dependency])
}
})
contextBridge.exposeInMainWorld('electronAPI', {
openLink: (url) => ipcRenderer.invoke('action:openUrl', url),
getSettings: () => ipcRenderer.invoke('settings:getSettings'),
setColorMode: (mode) => ipcRenderer.invoke('settings:setColorMode', mode),
chooseDatabaseFolder: () => ipcRenderer.invoke('dialog:databaseFolder'),
setDatabaseFolder: (folder) => ipcRenderer.invoke('settings:setDatabaseFolder', folder),
chooseSiteFolder: () => ipcRenderer.invoke('dialog:siteFolder'),
setSiteFolder: (folder) => ipcRenderer.invoke('settings:setSiteFolder', folder)
})