1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Electron: Trigger notifications using node-notifier

This commit is contained in:
Laurent Cozic 2017-11-28 18:47:41 +00:00
parent 033d356b56
commit 18dc6c826a
5 changed files with 60 additions and 7 deletions

View File

@ -274,7 +274,7 @@ class Application extends BaseApplication {
}, {
label: _('About Joplin'),
click: () => {
const p = require('./package.json');
const p = this.packageInfo();
let message = [
p.description,
'',
@ -308,10 +308,16 @@ class Application extends BaseApplication {
this.lastMenuScreen_ = screen;
}
packageInfo() {
if (this.packageInfo_) return this.packageInfo_;
this.packageInfo_ = require('./package.json');
return this.packageInfo_;
}
async start(argv) {
argv = await super.start(argv);
AlarmService.setDriver(new AlarmServiceDriverNode());
AlarmService.setDriver(new AlarmServiceDriverNode({ appName: this.packageInfo().build.appId }));
AlarmService.setLogger(reg.logger());
if (Setting.value('openDevTools')) {

View File

@ -2114,6 +2114,11 @@
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg="
},
"growly": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz",
"integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE="
},
"har-schema": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
@ -2507,8 +2512,7 @@
"isexe": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
"dev": true
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA="
},
"isobject": {
"version": "2.1.0",
@ -2993,6 +2997,17 @@
"is-stream": "1.1.0"
}
},
"node-notifier": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-5.1.2.tgz",
"integrity": "sha1-L6nhJgX6EACdRFSdb82KY93g5P8=",
"requires": {
"growly": "1.3.0",
"semver": "5.4.1",
"shellwords": "0.1.1",
"which": "1.3.0"
}
},
"noop-logger": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz",
@ -3893,6 +3908,11 @@
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=",
"dev": true
},
"shellwords": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz",
"integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww=="
},
"signal-exit": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
@ -5201,7 +5221,6 @@
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz",
"integrity": "sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==",
"dev": true,
"requires": {
"isexe": "2.0.0"
}

View File

@ -64,6 +64,7 @@
"mime": "^2.0.3",
"moment": "^2.19.1",
"node-fetch": "^1.7.3",
"node-notifier": "^5.1.2",
"promise": "^8.0.1",
"query-string": "^5.0.1",
"react": "^16.0.0",

View File

@ -85,6 +85,20 @@ On the **terminal application**, to initiate the synchronisation process, type `
Any kind of file can be attached to a note. In Markdown, links to these files are represented as a simple ID to the resource. In the note viewer, these files, if they are images, will be displayed or, if they are other files (PDF, text files, etc.) they will be displayed as links. Clicking on this link will open the file in the default application.
# Notifications
On the desktop and mobile apps, an alarm can be associated with any to-do. It will be triggered at the given time by displaying a notification. How the notification will be displayed depends on the operating system since each has a different way to handle this. Please see below for the requirements for the desktop applications:
- **Windows**: >= 8. Make sure the Action Center is enabled on Windows. Task bar balloon for Windows < 8. Growl as fallback. Growl takes precedence over Windows balloons.
- **macOS**: >= 10.8 or Growl if earlier.
- **Linux**: `notify-osd` or `libnotify-bin` installed (Ubuntu should have this by default). Growl otherwise
See [documentation and flow chart for reporter choice](./DECISION_FLOW.md)
On mobile, the alarms will be displayed using the built-in notification system.
If for any reason the notifications do not work, please [open an issue](https://github.com/laurent22/joplin/issues).
# Localisation
Joplin is currently available in English and French. If you would like to contribute a translation, it is quite straightforward, please follow these steps:

View File

@ -1,6 +1,11 @@
const notifier = require('node-notifier');
class AlarmServiceDriverNode {
constructor() {
constructor(options) {
// Note: appName is required to get the notification to work. It must be the same as the appId defined in package.json
// https://github.com/mikaelbr/node-notifier/issues/144#issuecomment-319324058
this.appName_ = options.appName;
this.notifications_ = {};
}
@ -24,9 +29,17 @@ class AlarmServiceDriverNode {
if (interval < 0) return;
const timeoutId = setTimeout(() => {
console.info('NOTIFICATION: ', notification);
const o = {
appName: this.appName_,
title: notification.title,
};
if ('body' in notification) o.message = notification.body;
notifier.notify(o);
this.clearNotification(notification.id);
}, interval);
this.notifications_[notification.id] = Object.assign({}, notification);
this.notifications_[notification.id].timeoutId = timeoutId;
}
}