Skip to content

Commit

Permalink
Add reminders and notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
piascikj committed Mar 15, 2018
1 parent cda7233 commit 60e2670
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .imdone/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
},
{
"name": "TODO",
"hidden": true
"hidden": false
},
{
"name": "DOING",
"hidden": false
},
{
"name": "CHANGED",
"hidden": false
"hidden": true
},
{
"name": "NOTE",
Expand Down
67 changes: 67 additions & 0 deletions lib/services/reminders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const notifyer = require('node-notifier')
const path = require('path')
const moment = require('moment')
const Task = require('imdone-core/lib/task')
const notifier = require('node-notifier')
const PackageManager = require('atom').PackageManager
const remote = require('electron').remote

class Reminders {
constructor(repo) {
this.repo = repo
this.listen()
// notifier.on('click', function(notifierObject, options) {
// debugger
// // Triggers if `wait: true` and user clicks notification
// });
//
// notifier.on('timeout', function(notifierObject, options) {
// debugger
// // Triggers if `wait: true` and notification closes
// });
}

destory() {
clearInterval(this.interval)
}

listen() {
const repo = this.repo
this.interval = setInterval(() => {
repo.getTasks().forEach(task => {
if (!task.meta.remind) return
const reminder = moment(task.meta.remind[0])
if (reminder.diff(moment()) > 0) return
this.notify(task)
})
}, 20000)
}

// DOING: Show imdone logo in notifications. remind:2018-03-15T02:05:05-04:00
notify(task) {
notifier.notify(
{
title: 'imdone reminder',
message: task.text,
// icon: path.join(__dirname, 'coulson.jpg'), // Absolute path (doesn't work on balloons)
sound: 'Tink', // Only Notification Center or Windows Toasters
// wait: true, // Wait with callback, until user action is taken against notification
sticky: true,
actions: 'Show'
},
(err, response, metadata) => {
remote.getCurrentWindow().show()
const filePath = this.repo.getFullPath(task.source.path)
atom.workspace.open(filePath, {split: 'left'}).then( () => {
const textEditor = atom.workspace.getActiveTextEditor()
const position = [task.line-1, 0]
textEditor.setCursorBufferPosition(position, {autoscroll: false})
textEditor.scrollToCursorPosition({center: true})
})
// Response is response from notification
}
)
}
}

module.exports = Reminders
8 changes: 7 additions & 1 deletion lib/services/worker-watched-fs-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var fs = require('fs'),
File = require('imdone-core/lib/file'),
constants = require('imdone-core/lib/constants'),
path = require('path'),
Reminders = require('./reminders'),
config = require('./imdone-config');

var workerPath = path.join(config.getPackagePath(), 'lib', 'services', 'worker.js')
Expand All @@ -27,17 +28,20 @@ function mixin(repo, fs) {
if (repo.paused) return
emitter.emit(event, data)
})

var _init = repo.init;
repo.init = function(cb) {
_init.call(repo, function(err, files) {
repo.initWatcher();
repo.reminders = new Reminders(repo);
if (cb) cb(err, files);
});
};

var _destroy = repo.destroy;
repo.destroy = function() {
repo.worker.send({event: 'destroyWatcher'})
repo.reminders.destory();
_destroy.apply(repo);
};

Expand All @@ -54,6 +58,7 @@ function mixin(repo, fs) {
emitter.once('refresh', function() {
// console.log('received refresh')
_refresh.call(repo, function(err, files) {
repo.reminders.listen();
repo.initWatcher();
refreshing = false
if (cb) cb(err, files);
Expand Down Expand Up @@ -114,7 +119,8 @@ function mixin(repo, fs) {
repo.emitFileUpdate(file);
},
unlinkDir: function(path) {log('Directory', path, 'has been removed');},
error: function(error) {log('Error while watching files:', error);}
error: function(error) {log('Error while watching files:', error);},
reminders: (tasks) => tasks.forEach(task => repo.reminders.notify(task))
}
repo.initWatcher = function() {
log("Creating a new watcher");
Expand Down
3 changes: 3 additions & 0 deletions lib/views/imdone-atom-view.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{$, $$, $$$, ScrollView} = require 'atom-space-pen-views'
$el = require 'laconic'
moment = require 'moment'
{Emitter} = require 'atom'
fs = require 'fs'
MenuView = null
Expand Down Expand Up @@ -511,6 +512,8 @@ class ImdoneAtomView extends ScrollView

for data in task.getMetaDataWithLinks(repo.getConfig())
do (data) =>
if (data.key == 'due' || data.key == 'remind')
data.value = moment(data.value).fromNow()
$icons = $el.td()
if data.link
$link = $el.a href: data.link.url, title: data.link.title,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"mkdirp": "^0.5.1",
"moment": "^2.21.0",
"nedb": "^1.8.0",
"node-notifier": "^5.2.1",
"pusher-js": "^3.0.0",
"regex-parser": "^2.2.9",
"sortablejs": "1.7.0",
Expand Down

0 comments on commit 60e2670

Please sign in to comment.