-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
123 lines (103 loc) · 3.65 KB
/
Copy pathextension.js
File metadata and controls
123 lines (103 loc) · 3.65 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* This file is part of Simple Break Timer Gnome-Shell extension.
* Copyright (c) 2020 Georgii Surkov.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const Main = imports.ui.main;
const ExtensionUtils = imports.misc.extensionUtils;
const Extension = ExtensionUtils.getCurrentExtension();
const Menu = Extension.imports.menu;
const Timer = Extension.imports.timer;
const Indicator = Extension.imports.indicator;
const Settings = Extension.imports.settings;
const Mode = {
WORK: 0,
BREAK: 1,
STOP: 2
};
/*
TODO:
- Localisation,
- Launch preferences from menu
*/
class SimpleBreakTimer {
enable() {
this._timer = new Timer.Timer();
this._indicator = new Indicator.Indicator();
this._menu = new Menu.Menu(this._indicator);
this._settings = new Settings.Settings();
this._menu.on('work', () => this._beginWork());
this._menu.on('break', () => this._beginBreak());
this._menu.on('stop', () => this._stop());
this._indicator.setMenu(this._menu);
this._indicator.resetTime();
this._timer.on('update', (time) => this._indicator.displayTime(time));
this._timer.on('timeout', () => this._timeout());
//TODO: Settings for position
//NOTE: It doesn't work like this because other extensions may load after this one
const pos = Main.panel._centerBox.get_n_children();
Main.panel.addToStatusArea('Simple Break Timer', this._indicator, pos, 'center');
if(this._settings.autostartEnabled.value) {
this._beginWork();
}
}
disable() {
this._timer.stop();
this._indicator.destroy();
}
_displayNotification(title, message) {
if(this._settings.notificationsEnabled.value) {
Main.notify(title, message);
}
}
_beginWork() {
this._setMode(Mode.WORK);
this._menu.setCurrent('work');
this._indicator.setHighlighted(false);
this._displayNotification('Begin working', `${this._settings.workDuration.value} minutes remaining`);
}
_beginBreak() {
this._setMode(Mode.BREAK);
this._menu.setCurrent('break');
this._indicator.setHighlighted(true);
this._displayNotification('Begin break', `${this._settings.breakDuration.value} minutes remaining`);
}
_stop() {
this._setMode(Mode.STOP);
this._menu.setCurrent('stop');
this._indicator.resetTime();
this._indicator.setHighlighted(false);
}
_timeout() {
if(this._mode == Mode.WORK) {
this._beginBreak();
} else if(this._mode == Mode.BREAK) {
this._beginWork();
} else {}
}
_setMode(mode) {
this._mode = mode;
if(mode == Mode.WORK) {
this._timer.start(this._settings.workDuration.value * 60);
} else if(mode == Mode.BREAK) {
this._timer.start(this._settings.breakDuration.value * 60);
} else {
this._timer.stop();
}
}
};
function init() {
return new SimpleBreakTimer();
}