Skip to content

Commit 3a8dfae

Browse files
committed
Keep extension and IP check alive after set to hibernation
1 parent e2df0d5 commit 3a8dfae

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

build.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ packageChromeFunction() {
3131
}
3232

3333
prepareFirefoxFunction() {
34-
echo "Preparing manifest.json for Firefox"
35-
sed -i -e '14d;16d;17d' ./dev/manifest.json
34+
#echo "Preparing manifest.json for Firefox"
35+
echo "Firefox is currently not supported. It uses a different manifest.json file. Use an older version of the extension for Firefox."
36+
exit 1
37+
#sed -i -e '14d;16d;17d' ./dev/manifest.json
3638
cd ./dev/
3739
zip -qr firefox.zip ./*
3840
cd ..

js/main.js

+44-1
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,47 @@ setBadgeColor('#000000');
125125
setBadgeTextColor('#ffffff');
126126
setBadgeText('...');
127127
fetchGeoLocation();
128-
let intval = setInterval(fetchGeoLocation, checkInterval);
128+
129+
let intval;
130+
131+
function startInterval() {
132+
if (!intval) {
133+
intval = setInterval(fetchGeoLocation, checkInterval);
134+
}
135+
}
136+
137+
function stopInterval() {
138+
if (intval) {
139+
clearInterval(intval);
140+
intval = null;
141+
}
142+
}
143+
144+
chrome.alarms.onAlarm.addListener((alarm) => {
145+
console.log('alarm fired');
146+
console.log(alarm);
147+
if (alarm.name === 'checkIntervalAlarm') {
148+
stopInterval();
149+
startInterval();
150+
}
151+
});
152+
153+
chrome.runtime.onSuspend.addListener(function () {
154+
console.log('unloading');
155+
stopInterval();
156+
});
157+
158+
159+
chrome.alarms.onAlarm.addListener((alarm) => {
160+
console.log('alarm fired');
161+
if (alarm.name === 'checkIntervalAlarm') {
162+
stopInterval();
163+
startInterval();
164+
}
165+
});
166+
167+
chrome.runtime.onInstalled.addListener(() => {
168+
console.log('installed');
169+
startInterval();
170+
chrome.alarms.create('checkIntervalAlarm', { periodInMinutes: 1 * 60000 });
171+
});

manifest.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "IP Address & Geolocation",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"manifest_version": 3,
55
"icons": {
66
"16": "img/icon16.png",
@@ -21,7 +21,8 @@
2121
},
2222
"permissions": [
2323
"notifications",
24-
"storage"
24+
"storage",
25+
"alarms"
2526
],
2627
"minimum_chrome_version": "88",
2728
"options_ui": {

0 commit comments

Comments
 (0)