Skip to content

Commit 8c54775

Browse files
simonkaspersenzeke
authored andcommitted
Added notifications to the demo-application (electron#304)
* added notifications to the demo-application * fixed tests * fixed some minor details with syntax + moved section to native-ui * Fixed a issue with last commit * color now represent native-ui * well well well, .DS_Store, you made it in a repo again * Fixed some issues with last commit * .ds_store * fixed image-path
1 parent 550c34b commit 8c54775

File tree

7 files changed

+94
-2
lines changed

7 files changed

+94
-2
lines changed

assets/img/icons.svg

Lines changed: 3 additions & 0 deletions
Loading

assets/img/programming.png

5.32 KB
Loading

index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<link rel="import" href="sections/menus/menus.html">
1919
<link rel="import" href="sections/menus/shortcuts.html">
2020
<link rel="import" href="sections/native-ui/ex-links-file-manager.html">
21+
<link rel="import" href="sections/native-ui/notifications.html">
2122
<link rel="import" href="sections/native-ui/dialogs.html">
2223
<link rel="import" href="sections/native-ui/tray.html">
2324
<link rel="import" href="sections/communication/ipc.html">
@@ -58,6 +59,7 @@ <h5 class="nav-category">
5859
<svg class="nav-icon"><use xlink:href="assets/img/icons.svg#icon-native-ui"></use></svg>
5960
Native User Interface</h5>
6061
<button type="button" id="button-ex-links-file-manager" data-section="ex-links-file-manager" class="nav-button">Open <em>external links</em> or system <em>file manager</em></button>
62+
<button type="button" id="button-notifications" data-section="notifications" class="nav-button"> Notifications with and without custom <em>image</em></button>
6163
<button type="button" id="button-dialogs" data-section="dialogs" class="nav-button">Use system <em>dialogs</em></button>
6264
<button type="button" id="button-tray" data-section="tray" class="nav-button">Put your app in the <em>tray</em></button>
6365
</div>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const path = require('path')
2+
3+
const notification = {
4+
title: 'Notification with image',
5+
body: 'Short message plus a custom image',
6+
icon: path.join(__dirname, '../../../assets/img/programming.png')
7+
}
8+
const notificationButton = document.getElementById('advanced-noti')
9+
10+
notificationButton.addEventListener('click', function () {
11+
const myNotification = new window.Notification(notification.title, notification)
12+
13+
myNotification.onclick = () => {
14+
console.log('Notification clicked')
15+
}
16+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const notification = {
2+
title: 'Basic Notification',
3+
body: 'Short message part'
4+
}
5+
const notificationButton = document.getElementById('basic-noti')
6+
7+
notificationButton.addEventListener('click', function () {
8+
const myNotification = new window.Notification(notification.title, notification)
9+
10+
myNotification.onclick = () => {
11+
console.log('Notification clicked')
12+
}
13+
})

sections/native-ui/notifications.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<template class="task-template">
2+
<section id="notifications-section" class="section js-section u-category-native-ui">
3+
<header class="notifications">
4+
<div class="section-wrapper">
5+
<h1>
6+
<svg class="section-icon"><use xlink:href="assets/img/icons.svg#icon-notification"></use></svg>
7+
Desktop notifications
8+
</h1>
9+
<h3>The <code>notification</code> module in Electron allows you to add basic desktop notifications.</h3>
10+
11+
<p>Electron conveniently allows developers to send notifications with the <a href="https://notifications.spec.whatwg.org/">HTML5 Notification API</a>, using the currently running operating system’s native notification APIs to display it.</p>
12+
13+
<p><b>Note:</b> Since this is an HTML5 API it is only available in the renderer process.</p>
14+
15+
<p>Open the <a href="https://electron.atom.io/docs/all/#notifications-windows-linux-macos">full API documentation<span class="u-visible-to-screen-reader">(opens in new window)</span></a> in your browser.</p>
16+
</div>
17+
</header>
18+
19+
<div class="demo">
20+
<div class="demo-wrapper">
21+
<button id="basic-notification-demo-toggle" class="js-container-target demo-toggle-button">Basic notification
22+
<div class="demo-meta u-avoid-clicks">Supports: Win 7+, macOS, Linux (that supports libnotify)<span class="demo-meta-divider">|</span> Process: Renderer</div>
23+
</button>
24+
<div class="demo-box">
25+
<div class="demo-controls">
26+
<button class="demo-button" id="basic-noti">View demo</button>
27+
</div>
28+
<p>This demo demonstrates a basic notification. Text only.</p>
29+
<h5>Renderer Process</h5>
30+
<pre><code data-path="renderer-process/native-ui/notifications/basic-notification.js"></pre></code>
31+
</div>
32+
</div>
33+
</div>
34+
35+
<div class="demo">
36+
<div class="demo-wrapper">
37+
<button id="advanced-notification-demo-toggle" class="js-container-target demo-toggle-button">Notification with image
38+
<div class="demo-meta u-avoid-clicks">Supports: Win 7+, macOS, Linux (that supports libnotify) <span class="demo-meta-divider">|</span> Process: Renderer</div>
39+
</button>
40+
<div class="demo-box">
41+
<div class="demo-controls">
42+
<button class="demo-button" id="advanced-noti">View demo</button>
43+
</div>
44+
<p>This demo demonstrates a basic notification. Both text and a image</p>
45+
<h5>Renderer Process</h5>
46+
<pre><code data-path="renderer-process/native-ui/notifications/advanced-notification.js"></pre></code>
47+
</div>
48+
</div>
49+
</div>
50+
51+
<script type="text/javascript">
52+
require('./renderer-process/native-ui/notifications/basic-notification')
53+
require('./renderer-process/native-ui/notifications/advanced-notification')
54+
</script>
55+
56+
</section>
57+
</template>

test/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ describe('demo app', function () {
155155

156156
describe('when a demo title is clicked', function () {
157157
it('it expands the demo content', function () {
158-
let onlyFirstVisible = Array(28).fill(false)
158+
let onlyFirstVisible = Array(30).fill(false)
159159
onlyFirstVisible[0] = true
160160

161161
return app.client.dismissAboutPage()
@@ -169,7 +169,7 @@ describe('demo app', function () {
169169

170170
describe('when the app is restarted after use', function () {
171171
it('it launches at last visted section & demo', function () {
172-
let onlyFirstVisible = Array(28).fill(false)
172+
let onlyFirstVisible = Array(30).fill(false)
173173
onlyFirstVisible[0] = true
174174

175175
return app.client.waitForVisible('#windows-section')
@@ -189,6 +189,7 @@ describe('demo app', function () {
189189
.auditSectionAccessibility('menus')
190190
.auditSectionAccessibility('shortcuts')
191191
.auditSectionAccessibility('ex-links-file-manager')
192+
.auditSectionAccessibility('notifications')
192193
.auditSectionAccessibility('dialogs')
193194
.auditSectionAccessibility('tray')
194195
.auditSectionAccessibility('ipc')

0 commit comments

Comments
 (0)