Skip to content

Commit

Permalink
Keep extension and IP check alive after set to hibernation
Browse files Browse the repository at this point in the history
  • Loading branch information
AykutCevik committed May 29, 2024
1 parent e2df0d5 commit 3a8dfae
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
6 changes: 4 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ packageChromeFunction() {
}

prepareFirefoxFunction() {
echo "Preparing manifest.json for Firefox"
sed -i -e '14d;16d;17d' ./dev/manifest.json
#echo "Preparing manifest.json for Firefox"
echo "Firefox is currently not supported. It uses a different manifest.json file. Use an older version of the extension for Firefox."
exit 1
#sed -i -e '14d;16d;17d' ./dev/manifest.json
cd ./dev/
zip -qr firefox.zip ./*
cd ..
Expand Down
45 changes: 44 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,47 @@ setBadgeColor('#000000');
setBadgeTextColor('#ffffff');
setBadgeText('...');
fetchGeoLocation();
let intval = setInterval(fetchGeoLocation, checkInterval);

let intval;

function startInterval() {
if (!intval) {
intval = setInterval(fetchGeoLocation, checkInterval);
}
}

function stopInterval() {
if (intval) {
clearInterval(intval);
intval = null;
}
}

chrome.alarms.onAlarm.addListener((alarm) => {
console.log('alarm fired');
console.log(alarm);
if (alarm.name === 'checkIntervalAlarm') {
stopInterval();
startInterval();
}
});

chrome.runtime.onSuspend.addListener(function () {
console.log('unloading');
stopInterval();
});


chrome.alarms.onAlarm.addListener((alarm) => {
console.log('alarm fired');
if (alarm.name === 'checkIntervalAlarm') {
stopInterval();
startInterval();
}
});

chrome.runtime.onInstalled.addListener(() => {
console.log('installed');
startInterval();
chrome.alarms.create('checkIntervalAlarm', { periodInMinutes: 1 * 60000 });
});
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "IP Address & Geolocation",
"version": "3.0.1",
"version": "3.0.2",
"manifest_version": 3,
"icons": {
"16": "img/icon16.png",
Expand All @@ -21,7 +21,8 @@
},
"permissions": [
"notifications",
"storage"
"storage",
"alarms"
],
"minimum_chrome_version": "88",
"options_ui": {
Expand Down

0 comments on commit 3a8dfae

Please sign in to comment.