Skip to content

Instantly share code, notes, and snippets.

@javan
Created April 8, 2016 18:26
Show Gist options
  • Save javan/4dd6990cf7756cdff81eca62896bbb98 to your computer and use it in GitHub Desktop.
Save javan/4dd6990cf7756cdff81eca62896bbb98 to your computer and use it in GitHub Desktop.
Sample Electron app Windows 10 notification issue: https://github.com/electron/electron/issues/4973
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<ul>
<li>appUserModelId: "<script>document.write(require("electron").remote.getGlobal("appUserModelId"))</script>"</li>
<li>Electron version: <script>document.write(process.versions.electron)</script></li>
</ul>
<p><button id="notifier">Display Notification</button></p>
<script>
document.getElementById("notifier").addEventListener("click", function(event) {
var notification = new Notification("It", { body: "works!" })
console.log("Created Notification:", notification)
})
</script>
</body>
</html>
'use strict';
const path = require('path');
const electron = require('electron');
const app = electron.app;
function setAppUserModelId() {
var updateDotExe = path.join(path.dirname(process.execPath), '..', 'update.exe');
var packageDir = path.dirname(path.resolve(updateDotExe));
var packageName = path.basename(packageDir);
var exeName = path.basename(process.execPath).replace(/\.exe$/i, '');
global.appUserModelId = `com.squirrel.${exeName}`;
app.setAppUserModelId(global.appUserModelId);
}
// Uncomment to set user model ID. Notifications will stop working.
// setAppUserModelId();
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/index.html');
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// 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;
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
}
});
{
"name": "electron-quick-start",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
"scripts": {
"start": "electron main.js"
},
"devDependencies": {
"electron-prebuilt": "0.37.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment