Skip to content

Commit

Permalink
feature: allow users to select update time
Browse files Browse the repository at this point in the history
  • Loading branch information
dubisdev committed May 3, 2021
1 parent 0ec114d commit 089e7e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ let settings = {
defaultValue: "",
description: "Your Todoist api Token",
},
"Today tasks update delay": {
type: "number",
defaultValue: 30,
description:
"Seconds between each update of today's tasks (less time, more processing)",
},
};
// ----------------- END Plugin settings --------------------- //

Expand Down
13 changes: 10 additions & 3 deletions src/plugin-structure/initialize.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import TDSClient from "todoist-rest-client";
import fs from "fs";
import path from "path";
var dir = path.join(process.env.APPDATA, "Cerebro", "config.json");

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 getUserUpdateTime() {
let text = fs.readFileSync(dir);
let json = JSON.parse(text);
return parseInt(
json["plugins"]["cerebro-todoist"]["Today tasks update delay"]
);
}

function init(done) {
let apitoken = getApiToken();
if (!apitoken) {
Expand All @@ -25,7 +32,7 @@ function init(done) {
info: info,
errorExists: false,
};
setTimeout(() => init(done), NO_ERROR_INTERVAL);
setTimeout(() => init(done), getUserUpdateTime() * 1000);
return obj;
})
.then((done) => done)
Expand Down

0 comments on commit 089e7e7

Please sign in to comment.