Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
858f1bc
commit 2892d06
Showing
7 changed files
with
132 additions
and
77 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,6 @@ jspm_packages | |
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
samples/electron/dist | ||
samples/electron/node_modules |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "notifications", | ||
"version": "1.0.0", | ||
"author": { | ||
"name": "Felix Rieseberg", | ||
"email": "felix@felixrieseberg.com" | ||
}, | ||
"main": "main.js", | ||
"description": "A sample electron app for the electron-windows-notifications module", | ||
"dependencies": { | ||
"electron-windows-notifications": "1.0.0-beta.17" | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const path = require('path') | ||
const {remote} = require('electron') | ||
const ElectronWindowsNotifications = require('electron-windows-notifications'); | ||
|
||
const {ToastNotification, TileNotification, Template} = ElectronWindowsNotifications | ||
|
||
const iconPath = path.join(__dirname, '../images/bp.png') | ||
const appId = 'electron-windows-notifications-sample' | ||
const textNode = document.querySelector('#text') | ||
|
||
function sendNotification(evt) { | ||
let template | ||
let strings | ||
|
||
// set notification content accordingly | ||
if (evt.srcElement.id === 'basic') { | ||
template = new Template({ | ||
templateText: '<text>%s</text>' | ||
}) | ||
strings = ['Hi from Electron'] | ||
} else if (evt.srcElement.id === 'image') { | ||
template = new Template ({ | ||
templateText: '<text>%s</text>', | ||
templateImage: '<image id="1" src="%s"/><text>This is a simple image toast notification example</text>' | ||
}) | ||
strings = ['Hi from Electron', iconPath] | ||
} else if (evt.srcElement.id === 'actions') { | ||
template = new Template({ | ||
templateText: '<text>%s</text>', | ||
templateImage: '<image id="1" src="%s"/><text>This is a simple actions toast notification example</text>', | ||
templateActions: '<actions><action content="Confirm" arguments="confirm" /><action content="Cancel" arguments="cancel" /></actions>' | ||
}) | ||
strings = ['Hi from Electron', iconPath] | ||
} | ||
|
||
console.log(template.getXML()) | ||
|
||
// create the notification object | ||
let notification = new ToastNotification({ | ||
appId: process.windowsStore ? undefined : appId, | ||
template: template.getXML(), | ||
strings: strings | ||
}) | ||
|
||
// register to notification events | ||
notification.on('failed', () => textNode.innerHTML('Notification failed!')) | ||
notification.on('dismissed', () => textNode.innerHTML('Notification dismissed!')) | ||
|
||
// information about the chosen action is provided inside the "arguments" object | ||
notification.on('activated', (t, e) => textNode.innerHTML(`You've clicked ${e.arguments}!`)) | ||
|
||
// show notification | ||
notification.show() | ||
} | ||
|
||
function sendTile() { | ||
let template = ` | ||
<tile> | ||
<visual> | ||
<binding template="TileSmall"> | ||
<text>Small</text> | ||
</binding> | ||
<binding template="TileMedium"> | ||
<text>Medium</text> | ||
</binding> | ||
<binding template="TileWide"> | ||
<text>Wide</text> | ||
</binding> | ||
<binding template="TileLarge"> | ||
<text>Large</text> | ||
</binding> | ||
</visual> | ||
</tile>`.replace(/\>\s+\</g, '><') | ||
|
||
let tile = new TileNotification({template}) | ||
tile.show(); | ||
} | ||
|
||
ElectronWindowsNotifications.setLogger(console.log) | ||
remote.getCurrentWebContents().toggleDevTools() | ||
|
||
document.addEventListener('DOMContentLoaded', function() { | ||
document.getElementById('basic').addEventListener('click', sendNotification); | ||
document.getElementById('image').addEventListener('click', sendNotification); | ||
document.getElementById('actions').addEventListener('click', sendNotification); | ||
document.getElementById('tile').addEventListener('click', sendTile); | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
{ | ||
"name": "notification-demo", | ||
"name": "notifications", | ||
"version": "1.1.0", | ||
"main": "main.js", | ||
"main": "app/main.js", | ||
"author": { | ||
"name": "Felix Rieseberg", | ||
"email": "felix@felixrieseberg.com" | ||
}, | ||
"description": "A sample electron app for the electron-windows-notifications module", | ||
"devDependencies": { | ||
"electron-prebuilt": "^1.2.0", | ||
"electron-rebuild": "^1.2.1" | ||
}, | ||
"dependencies": { | ||
"electron-windows-notifications": "^0.4.1" | ||
"electron-rebuild": "^1.2.1", | ||
"electron-builder": "^7.11.4" | ||
}, | ||
"scripts": { | ||
"start": "electron ." | ||
"start": "electron .", | ||
"pack": "build --dir --win", | ||
"dist": "build --win" | ||
}, | ||
"build": { | ||
"appId": "com.electron.sample", | ||
"asar": false | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.