1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-13 00:10:37 +02:00
Files
Assets
CliClient
CliClientDemo
ElectronClient
ReactNativeClient
android
ios
lib
components
images
models
services
AlarmService.js
AlarmServiceDriver.android.js
AlarmServiceDriver.ios.js
AlarmServiceDriverNode.js
BaseService.js
DecryptionWorker.js
EncryptionService.js
EncryptionServiceDriverNode.js
EncryptionServiceDriverRN.js
InteropService.js
InteropService_Exporter_Base.js
InteropService_Exporter_Jex.js
InteropService_Exporter_Raw.js
InteropService_Importer_Base.js
InteropService_Importer_Enex.js
InteropService_Importer_Jex.js
InteropService_Importer_Md.js
InteropService_Importer_Raw.js
NavService.js
ResourceService.js
back-button.js
report.js
vendor
ArrayUtils.js
BaseApplication.js
BaseModel.js
BaseSyncTarget.js
Cache.js
DropboxApi.js
EventDispatcher.js
JoplinError.js
MdToHtml.js
MdToHtml_Katex.js
ModelCache.js
ObjectUtils.js
SyncTargetDropbox.js
SyncTargetFilesystem.js
SyncTargetMemory.js
SyncTargetNextcloud.js
SyncTargetOneDrive.js
SyncTargetOneDriveDev.js
SyncTargetRegistry.js
SyncTargetWebDAV.js
WebDavApi.js
database-driver-node.js
database-driver-react-native.js
database.js
dialogs.js
file-api-driver-dropbox.js
file-api-driver-local.js
file-api-driver-memory.js
file-api-driver-onedrive.js
file-api-driver-webdav.js
file-api.js
folders-screen-utils.js
fs-driver-base.js
fs-driver-dummy.js
fs-driver-node.js
fs-driver-rn.js
geolocation-node.js
geolocation-react.js
import-enex-md-gen.js
import-enex.js
joplin-database.js
layout-utils.js
locale.js
logger.js
markdown-utils.js
mime-utils.js
net-utils.js
onedrive-api.js
package.json
parameters.js
parseUri.js
path-utils.js
poor-man-intervals.js
promise-utils.js
react-logger.js
reducer.js
registry.js
shim-init-node.js
shim-init-react.js
shim.js
string-utils.js
synchronizer.js
time-utils.js
urlUtils.js
uuid.js
locales
.babelrc
.buckconfig
.flowconfig
.gitattributes
.gitignore
.watchmanconfig
app.json
build_android.bat
build_android_prod.bat
clean_build.bat
debug_log.bat
debug_log.sh
index.android.js
index.ios.js
index.js
main.js
package-lock.json
package.json
root.js
start_emulator.bat
start_server.bat
start_server.sh
Tools
docs
readme
.gitignore
.travis.yml
BUILD.md
CONTRIBUTING.md
LICENSE
README.md
_config.yml
appveyor.yml
joplin.sublime-project
linkToLocal.sh
joplin/ReactNativeClient/lib/services/AlarmServiceDriverNode.js
2017-11-28 18:47:41 +00:00

47 lines
1.2 KiB
JavaScript

const notifier = require('node-notifier');
class AlarmServiceDriverNode {
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_ = {};
}
hasPersistentNotifications() {
return false;
}
notificationIsSet(id) {
return id in this.notifications_;
}
async clearNotification(id) {
if (!this.notificationIsSet(id)) return;
clearTimeout(this.notifications_[id].timeoutId);
delete this.notifications_[id];
}
async scheduleNotification(notification) {
const now = Date.now();
const interval = notification.date.getTime() - now;
if (interval < 0) return;
const timeoutId = setTimeout(() => {
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;
}
}
module.exports = AlarmServiceDriverNode;