Skip to content

Commit

Permalink
feat: added notification system. Closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Мурат Атила authored and Мурат Атила committed Jul 10, 2023
1 parent 8a611b7 commit 8553441
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{
"view": "infocus.todoist.TreeView",
"contents": "Data is loading, be patience.\n ------ \n Click refresh in toolbar to resync.",
"when": "!!config.infocus.todoist.token"
"when": "config.infocus.todoist.token"
},
{
"view": "infocus.todoist.TreeView",
Expand Down Expand Up @@ -287,6 +287,23 @@
"configuration": {
"title": "InFocus",
"properties": {
"infocus.todoist.notifications": {
"type": "string",
"enum": [
"all",
"missed",
"todays",
"disabled"
],
"enumDescriptions": [
"All reminder notifications will be shown",
"Only missed tasks will shown in notifications",
"Only todays dedline tasks will shown in notifications",
"All reminder notifications disabled"
],
"default": "all",
"description": "Notifications mode"
},
"infocus.todoist.token": {
"type": "string",
"description": "Your todoist API token. See https://todoist.com/app/settings/integrations"
Expand Down
25 changes: 19 additions & 6 deletions src/features/todoist/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { withAsyncProgress } from "../../lib/withAsyncProgress";
import { SectionItem } from "./providers/SectionItem";
import { Task } from './entities';
import { DueDate } from 'todoist/dist/v9-types';
import { SettingsHelper } from '../../lib/settingsHelper';

export function registerTodoistCommands(context: ExtensionContext) {
context.subscriptions.push(
Expand Down Expand Up @@ -277,18 +278,30 @@ function tasksDateObserver() {
// @ts-ignore
schedule.gracefulShutdown();

const notificationType = SettingsHelper.getReminderNotificationsMode();
const allAndMissedNotifications: (typeof notificationType)[] = ['all', 'missed'];
const allAndTodayNotifications: (typeof notificationType)[] = ['all', 'todays'];

if (notificationType === 'disabled') {
return;
}

if (tasks.length) {
tasks.forEach(async (task) => {
if (task?.due?.date && !task.checked) {
const taskDate = new Date(task.due.date);

if (!notifiedTasks[task.id]) {
if (isToday(taskDate)) {
schedule.scheduleJob(taskDate, async () => {
showMessageWithSheduleAction(task, `Task due now: ${task.content}`);
});
} else if (isPast(taskDate)) {
showMessageWithSheduleAction(task, `You missed due date. Task: ${task.content}`);
if (isPast(taskDate)) {
if (allAndMissedNotifications.includes(notificationType)) {
showMessageWithSheduleAction(task, `You missed due date. Task: ${task.content}`);
}
} else if (isToday(taskDate)) {
if (allAndTodayNotifications.includes(notificationType)) {
schedule.scheduleJob(taskDate, async () => {
showMessageWithSheduleAction(task, `Today's Deadline: ${task.content}`);
});
}
}

notifiedTasks[task.id] = true;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/settingsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ export class SettingsHelper {
static isCodeLensEnabled(): boolean {
return workspace.getConfiguration(ExtensionName).get('todoist.enableCodeLens', true);
}

static getReminderNotificationsMode(): 'all' | 'missed' | 'todays' | 'disabled' {
return workspace.getConfiguration(ExtensionName).get('todoist.notification', 'all');
}
}

0 comments on commit 8553441

Please sign in to comment.