electron#ipcMain JavaScript Examples
The following examples show how to use
electron#ipcMain.
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: index.js From desktop with GNU General Public License v3.0 | 6 votes |
ipcMain.handle('show-save-dialog', async (event, options) => {
const result = await dialog.showSaveDialog(BrowserWindow.fromWebContents(event.sender), {
filters: options.filters,
defaultPath: pathUtil.join(getLastAccessedDirectory(), options.suggestedName)
});
if (!result.canceled) {
const {filePath} = result;
setLastAccessedFile(filePath);
allowedToAccessFiles.add(filePath);
}
return result;
});
Example #2
Source File: index.js From among-us-proxy with MIT License | 6 votes |
ipcMain.on(RunDiscovery, event => {
close();
const discovery = (instance = new Discovery());
discovery.on('message', host => {
event.reply(DiscoveredHost, host);
});
discovery.listen();
});
Example #3
Source File: translations.js From desktop with GNU General Public License v3.0 | 6 votes |
ipcMain.on('locale-changed', (event, newLocale) => {
if (newLocale === locale) {
return;
}
log(`new locale: ${newLocale}`);
locale = newLocale;
set(STORAGE_KEY, locale);
translations = getTranslations(locale);
});
Example #4
Source File: controller.js From juggernaut-desktop with MIT License | 6 votes |
constructor(mainWindow) {
// Variable to hold the main window instance.
this.mainWindow = mainWindow;
// Active process pids, keyed by process name.
this.processes = {};
ipcMain.on('processSpawn', (event, { name, pid }) => {
this.processes[name] = pid;
});
ipcMain.on('processExit', (event, { name }) => {
this.processes[name] = null;
});
}
Example #5
Source File: rpc.js From desktop with GNU General Public License v3.0 | 6 votes |
destroy() {
this.removeAllListeners();
this.wc.removeAllListeners();
if (this.id) {
ipcMain.removeListener(this.id, this.ipcListener);
} else {
// mark for `genUid` in constructor
this.destroyed = true;
}
}
Example #6
Source File: index.js From clipcc-desktop with GNU Affero General Public License v3.0 | 6 votes |
ipcMain.on('open-extension-store', () => {
if (!net.isOnline()) {
return dialog.showMessageBoxSync(_windows.main, {
message: 'You need to be connected to the Internet to use the extension store.',
type: 'info'
});
}
_windows.extensionStore.loadURL('https://codingclip.com/extension/?desktop=1');
_windows.extensionStore.show();
});
Example #7
Source File: rpc.js From desktop with GNU General Public License v3.0 | 6 votes |
constructor(win) {
super();
this.win = win;
this.ipcListener = this.ipcListener.bind(this);
if (this.destroyed) {
return;
}
const uid = uuid.v4();
this.id = uid;
ipcMain.on(uid, this.ipcListener);
// we intentionally subscribe to `on` instead of `once`
// to support reloading the window and re-initializing
// the channel
this.wc.on("did-finish-load", () => {
this.wc.send("init", uid);
});
}
Example #8
Source File: index.js From clipcc-desktop with GNU Affero General Public License v3.0 | 6 votes |
ipcMain.handle('write-file', async (event, file, content) => {
try {
await fs.writeFile(file, content);
} catch (e) {
await dialog.showMessageBox(_windows.main, {
type: 'error',
message: `Cannot write file:\n${file}`,
detail: e.message
});
}
});
Example #9
Source File: index.js From desktop with GNU General Public License v3.0 | 6 votes |
ipcMain.on('alert', (event, message) => {
dialog.showMessageBoxSync(BrowserWindow.fromWebContents(event.sender), {
title: APP_NAME,
message: '' + message,
buttons: [
getTranslation('prompt.ok')
],
noLink: true
});
// set returnValue to something to reply so the renderer can resume
event.returnValue = 1;
});
Example #10
Source File: index.js From NIM-Pools-Hub-Miner with GNU General Public License v3.0 | 6 votes |
ipcMain.on("stopMining", async (event, arg) => {
store.dispatch("setPoolBalance", null);
if (arg === "cpu") {
if ($.miner) {
$.miner.disconnect();
delete $.miner;
store.dispatch("setCpuHashrate", "0 kH/s");
}
} else {
if ($.minerGPU) {
$.minerGPU.disconnect();
delete $.minerGPU;
}
if ($.nativeMiner) {
$.nativeMiner.stop();
delete $.nativeMiner;
store.dispatch("setGpuHashrate", "0 kH/s");
}
}
});
Example #11
Source File: ipc-server.js From EveReader with GNU Affero General Public License v3.0 | 6 votes |
constructor(eveApp) {
this.eveApp = eveApp;
// Set
ipcMain.on("get", function (event, key, id, windowId) {
event.sender.send("get-reply", key, eveApp[key], id, windowId);
});
// Get
ipcMain.on("set", function (event, key, value, id, windowId) {
eveApp[key] = value;
event.sender.send("set-reply", key, value, id, windowId);
});
/*
Trigger an eveApp method.
This method firts parameter 'args' is the arguments object sent by ipcMain-client.
The second parameter is an optionnal callback that can be added at the end of the method to send back a 'res' variable to ipcMain-client.
*/
ipcMain.on("trigger", function (event, key, args, id, windowId) {
if (typeof eveApp[key] !== "function") {
console.error(key + " is not a valid eveApp method");
} else {
eveApp[key](args, windowId, function (res) {
event.sender.send("trigger-reply", key, res, id, windowId);
});
}
});
}
Example #12
Source File: background.js From linked with GNU General Public License v3.0 | 6 votes |
ipcMain.handle('FETCH_FILE', async (event, args) => {
const [year, fileName] = args
const dataPath = getFilePath(year)
const filePath = `${dataPath}/${fileName}.json`
let file
// create the file if it does not exist yet
if (!fs.existsSync(filePath)) {
file = fs.promises.mkdir(dataPath, { recursive: true }).then(() => {
return fs.promises.writeFile(filePath, getDefaultData()).then(() => {
return fs.promises.readFile(filePath, 'utf-8').then((data) => {
return JSON.parse(data)
})
})
})
} else {
file = fs.promises.readFile(filePath, 'utf-8').then(data => JSON.parse(data))
}
// return the file
return file
})
Example #13
Source File: index.js From desktop with GNU General Public License v3.0 | 6 votes |
ipcMain.on('export-addon-settings', async (event, settings) => {
const result = await dialog.showSaveDialog(BrowserWindow.fromWebContents(event.sender), {
defaultPath: 'turbowarp-addon-setting.json',
filters: [
{
name: 'JSON',
extensions: ['json']
}
]
});
if (result.canceled) {
return;
}
const path = result.filePath;
await writeFile(path, JSON.stringify(settings));
});
Example #14
Source File: background.js From melvor-mod-manager with MIT License | 6 votes |
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', async () => {
if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools
try {
await installExtension(VUEJS_DEVTOOLS);
} catch (e) {
console.error('Vue Devtools failed to install:', e.toString());
}
}
ipcMain.handle('process', processHandler);
ipcMain.handle('file', fileHandler);
ipcMain.handle('mods', modsHandler);
createWindow();
});
Example #15
Source File: TXTResolvingController.electron.main.js From mymonero-android-js with BSD 3-Clause "New" or "Revised" License | 6 votes |
startObserving_ipc () {
const self = this
ipcMain.on(
'TXTRecords',
function (event, params) {
self._resolveJob(
event,
params.hostname,
params.uuid // use uuid as resolverUUID
)
}
)
ipcMain.on(
'TXTRecords-Abort',
function (event, params) {
self._abortJob(
event,
params.uuid
)
}
)
}
Example #16
Source File: index.js From desktop with GNU General Public License v3.0 | 5 votes |
ipcMain.handle('request-url', (event, url) => {
if (!allowedToAccessFiles.has(url)) {
throw new Error('Not allowed to access URL');
}
return requestURLAsArrayBuffer(url);
});
Example #17
Source File: index.js From TenantSite.Developer.Tools.UI with MIT License | 5 votes |
ipc = ipcMain
Example #18
Source File: background.js From dev-sidecar with Mozilla Public License 2.0 | 5 votes |
function createWindow (startHideWindow) {
// Create the browser window.
win = new BrowserWindow({
width: 900,
height: 750,
title: 'DevSidecar',
webPreferences: {
enableRemoteModule: true,
contextIsolation: false,
nativeWindowOpen: true, // ADD THIS
// preload: path.join(__dirname, 'preload.js'),
// Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
nodeIntegration: true// process.env.ELECTRON_NODE_INTEGRATION
},
show: !startHideWindow,
// eslint-disable-next-line no-undef
icon: path.join(__static, 'icon.png')
})
Menu.setApplicationMenu(null)
win.setMenu(null)
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
if (!process.env.IS_TEST) win.webContents.openDevTools()
} else {
createProtocol('app')
// Load the index.html when not in development
win.loadURL('app://./index.html')
}
if (startHideWindow) {
hideWin()
}
win.on('closed', async (e) => {
win = null
tray = null
})
ipcMain.on('close', async (event, message) => {
if (message.value === 1) {
quit()
} else {
hideWin()
}
})
win.on('close', (e) => {
if (forceClose) {
return
}
e.preventDefault()
if (isLinux()) {
quit(app)
return
}
const config = DevSidecar.api.config.get()
const closeStrategy = config.app.closeStrategy
if (closeStrategy === 0) {
// 提醒
win.webContents.send('close.showTip')
} else if (closeStrategy === 1) {
// 直接退出
quit()
} else if (closeStrategy === 2) {
// 隐藏窗口
hideWin()
}
})
win.on('session-end', async (e) => {
log.info('session-end', e)
await quit()
})
}
Example #19
Source File: electron-main.js From loa-details with GNU General Public License v3.0 | 5 votes |
ipcMain.on("window-to-main", (event, arg) => {
const ipcFunction =
ipcFunctions[arg.message] ||
(() => {
log.error("Unknown winodw-to-main message: " + arg.message);
});
ipcFunction(event, arg);
});
Example #20
Source File: background.js From linked with GNU General Public License v3.0 | 5 votes |
/*
* IPC MAIN COMMUNICATION
*/
ipcMain.handle('GET_STORAGE_VALUE', (event, key) => {
return global.storage.get(key)
})
Example #21
Source File: eve-application.js From EveReader with GNU Affero General Public License v3.0 | 5 votes |
initIpcMain() {
ipcMain.on("IPC::ASK-OPEN-FILE", () => {
this.dialog.askOpenFile();
});
}
Example #22
Source File: index.js From zengm-legacy with Apache License 2.0 | 5 votes |
createWindow = () => {
// Rewrite URLs to handle host-relative URLs, which begin with a slash.
protocol.registerBufferProtocol(scheme, (req, callback) => {
let reqUrl = url.parse(req.url);
let pathname = reqUrl.pathname;
if (pathname.endsWith('/')) pathname += 'index.html';
if (reqUrl.hostname === hostname) {
let filePath = path.normalize(pathname);
if (startsWith(filePath, prefixesStaticWithHtml)) {
filePath += '.html';
}
filePath = path.join(webroot, filePath);
fs.access(filePath, fs.constants.R_OK, (err) => {
if (err) {
console.error(err);
callback(404);
} else {
callback({
mimeType: mimeType(pathname), charset: 'UTF-8',
data: fs.readFileSync(filePath)
});
}
});
} else {
serveLocalMirror(reqUrl, callback);
}
}, (err) => {
if (err) console.error('ERROR: failed to register protocol', scheme);
});
protocol.registerServiceWorkerSchemes([scheme]);
// Create the browser window.
// https://electron.atom.io/docs/api/browser-window/
mainWindow = new BrowserWindow({
width: 1024, height: 768, backgroundColor: '#203C64',
center:true, fullscreen:false,
title: app.getName(),
webPreferences: {
nodeIntegration:false,
preload: path.join(__dirname, 'preload.js')
}
});
// and load the index.html of the app.
mainWindow.loadURL(`${scheme}://${hostname}/`);
// Open external URLs in the browser:
mainWindow.webContents.on('will-navigate', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
// Open the DevTools.
process.argv.some((arg) => {
if (arg === '--dev') {
mainWindow.webContents.openDevTools();
return true;
}
return false;
});
// Implement window.prompt() and window.confirm() which are used by ZenGM:
ipcMain.on('prompt', prompt);
ipcMain.on('prompt-response', promptResponse);
ipcMain.on('confirm', confirm);
ipcMain.on('confirm-response', confirmResponse);
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}
Example #23
Source File: ScratchDesktopTelemetry.js From clipcc-desktop with GNU Affero General Public License v3.0 | 5 votes |
ipcMain.on('projectWasCreated', (event, arg) => {
scratchDesktopTelemetrySingleton.projectWasCreated(arg);
});
Example #24
Source File: index.js From desktop with GNU General Public License v3.0 | 5 votes |
ipcMain.on('open-desktop-settings', () => {
createDesktopSettingsWindow();
});
Example #25
Source File: index.js From clipcc-desktop with GNU Affero General Public License v3.0 | 5 votes |
// IIFE
ipcMain.handle('get-initial-project-data', () => initialProjectDataPromise);
Example #26
Source File: index.js From NIM-Pools-Hub-Miner with GNU General Public License v3.0 | 5 votes |
ipcMain.on("getGlobalHashrate", async (event) => {
const globalHashrate = await getGlobalHashrate();
event.reply("getGlobalHashrateReply", globalHashrate);
});
Example #27
Source File: index.js From among-us-proxy with MIT License | 5 votes |
ipcMain.on(Close, event => {
close();
CurrentState = { code: 'none' };
event.reply(GetAppState, CurrentState);
});
Example #28
Source File: index.js From desktop with GNU General Public License v3.0 | 5 votes |
ipcMain.on('open-privacy-policy', () => {
createPrivacyWindow()
});
Example #29
Source File: index.js From clipcc-desktop with GNU Affero General Public License v3.0 | 5 votes |
ipcMain.handle('load-extension', (event, extension) => {
_windows.main.webContents.send('loadExtensionFromFile', {extension});
});