Skip to content

Commit

Permalink
📚 Update Sample
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrieseberg committed Oct 12, 2016
1 parent 858f1bc commit 2892d06
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 77 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -35,3 +35,6 @@ jspm_packages

# Optional REPL history
.node_repl_history

samples/electron/dist
samples/electron/node_modules
File renamed without changes.
13 changes: 13 additions & 0 deletions samples/electron/app/package.json
@@ -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"
}
}
20 changes: 14 additions & 6 deletions samples/electron/window.html → samples/electron/app/window.html
Expand Up @@ -5,25 +5,33 @@
</head>
<body>
<h1>electron-windows-notifications Sample</h1>
<p>This sample demonstrates the use of the electron-windows-notifications module.
<p>This sample demonstrates the use of the electron-windows-notifications module.
Use the button below to create various different notifications.
Demo is based on this great sample:
<a href="https://github.com/hokein/electron-sample-apps/tree/master/notifications">https://github.com/hokein/electron-sample-apps/tree/master/notifications</a></p>
Demo is based on this great sample:
<a href="https://github.com/hokein/electron-sample-apps/tree/master/notifications">https://github.com/hokein/electron-sample-apps/tree/master/notifications</a>
</p>
<div class="sample">
<button id="basic">Basic Notification</button>
<span>Basic notification: title only. </span>
<span>Basic notification: title only.</span>
</div>
<br/>
<div class="sample">
<button id="image">Image Notification</button>
<span>Image notification: title, text & image. </span>
<span>Image notification: title, text & image.</span>
</div>
<br/>
<div class="sample">
<button id="actions">Actions Notification</button>
<span>Actions notification: text, image and action buttons </span>
<span>Actions notification: text, image and action buttons.</span>
</div>
<br/>
<div class="sample">
<button id="tile">Tile Notification</button>
<span>Tile notification: update the app's tile.</span>
</div>
<br/>


<div id="text"></div>

<script src="https://code.jquery.com/jquery-2.1.4.min.js" onload="window.$ = window.jQuery = module.exports;"></script>
Expand Down
87 changes: 87 additions & 0 deletions samples/electron/app/window.js
@@ -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);
})
22 changes: 15 additions & 7 deletions samples/electron/package.json
@@ -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
}
}
64 changes: 0 additions & 64 deletions samples/electron/window.js

This file was deleted.

0 comments on commit 2892d06

Please sign in to comment.