-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
97 lines (86 loc) · 3.81 KB
/
main.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
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
var { ActionButton } = require('sdk/ui/button/action');
var { Pomodoro } = require('Pomodoro');
var {Cc, Ci, Cu} = require('chrome');
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
var notificationIconURLActive = data.url("./pomodoro-active-64.png");
var notificationIconURLBreak = data.url("./pomodoro-break-64.png");
var blockedDomainString = require('sdk/simple-prefs').prefs['blockedDomainsList'];
var blockedDomainList = [];
var userstyles = require("./userstyles"),
os = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS,
windows = {
get active () { // Chrome window
return require('sdk/window/utils').getMostRecentBrowserWindow()
},
get activeWindow () { // SDK window
return require("sdk/windows").browserWindows.activeWindow
}
},
isAustralis = "gCustomizeMode" in windows.active,
toolbarbutton = isAustralis ? require("toolbarbutton/new") : require("toolbarbutton/old");
var pomodoroInstance = new Pomodoro(getPomodoroSettings());
var pomodoroButton = toolbarbutton.ToolbarButton({
id: "pomodoro-notifier",
label: pomodoroInstance._LABEL_ADDON_NAME,
tooltiptext: pomodoroInstance._LABEL_START_SESSION,
onClick: handleClick
});
function handleClick()
{
var strictMode = require('sdk/simple-prefs').prefs['strictMode'];
if (pomodoroInstance.timerIsOn) {
if (strictMode) {
console.log("strict mode enabled. Cannot stop period");
pomodoroInstance.toast(pomodoroInstance._NOTIFICATION_SESSION_CANNOT_STOP);
} else {
console.log("stopping session");
//pomodoroInstance.stopTimer(pomodoroButton);
pomodoroInstance.stopSession(pomodoroButton);
pageMod.destroy();
pomodoroInstance.toggleIcon(pomodoroButton, pomodoroInstance._INACTIVE, 0);
pomodoroInstance.toast(pomodoroInstance._NOTIFICATION_SESSION_STOPPED);
}
} else {
console.log("starting session");
var time = require('sdk/simple-prefs').prefs['timeActivityPeriod'];
//pomodoroInstance.startTimer(pomodoroButton, time);
pageMod.PageMod({
include: blockedDomainList,
contentScriptFile: data.url('./banner.js'),
contentScriptOptions: {pomodoroInstance: pomodoroInstance, url: data.url("pomodoro-active-128.png")},
contentScriptWhen: "ready",
contentStyle: "body {" +
" font-family: Helvetica !important;" +
" background-color: white !important;" +
" color: black !important;" +
"}"
});
pomodoroInstance.startSession(pomodoroButton, time, pageMod);
pomodoroInstance.toggleIcon(pomodoroButton, pomodoroInstance._ACTIVITY, time);
pomodoroInstance.toast(pomodoroInstance._NOTIFICATION_SESSION_STARTED);
}
}
function getPomodoroSettings()
{
return {
numCyclesPerSession : require('sdk/simple-prefs').prefs['numCyclesPerSession'],
timeActivityPeriod : require('sdk/simple-prefs').prefs['timeActivityPeriod'],
timeBreakPeriod : require('sdk/simple-prefs').prefs['timeBreakPeriod'],
strictMode : require('sdk/simple-prefs').prefs['strictMode'],
notificationIconURLActive : notificationIconURLActive,
notificationIconURLBreak : notificationIconURLBreak
};
}
if (typeof blockedDomainString == 'string') {
blockedDomainList = blockedDomainString.split(",");
} else {
pomodoroInstance.toast(pomodoroInstance._ERROR_BAD_FORMAT_DOMAIN_LIST);
}
userstyles.load(data.url("overlay.css"));
if (os == "Linux") {
userstyles.load(data.url("overlay-linux.css"));
} else if (os == "Darwin") {
userstyles.load(data.url("overlay-darwin.css"));
}
pomodoroInstance.toggleIcon(pomodoroButton, pomodoroInstance._INACTIVE, 0);