DEV Community

Cover image for Vs Code Extension
Ganesh Raja
Ganesh Raja

Posted on • Edited on

Vs Code Extension

Today I spent time updating the code from JS file to Class Format. The update is partially done. I will be continuing this tomorrow. You can check full code in Repo as well.

const vscode = require("vscode");

const pomodo = class Pomodoro {
  constructor(context) {
    this.vsCodeStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment["Right"], 10);
    this.context = context;
  }
  startPomodoTimer() {
    this.vsCodeStatusBar.text = "Pomodo Started";
    this.vsCodeStatusBar.show();
    this.startWorkTimer();
  }
  appendZero() {
    this.num <= 9 ? "0" + this.num : this.num;
  }

  updateStatusBar(min, sec, icon) {}

  timer(countDownTime, callEverySecond = null, counterisDone = null, icon = null) {
    let countDownTimer = countDownTime;
    let that = this;
    let timerId = setInterval(function () {
      countDownTimer -= 1000;
      let min = Math.floor(countDownTimer / (60 * 1000));
      let sec = Math.floor((countDownTimer - min * 60 * 1000) / 1000);

      if (countDownTimer <= 0) {
        clearInterval(timerId);
        if (counterisDone) counterisDone();
      } else {
        that.vsCodeStatusBar.text = icon + " " + this.appendZero(min) + " : " + this.appendZero(sec);
      }
    }, 1000);
  }

  startWorkTimer() {
    const pomodoCountDown = 5 * 60 * 1000;
    const tomatodIcon = "🍅";
    this.timer(pomodoCountDown, this.updateStatusBar, this.startRestTimer, tomatodIcon);
  }

  pomodoDone() {
    this.vsCodeStatusBar.text = "Pomodo Done!!!";
  }

  startRestTimer() {
    const restCountDown = 1 * 60 * 100;
    const restIcon = "🌴";
    this.timer(restCountDown, this.updateStatusBar, this.pomodoDone, restIcon);
  }
};
exports.pomodo = pomodo;

Enter fullscreen mode Exit fullscreen mode

Top comments (0)