Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic "reminders" functionality for when extension starts (#184) #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@
"message": "Schedule the first Pomodoro of the day to automatically start at the specified time.",
"description": "Autostart setting description. Shown on the settings page."
},
"reminders_title": {
"message": "Reminders",
"description": "Reminders section header. Shown on the settings page."
},
"reminders_description": {
"message": "Reminders to start a new cycle.",
"description": "Reminders section description. Shown on the settings page."
},
"reminder_on_start": {
"message": "When Chrome starts:",
"description": "Reminder options for when Chrome starts. Shown on the settings page."
},
"time": {
"message": "Time:",
"description": "Time input label. Shown on the settings page."
Expand Down
12 changes: 12 additions & 0 deletions src/_locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@
"message": "Intervalo Longo",
"description": "Long Break section header. Shown on the settings page."
},
"reminders_title": {
"message": "Lembretes",
"description": "Reminders section header. Shown on the settings page."
},
"reminders_description": {
"message": "Lembretes para começar um novo ciclo",
"description": "Reminders section description. Shown on the settings page."
},
"reminder_on_start": {
"message": "Quando abrir o navegador:",
"description": "Reminder options for when Chrome starts. Shown on the settings page."
},
"duration": {
"message": "Duração:",
"description": "Timer duration label. Shown on the settings page."
Expand Down
30 changes: 30 additions & 0 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Controller
this.loadTimer(this._settings, Phase.Focus);
this.menu = this.createMenu();
this.menu.apply();
this.showInitialReminders(this._settings)

chrome.alarms.onAlarm.addListener(alarm => {
if (alarm.name === 'autostart' && this.timer.isStopped) {
Expand Down Expand Up @@ -395,6 +396,35 @@ class Controller
return T('pomodoro_count_many', count.toLocaleString());
}
}

async showInitialReminders(settings) {
const pomodoros = this.timer.longBreakPomodoros;
const pomodorosLeftMsg = pomodoros === 0 ? '' : T('pomodoros_until_long_break', this.pomodoroCount(pomodoros));

const notificationMessages = count => {
const pomodorosTodayMsg = count === 0 ? '' : T('pomodoros_completed_today', this.pomodoroCount(count));
return [pomodorosLeftMsg, pomodorosTodayMsg];
};

const pomodorosTodayCount = await this.history.countToday();
if (settings.reminders.notification) {
this.notification = await Notification.show(
this,
T('start_focusing'),
notificationMessages(pomodorosTodayCount),
T('start_focusing_now')
);
}
if (settings.reminders.tab) {
this.expiration = await ExpirationPage.show(
T('start_focusing'),
[pomodorosLeftMsg],
T('start_focusing'),
pomodorosTodayCount,
'focus'
);
}
}
}

let history = new History();
Expand Down
18 changes: 17 additions & 1 deletion src/background/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class StorageManager extends EventEmitter
class MarinaraSchema
{
get version() {
return 5;
return 6;
}

get default() {
Expand Down Expand Up @@ -108,6 +108,10 @@ class MarinaraSchema
autostart: {
time: null,
},
reminders: {
notification: true,
tab: true
},
version: this.version
};
}
Expand Down Expand Up @@ -203,4 +207,16 @@ class MarinaraSchema

return v5;
}

from5To6(v5) {
let v6 = clone(v5);
v6.version = 6;

v6.reminders = {
notification: null,
tab: null
};

return v6;
}
}
19 changes: 19 additions & 0 deletions src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ <h2 data-t="autostart_title"></h2>
</label>
</p>
</div>
<div class="section">
<h2 data-t="reminders_title"></h2>
<p data-t="reminders_description"></p>
<p data-t="reminder_on_start"></p>
<div class="group">
<p class="field">
<label>
<input type="checkbox" id="reminder-notification">
<span data-t="show_desktop_notification"></span>
</label>
</p>
<p class="field">
<label>
<input type="checkbox" id="reminder-tab">
<span data-t="show_new_tab_notification"></span>
</label>
</p>
</div>
</div>
</form>
</div>
<div class="tab-page" id="history-page">
Expand Down
18 changes: 18 additions & 0 deletions src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ function loadSettingGroupAutostart(settings) {
time.value = settings.time;
}

function loadSettingGroupReminders(settings) {
let notif = document.getElementById('reminder-notification');
let tab = document.getElementById('reminder-tab');
notif.checked = settings.notification;
tab.checked = settings.tab;
}

async function loadSettings() {
let settings = await BackgroundClient.getSettings();
let notificationSounds = await BackgroundClient.getNotificationSounds();
Expand All @@ -169,6 +176,7 @@ async function loadSettings() {
loadSettingGroup('short-break', settings.shortBreak, notificationSounds, timerSounds);
loadSettingGroup('long-break', settings.longBreak, notificationSounds, timerSounds);
loadSettingGroupAutostart(settings.autostart);
loadSettingGroupReminders(settings.reminders);

let longBreakInterval = document.getElementById('long-break-interval');

Expand Down Expand Up @@ -228,11 +236,21 @@ function getSettingGroupAutostart() {
};
}

function getSettingGroupReminders() {
let notif = document.getElementById('reminder-notification');
let tab = document.getElementById('reminder-tab');
return {
notification: notif.checked || null,
tab: notif.checked || null
};
}

async function saveSettings(settings) {
settings.focus = getSettingGroup('focus');
settings.shortBreak = getSettingGroup('short-break');
settings.longBreak = getSettingGroup('long-break');
settings.autostart = getSettingGroupAutostart();
settings.reminders = getSettingGroupReminders();

let longBreakInterval = document.getElementById('long-break-interval');
settings.longBreak.interval = longBreakInterval.value;
Expand Down