Plugin: Pomodoro timer

name

Pomodoro Timer

description

Starts a configurable number of work-break cycles. Use the settings page to configure the length of the work and break timers.

instructions

Use {Start timer} to invoke this plugin, after configuring the length of the work and break timers.

The plugin will first prompt for how many cycles you want to work for.

icon

timer-outline

setting

Work timer (minutes)

setting

Break timer (minutes)

{
insertText: {
"Start": async function(app) {
let cycle_count = await app.prompt("How many cycles are you working?");
if (!this._isStringAnInteger(cycle_count)) {
app.alert("Not an integer number of cycles.");
return null;
}
cycle_count = parseInt(cycle_count);
 
for (let i = 0; i < cycle_count; i++) {
await this.showAlertAfterWait(app, app.settings["Work timer (minutes)"], "Take a break.");
await this.showAlertAfterWait(app, app.settings["Break timer (minutes)"], `${i + 1}/${cycle_count} cycles done.`);
}
return `Completed ${cycle_count} cycles!`;
},
},
 
_isStringAnInteger(str) {
const integerRegex = /^\d+$/;
return integerRegex.test(str);
},
 
_wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
},
 
async showAlertAfterWait(app, timer, text) {
await this._wait(1 * 1000 * 10);
await app.prompt(text);
}
}