Skip to content

Commit 08395b5

Browse files
committed
Migrate extension to Manifest V3
1 parent ebe9900 commit 08395b5

File tree

5 files changed

+51
-14
lines changed

5 files changed

+51
-14
lines changed

src/manifest.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"manifest_version": 2,
2+
"manifest_version": 3,
33

44
"name": "Feedly Notifier",
55
"description": "__MSG_ExtensionDescription__",
@@ -9,16 +9,15 @@
99
"storage",
1010
"tabs",
1111
"notifications",
12-
"webRequest",
12+
"webRequest"
13+
],
14+
"host_permissions": [
1315
"*://*.feedly.com/"
1416
],
15-
"optional_permissions": [
16-
// @if BROWSER='chrome'
17-
"background",
18-
// @endif
17+
"optional_host_permissions": [
1918
"<all_urls>"
2019
],
21-
"browser_action": {
20+
"action": {
2221
"default_icon": {
2322
"19": "/images/icon_inactive.png",
2423
"38": "/images/icon_inactive38.png"
@@ -45,16 +44,17 @@
4544
},
4645
// @endif
4746
"background": {
48-
"scripts": [ "scripts/browser-polyfill.min.js", "scripts/feedly.api.js", "scripts/core.js"]
47+
"service_worker": "scripts/background.js"
4948
},
5049
"icons": {
5150
"16": "/images/icon16.png",
5251
"48": "/images/icon48.png",
5352
"128": "/images/icon128.png"
5453
},
55-
"web_accessible_resources": [
56-
"/images/icon128.png"
57-
],
54+
"web_accessible_resources": [{
55+
"resources": ["/images/icon128.png", "sound/*.mp3"],
56+
"matches": ["<all_urls>"]
57+
}],
5858
// @if BROWSER!='firefox'
5959
"minimum_chrome_version": "70",
6060
// @endif

src/offscreen.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<script src="scripts/offscreen.js"></script>
8+
</body>
9+
</html>

src/scripts/background.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
importScripts('browser-polyfill.min.js', 'feedly.api.js', 'core.js');
2+
3+
async function ensureOffscreen() {
4+
if (chrome.offscreen && !(await chrome.offscreen.hasDocument())) {
5+
await chrome.offscreen.createDocument({
6+
url: 'offscreen.html',
7+
reasons: [chrome.offscreen.Reason.AUDIO_PLAYBACK],
8+
justification: 'play notification sounds'
9+
});
10+
}
11+
}
12+
13+
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
14+
if (msg && msg.type === 'playSound') {
15+
ensureOffscreen().then(() => {
16+
chrome.runtime.sendMessage({offscreen: 'playSound', url: msg.url, volume: msg.volume});
17+
});
18+
}
19+
});

src/scripts/core.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,11 @@ function removeFeedFromCache(feedId) {
387387

388388
/* Plays alert sound */
389389
function playSound(){
390-
var audio = new Audio(appGlobal.options.sound);
391-
audio.volume = appGlobal.options.soundVolume;
392-
audio.play();
390+
chrome.runtime.sendMessage({
391+
type: 'playSound',
392+
url: chrome.runtime.getURL(appGlobal.options.sound),
393+
volume: appGlobal.options.soundVolume
394+
});
393395
}
394396

395397
/* Returns only new feeds and set date of last feed

src/scripts/offscreen.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
chrome.runtime.onMessage.addListener((msg) => {
2+
if (msg && msg.offscreen === 'playSound') {
3+
const audio = new Audio(msg.url);
4+
audio.volume = msg.volume ?? 1;
5+
audio.play();
6+
}
7+
});

0 commit comments

Comments
 (0)