Last active
March 26, 2016 16:25
-
-
Save KimuraTakaumi/9f184167f321d8f618ec to your computer and use it in GitHub Desktop.
Electronでプロセス間通信(ipc) MainProcessからRendererProcessへ非同期通信
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello World!</title> | |
<script type="text/javascript"> | |
var ipc = require('ipc'); | |
// 非同期でメインプロセスからのメッセージを受信する | |
ipc.on('main-process-message', function(args) { | |
console.log("main process message : " + args); | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
<button onclick="asynchronousMessage()">asynchronousMessage</button> | |
<button onclick="synchronousMessage()">synchronousMessage</button> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const electron = require('electron'); | |
const app = electron.app; | |
var ipc = require('ipc'); | |
var Tray = require('tray'); | |
var Menu = require('menu'); | |
var appIcon = null; | |
app.on('ready', function () { | |
createWindow(); | |
appIcon = new Tray(__dirname + '/img/icon.png'); | |
var array = []; | |
var item = {}; | |
item["label"] = "asynchronous"; | |
item["click"] = function () { | |
// 非同期でレンダラープロセスへメッセージを送信する | |
mainWindow.webContents.send('main-process-message', 'main process send message.'); | |
}; | |
array.push(item); | |
var contextMenu = Menu.buildFromTemplate(array); | |
appIcon.setContextMenu(contextMenu); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment