electron#contextBridge JavaScript Examples
The following examples show how to use
electron#contextBridge.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: preload.js From melvor-mod-manager with MIT License | 6 votes |
contextBridge.exposeInMainWorld('process', {
launchMelvor: async (melvorDir, launchMode) => await ipcRenderer.invoke('process', { type: process.launchMelvor, melvorDir, launchMode }),
openLink: async (url) => await ipcRenderer.invoke('process', { type: process.openLink, url }),
minimize: () => ipcRenderer.invoke('process', { type: process.minimize }),
maximize: () => ipcRenderer.invoke('process', { type: process.maximize }),
exit: () => ipcRenderer.invoke('process', { type: process.exit }),
getPlatform: () => ipcRenderer.invoke('process', { type: process.getPlatform }),
getVersion: () => ipcRenderer.invoke('process', { type: process.getVersion })
});
Example #2
Source File: preload.js From melvor-mod-manager with MIT License | 6 votes |
contextBridge.exposeInMainWorld('mods', {
// Returns mod manifest
parseFile: async (filePath) => await ipcRenderer.invoke('mods', { type: mods.parseFile, filePath }),
// Returns mod manifest
parseWeb: async (url) => await ipcRenderer.invoke('mods', { type: mods.parseWeb, origin: url }),
// Returns mod manifest
cloneGit: async (url, packageDir) => await ipcRenderer.invoke('mods', { type: mods.cloneGit, origin: url, packageDir }),
// Returns mod manifest
browserInstall: async (packageDir, data) => await ipcRenderer.invoke('mods', { type: mods.browserInstall, packageDir, data }),
// Returns error
add: async (packageDir, origin, manifest, content) => await ipcRenderer.invoke('mods', { type: mods.add, packageDir, origin, manifest, content }),
// Returns array of mod manifests
loadAll: async (packageDir) => await ipcRenderer.invoke('mods', { type: mods.loadAll, packageDir }),
// Returns mod manifest
load: async (packageDir, id) => await ipcRenderer.invoke('mods', { type: mods.load, packageDir, id }),
// Returns latest mod version or null if unable to fetch
checkForUpdates: async (mod) => await ipcRenderer.invoke('mods', { type: mods.checkForUpdates, mod }),
// Returns error
update: async (packageDir, id, browserData) => await ipcRenderer.invoke('mods', { type: mods.update, packageDir, id, browserData }),
// Returns error
remove: async (packageDir, id) => await ipcRenderer.invoke('mods', { type: mods.remove, packageDir, id }),
// Returns error
inject: async (packageDir, modsToInject) => await ipcRenderer.invoke('mods', { type: mods.inject, packageDir, mods: modsToInject })
});
Example #3
Source File: preload.js From among-us-proxy with MIT License | 6 votes |
contextBridge.exposeInMainWorld('ipcRenderer', {
send: (method, arg) => {
ipcRenderer.send(method, arg);
},
on: (m, f) => {
ipcRenderer.on(m, f);
},
removeListener: (m, f) => {
ipcRenderer.removeListener(m, f);
},
});
Example #4
Source File: electron-preload.js From loa-details with GNU General Public License v3.0 | 6 votes |
contextBridge.exposeInMainWorld("messageApi", {
send: (channel, data) => {
let validChannels = ["window-to-main"];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
receive: (channel, func) => {
let validChannels = [
"updater-message",
"pcap-on-message",
"pcap-on-state-change",
"pcap-on-reset-state",
"on-settings-change",
"parsed-logs-list",
"parsed-log",
"log-parser-status",
"on-restore-from-taskbar",
"shortcut-action",
"selected-log-path-folder",
];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
},
});
Example #5
Source File: electron-preload.js From loa-details with GNU General Public License v3.0 | 6 votes |
contextBridge.exposeInMainWorld("windowControlApi", {
minimize() {
BrowserWindow.getFocusedWindow().minimize();
},
toggleMaximize() {
const win = BrowserWindow.getFocusedWindow();
if (win.isMaximized()) {
win.unmaximize();
} else {
win.maximize();
}
},
close() {
BrowserWindow.getFocusedWindow().close();
},
hide() {
BrowserWindow.getFocusedWindow().hide();
},
setIgnoreMouseEvents(ignore, options) {
BrowserWindow.getFocusedWindow().setIgnoreMouseEvents(ignore, options);
},
});
Example #6
Source File: preload.js From melvor-mod-manager with MIT License | 5 votes |
contextBridge.exposeInMainWorld('file', {
// Returns generated manifest (for validation/renaming) and path
openScript: async () => await ipcRenderer.invoke('file', { type: file.openScript }),
// Returns path to opened directory
openDir: async () => await ipcRenderer.invoke('file', { type: file.openDir }),
// Returns true/false based on if Melvor is detected at path
validateMelvorDir: async (dir) => await ipcRenderer.invoke('file', { type: file.validateMelvorDir, dir })
});
Example #7
Source File: electron-preload.js From follow with GNU General Public License v3.0 | 5 votes |
contextBridge.exposeInMainWorld("ipc", {
getFileTypeFromBuffer: async (buf) => {
return await FileType.fromBuffer(buf);
},
invoke: async (channel, arg1, arg2, arg3, arg4, arg5) => {
return await ipcRenderer.invoke(channel, arg1, arg2, arg3, arg4, arg5);
},
send: (channel, data) => {
if (validChannels.includes(channel)) {
console.log("ipc.send...");
ipcRenderer.send(channel, data);
}
},
on: (channel, func) => {
if (validChannels.includes(channel)) {
// Strip event as it includes `sender` and is a security risk
console.log("ipc.on...");
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
},
once: (channel, callback) => {
if (validChannels.includes(channel)) {
console.log("ipc.once...");
const newCallback = (_, data) => callback(data);
ipcRenderer.once(channel, newCallback);
}
},
removeListener: (channel, callback) => {
if (validChannels.includes(channel)) {
console.log("ipc.removeListener...");
ipcRenderer.removeListener(channel, callback);
}
},
removeAllListeners: (channel) => {
if (validChannels.includes(channel)) {
console.log("ipc.removeAllListeners...");
ipcRenderer.removeAllListeners(channel);
}
},
});