Skip to content

Commit 43bdd4c

Browse files
committed
fixes #703
1 parent 003d93b commit 43bdd4c

5 files changed

Lines changed: 91 additions & 31 deletions

File tree

v3.classic/_locales/en/messages.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@
116116
"options_timings_l8": {
117117
"message": "Set the value to zero for no email check until the first manual refresh [Not available on Safari]."
118118
},
119+
"options_timings_l9": {
120+
"message": "Track Gmail tabs and network activity to refresh the notifier on changes."
121+
},
122+
"options_timings_20": {
123+
"message": "Monitor system idle state to refresh the notifier when activity resumes."
124+
},
119125
"options_gmail": {
120126
"message": "Gmail™"
121127
},

v3.classic/core/repeater.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,39 @@ chrome.runtime.onStartup.addListener(() => repeater.build('normal', 'startup'));
6464
chrome.runtime.onInstalled.addListener(() => repeater.build('normal', 'startup'));
6565

6666
/* idle */
67-
chrome.runtime.onStartup.addListener(() => chrome.storage.local.get({
68-
'idle-detection': 5 // minutes
69-
}, prefs => {
70-
chrome.idle.setDetectionInterval(prefs['idle-detection'] * 60);
71-
}));
72-
chrome.idle.onStateChanged.addListener(name => {
73-
if (name === 'active') {
74-
repeater.reset('exit.idle');
75-
}
76-
});
67+
{
68+
const observe = name => {
69+
if (name === 'active') {
70+
repeater.reset('exit.idle');
71+
}
72+
};
73+
74+
const run = b => {
75+
chrome.idle.onStateChanged.removeListener(observe);
76+
if (b) {
77+
chrome.idle.onStateChanged.addListener(observe);
78+
}
79+
};
80+
81+
chrome.storage.local.get({
82+
'idle.watch': true
83+
}).then(prefs => {
84+
run(prefs['idle.watch']);
85+
});
86+
87+
chrome.storage.onChanged.addListener(ps => {
88+
if ('idle.watch' in ps) {
89+
run(ps['idle.watch'].newValue);
90+
}
91+
});
92+
93+
chrome.runtime.onStartup.addListener(() => chrome.storage.local.get({
94+
'idle-detection': 5 // minutes
95+
}, prefs => {
96+
chrome.idle.setDetectionInterval(prefs['idle-detection'] * 60);
97+
}));
98+
}
99+
77100
/* pref changes */
78101
chrome.storage.onChanged.addListener(prefs => {
79102
if (prefs.minimal ||

v3.classic/core/watch.js

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11
/* global repeater */
22

33
/* updating badge when action is posted */
4-
chrome.webRequest.onCompleted.addListener(d => {
5-
if (d.tabId) {
6-
if (
7-
d.type === 'main_frame' ||
8-
d.url.includes('&act=') ||
9-
(d.url.includes('/sync/u/') && d.method === 'POST') ||
10-
(d.url.includes('/mail/u/') && d.method === 'POST')
11-
) {
12-
repeater.reset('webrequest', 1000);
4+
5+
{
6+
const observe = d => {
7+
if (d.tabId) {
8+
if (
9+
d.type === 'main_frame' ||
10+
d.url.includes('&act=') ||
11+
(d.url.includes('/sync/u/') && d.method === 'POST') ||
12+
(d.url.includes('/mail/u/') && d.method === 'POST')
13+
) {
14+
repeater.reset('webrequest', 1000);
15+
}
16+
}
17+
};
18+
19+
const run = b => {
20+
chrome.webRequest.onCompleted.removeListener(observe);
21+
if (b) {
22+
chrome.webRequest.onCompleted.addListener(observe, {
23+
urls: [
24+
'*://mail.google.com/mail/u*',
25+
'*://mail.google.com/sync/u/*/i/s*',
26+
'*://mail.google.com/mail/logout*'
27+
]},
28+
[]);
29+
}
30+
};
31+
32+
chrome.storage.local.get({
33+
'network.watch': true
34+
}).then(prefs => {
35+
run(prefs['network.watch']);
36+
});
37+
38+
chrome.storage.onChanged.addListener(ps => {
39+
if ('network.watch' in ps) {
40+
run(ps['network.watch'].newValue);
1341
}
14-
}
15-
}, {
16-
urls: [
17-
'*://mail.google.com/mail/u*',
18-
'*://mail.google.com/sync/u/*/i/s*',
19-
'*://mail.google.com/mail/logout*'
20-
]},
21-
[]);
42+
});
43+
}

v3.classic/data/options/config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ config.map = {
2222
'plug-in/labels', 'express', 'basic.html', 'smartOpen',
2323
'notification.buttons.markasread', 'notification.buttons.archive', 'notification.buttons.trash',
2424
'notification.state.active', 'notification.state.idle', 'notification.state.locked',
25-
'sound.state.active', 'sound.state.idle', 'sound.state.locked'
25+
'sound.state.active', 'sound.state.idle', 'sound.state.locked', 'network.watch'
2626
]
2727
};
2828

@@ -102,5 +102,8 @@ config.prefs = {
102102
// styling
103103
'scale': 1,
104104
'styling_top': 'ddd',
105-
'styling_body': 'mmm'
105+
'styling_body': 'mmm',
106+
// watch
107+
'network.watch': true,
108+
'idle.watch': true
106109
};

v3.classic/data/options/index.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@
5050
<input id="initialPeriod" type="number" min="0" required></input>
5151
</div>
5252
<p class="note" data-l10n-id="options_timings_l8"></p>
53+
<div class="fm">
54+
<label for="network.watch" data-l10n-id="options_timings_l9"></label>
55+
<input id="network.watch" type="checkbox"></input>
56+
</div>
57+
<div class="fm">
58+
<label for="idle.watch" data-l10n-id="options_timings_20"></label>
59+
<input id="idle.watch" type="checkbox"></input>
60+
</div>
5361
</div>
5462
</div>
5563
<div hbox>
@@ -69,8 +77,6 @@
6977
<input type="text" id="feeds_4" placeholder="e.g.: inbox, important"/>
7078
<div data-l10n-id="options_gmail_7" class="nwap"></div>
7179
<input type="text" id="feeds_5" placeholder="e.g.: inbox, important"/>
72-
73-
7480
</div>
7581
<div class="note">
7682
<span data-l10n-id="options_gmail_2"></span>

0 commit comments

Comments
 (0)