Skip to content

Commit e353d3d

Browse files
authored
Merge pull request #38 from femioladeji/feat/update-v2-v3
update manifest file
2 parents 1876c18 + 959ef5c commit e353d3d

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

manifest.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"manifest_version": 2,
2+
"manifest_version": 3,
33
"name": "Screentime",
44
"description": "To keep track and manage your time on sites that reduce productivity. You can set the number of minutes you want and time frames",
55
"short_name": "screentime",
66
"version": "5.0.2",
7-
"browser_action": {
7+
"action": {
88
"default_popup": "index.html",
99
"default_icon" : "images/icon_128.png"
1010
},
@@ -14,15 +14,13 @@
1414
"128": "images/icon_128.png"
1515
},
1616
"background": {
17-
"scripts": [
18-
"js/background/main.js"
19-
]
17+
"service_worker": "js/background/main.js",
18+
"type": "module"
2019
},
2120
"permissions": [
2221
"storage",
2322
"notifications",
2423
"tabs"
25-
],
26-
"content_security_policy": "script-src 'self'; object-src 'self'"
24+
]
2725
}
2826

src/assets/js/background.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const setDelayedAction = async (name, tabId) => {
2323
if (secondsToNextBlock && secondsToNextBlock < secondsToLimit) {
2424
secondsLeft = secondsToNextBlock;
2525
}
26-
delayHandler = setTimeout(() => {
27-
chrome.tabs.remove(tabId);
26+
delayHandler = setTimeout(async () => {
27+
await chrome.tabs.remove(tabId);
2828
utils.notify(`You can no longer be on ${name}`);
2929
}, secondsLeft * 1000);
3030
}
@@ -38,10 +38,10 @@ const setActive = async () => {
3838
if (utils.isTabAMatch(name, cacheStorage.configuration)) {
3939
if (utils.isTimeExceeded(cacheStorage, name)) {
4040
// eslint-disable-next-line
41-
chrome.tabs.remove(id);
41+
await chrome.tabs.remove(id);
4242
} else if (utils.isTimeframeBlocked(cacheStorage, name)) {
4343
// eslint-disable-next-line
44-
chrome.tabs.remove(id);
44+
await chrome.tabs.remove(id);
4545
} else if (cacheStorage.active.name !== name) {
4646
// if a different site is active then end the existing site's session
4747
utils.end(cacheStorage);
@@ -79,10 +79,12 @@ const synchronize = async (fetchData = false) => {
7979

8080
// eslint-disable-next-line
8181
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
82-
const { url } = tab;
83-
const name = utils.getName(url);
84-
if (cacheStorage.active.name !== name) {
85-
setActive();
82+
if (tab) {
83+
const { url } = tab;
84+
const name = utils.getName(url);
85+
if (cacheStorage.active.name !== name) {
86+
setActive();
87+
}
8688
}
8789
});
8890

@@ -106,17 +108,17 @@ const synchronize = async (fetchData = false) => {
106108
});
107109

108110
// eslint-disable-next-line
109-
chrome.notifications.onButtonClicked.addListener((notificationId, buttonIndex) => {
111+
chrome.notifications.onButtonClicked.addListener(async (notificationId, buttonIndex) => {
110112
if (buttonIndex === 0) {
111113
// close the tab
112114
// eslint-disable-next-line
113-
chrome.tabs.query({
115+
const activeTab = await chrome.tabs.query({
114116
active: true,
115117
currentWindow: true
116-
}, (activeTab) => {
117-
// eslint-disable-next-line
118-
chrome.tabs.remove(activeTab[0].id);
119118
});
119+
if (activeTab[0]) {
120+
await chrome.tabs.remove(activeTab[0].id);
121+
}
120122
}
121123
});
122124

src/assets/js/utils.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default {
132132
* @param {string} message message to show
133133
* @param {boolean} action if action buttons should be added
134134
*/
135-
notify(message, action) {
135+
async notify(message, action) {
136136
const notificationObject = {
137137
type: 'basic',
138138
iconUrl: 'images/icon_128.png',
@@ -145,9 +145,7 @@ export default {
145145
];
146146
notificationObject.requireInteraction = true;
147147
}
148-
// eslint-disable-next-line
149-
chrome.notifications.create(notificationObject, () => {
150-
});
148+
await chrome.notifications.create(null, notificationObject);
151149
},
152150

153151
saveConfiguration(key, data) {

0 commit comments

Comments
 (0)