-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
61 lines (46 loc) · 1.95 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const vscode = require('vscode');
const fetch = require('superagent');
const convertTime = require('./utils/convert-time');
const URL = 'http://be-human-demo.herokuapp.com';
/**
* @param {vscode.ExtensionContext} context
*/
const activate = async (context) => {
const oneMinute = (1000 * 60)
const timeInterval = Number(vscode.workspace.getConfiguration("be-human").get("timeInterval"))
const userTimeInterval = (oneMinute * timeInterval);
let startTime = Date.now();
let intervalId = null;
async function intervalIdFunction(){
intervalId = await setInterval(async() => {
const lapTime = Date.now();
const incrementOfTime = Math.round((lapTime - startTime) / 60000);
const convertedTime = convertTime(incrementOfTime);
const randomTip = await fetch.get(`${URL}/api/v1/tips/random`);
const userChoice = await vscode.window.showInformationMessage(`You have been working for ${convertedTime}. Quick tip: ${randomTip.body.tip} Have time for a short break?`, 'Move your body', 'Not this time');
if (userChoice === 'Move your body') {
const randomLink = await fetch.get(`${URL}/api/v1/links/random`)
vscode.env.openExternal(vscode.Uri.parse(`${randomLink.body.url}`));
}
}, userTimeInterval)
}
const response = await vscode.window.showInformationMessage('Welcome to beHuman! Would you like to be reminded to take breaks today?', 'Yes', 'No');
if(response === 'Yes') {
vscode.window.showInformationMessage('Have a great day!');
intervalId = intervalIdFunction();
} else if(response === 'No'){
vscode.window.showInformationMessage('Let\'s try again tomorrow!');
}
let resetTimer = vscode.commands.registerCommand('be-human.resetTime', function () {
clearInterval(intervalId);
startTime = Date.now();
vscode.window.showInformationMessage('You have reset your time.');
intervalId = intervalIdFunction();
});
context.subscriptions.push(resetTimer);
}
function deactivate() {}
module.exports = {
activate,
deactivate
}