Skip to content

Commit

Permalink
added error warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dubisdev committed May 3, 2021
1 parent 6cbff8e commit 0c20c3c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 17 deletions.
12 changes: 9 additions & 3 deletions src/core-engine/apiConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ class apiInterface {

createTask({ text = "" } = {}) {
let task = getSubCommandText(text);
this.Client.create(

return this.Client.create(
{ type: "task" },
new Task({ content: task, due_string: "today", due_lang: "en" })
);
return new Notification("Task Created");
).then((res) => {
if (res === true) {
return new Notification("Task Created");
} else {
return new Notification("Task couldn't be created");
}
});
}
}

Expand Down
22 changes: 20 additions & 2 deletions src/plugin-structure/DisplayGetter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@ import icon from "../icons";
import apiInterface from "../core-engine/apiConnect";

export default class DisplayGetter {
constructor({ apiToken }) {
this.myInterface = new apiInterface({ apiToken });
constructor({ apiToken, noToken }) {
if (noToken) {
this.noToken = noToken;
} else {
this.myInterface = new apiInterface({ apiToken });
}
}

get({ action, getPreview, term }) {
if (this.noToken) {
return {
term: `tds ${action.toLowerCase()}`,
icon: icon,
title: `Todoist Workflow ${action}`,
getPreview: () => (
<h4>
No token found or incorrect token. Please go to `plugins todoist`
settings. Then restart the app.
</h4>
),
};
}

return {
term: `tds ${action.toLowerCase()}`,
icon: icon,
Expand Down
49 changes: 37 additions & 12 deletions src/plugin-structure/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,45 @@ import TDSClient from "todoist-rest-client";
import fs from "fs";
import path from "path";

const INTERVAL = 1 * 60 * 1000;
var dir = path.join(process.env.APPDATA, "Cerebro", "config.json");
let text = fs.readFileSync(dir);
let json = JSON.parse(text);
let apitoken = json["plugins"]["cerebro-todoist"]["token"];
const NO_ERROR_INTERVAL = 30 * 1000;
const ERROR_INTERVAL = 10 * 60 * 1000;

function getApiToken() {
var dir = path.join(process.env.APPDATA, "Cerebro", "config.json");
let text = fs.readFileSync(dir);
let json = JSON.parse(text);
return json["plugins"]["cerebro-todoist"]["token"];
}

function init(done) {
const update = () => {
//get today tasks
const cliente = new TDSClient(apitoken);
cliente.getTodayTasks().then(done);
setTimeout(update, INTERVAL);
};
update();
let apitoken = getApiToken();
if (!apitoken) {
return;
}
const cliente = new TDSClient(apitoken);
cliente
.getTodayTasks()
.then((info) => {
var obj = {
info: info,
errorExists: false,
};
setTimeout(() => init(done), NO_ERROR_INTERVAL);
return obj;
})
.then((done) => done)
.catch(() => {
new Notification(
"Please check the token in the cerebro-todoist settings."
);
setTimeout(() => init(done), ERROR_INTERVAL);
var obj = {
info: [""],
errorExists: true,
};
return obj;
})
.then(done);
}

export default init;

0 comments on commit 0c20c3c

Please sign in to comment.