-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
27 lines (22 loc) · 973 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
23
24
25
26
27
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('darkMode', {
toggle: () => ipcRenderer.invoke('dark-mode:toggle'),
system: () => ipcRenderer.invoke('dark-mode:system')
})
contextBridge.exposeInMainWorld('notifications', {
push: (title, content, imageURL) => ipcRenderer.invoke('notifications:push', title, content, imageURL)
})
contextBridge.exposeInMainWorld('compactMode', {
enable: () => ipcRenderer.invoke('compact-mode:enable'),
disable: () => ipcRenderer.invoke('compact-mode:disable'),
get: () => ipcRenderer.invoke('compact-mode:get')
})