Skip to content

Instantly share code, notes, and snippets.

@KimuraTakaumi
Last active April 3, 2016 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KimuraTakaumi/64c492e79490b69c6ff6dc9332e88e10 to your computer and use it in GitHub Desktop.
Save KimuraTakaumi/64c492e79490b69c6ff6dc9332e88e10 to your computer and use it in GitHub Desktop.
ElectronでNotificationを表示する(メインプロセス)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<script type="text/javascript">
var main = require("remote").require("./main");
function notificationMainProcess() {
main.notificationMainProcess();
}
</script>
</head>
<body>
<h1>Hello World!</h1>
<button onclick="notificationMainProcess()">notification main process</button>
</body>
</html>
'use strict';
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
var mainWindow;
const notifier = require('node-notifier');
function createWindow() {
mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.loadURL('file://' + __dirname + '/index.html');
// Open the DevTools.
// mainWindow.webContents.openDevTools();
mainWindow.on('closed', function () {
mainWindow = null;
});
}
app.on('ready', function () {
createWindow();
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
exports.notificationMainProcess = function () {
notifier.notify({
title: 'Notification Main Process',
message: 'Nofitificaiton Main Process Message',
icon: 'file://' + __dirname + '/img/icon.png',
sound: true,
wait: true,
contentImage: 'file://' + __dirname + '/img/icon.png'
}, function (err, response) {
console.log(response);
});
notifier.on('click', function (notifierObject, options) {
console.log('notification click');
});
notifier.on('timeout', function (notifierObject, options) {
console.log('notification timeout');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment