-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
59 lines (45 loc) · 2.47 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Electro - A basic single page Electron application template.
Copyright (c) Cliff Earl, Antix Development, 2022.
MIT License:
*/
'use-strict';
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electronAPI', {
//
// Functions that `ipcMain` can call on `ipcRenderer`
//
//
// Resizing and dimensions
//
resized: (channel, func) => ipcRenderer.on(channel, func),
//
// Functions that `ipcRenderer` can call on `ipcMain`
//
getWindowBounds: () => (ipcRenderer.sendSync('getBounds')),
// General
getPlatform: () => (ipcRenderer.sendSync('getPlatform')),
setWindowIcon: (dataURL) => (ipcRenderer.sendSync('setWindowIcon', dataURL)),
quitApplication: () => (ipcRenderer.sendSync('quitApplication')),
enableConfig: (state) => (ipcRenderer.sendSync('enableConfig', state)),
launchURL: (url) => (ipcRenderer.sendSync('launchURL', url)),
// File system operations
exists: (path) => (ipcRenderer.sendSync('exists', path)),
deleteFile: (path) => (ipcRenderer.sendSync('unlinksync', path)),
createFolder: (path) => (ipcRenderer.sendSync('createFolder', path)),
fileInfo: (path) => (ipcRenderer.sendSync('fileInfo', path)),
currentDirectory: (path) => (ipcRenderer.sendSync('currentDirectory', path)),
newFileName: (...parts) => (ipcRenderer.sendSync('newFileName', ...parts)),
loadTextFile: (path) => (ipcRenderer.sendSync('loadTextFile', path)),
saveTextFile: (path, data) => (ipcRenderer.sendSync('saveTextFile', {path: path, data : data})),
saveBinaryFile: (path, data) => (ipcRenderer.sendSync('saveBinaryFile', {path: path, data : data})),
saveCanvas: (path, dataURL) => (ipcRenderer.sendSync('saveCanvas', {path : path, dataURL: dataURL})),
showSingleFileDialog: (options) => (ipcRenderer.sendSync('showSingleFileDialog', {title: options.title, defaultPath : options.path, filters: [options.filter]})),
showMultipleFileDialog: (options) => (ipcRenderer.sendSync('showMultipleFileDialog', {title: options.title, defaultPath : options.path, filters: [options.filter]})),
showSaveFileDialog: (options) => (ipcRenderer.sendSync('showSaveFileDialog', {title: options.title, defaultPath : options.path, filters: [options.filter]})),
// Title bar and menus
setWindowTitle: () => (ipcRenderer.sendSync('setWindowTitle')),
maximizeWindow: () => ipcRenderer.send('maximize'),
minimizeWindow: () => ipcRenderer.send('minimize'),
quitApplication: () => ipcRenderer.send('close'),
});