Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"manifest_version": 2,
"manifest_version": 3,

"name": "Feedly Notifier",
"description": "__MSG_ExtensionDescription__",
Expand All @@ -9,16 +9,15 @@
"storage",
"tabs",
"notifications",
"webRequest",
"webRequest"
],
"host_permissions": [
"*://*.feedly.com/"
],
"optional_permissions": [
// @if BROWSER='chrome'
"background",
// @endif
"optional_host_permissions": [
"<all_urls>"
],
"browser_action": {
"action": {
"default_icon": {
"19": "/images/icon_inactive.png",
"38": "/images/icon_inactive38.png"
Expand All @@ -45,16 +44,17 @@
},
// @endif
"background": {
"scripts": [ "scripts/browser-polyfill.min.js", "scripts/feedly.api.js", "scripts/core.js"]
"service_worker": "scripts/background.js"
},
"icons": {
"16": "/images/icon16.png",
"48": "/images/icon48.png",
"128": "/images/icon128.png"
},
"web_accessible_resources": [
"/images/icon128.png"
],
"web_accessible_resources": [{
"resources": ["/images/icon128.png", "sound/*.mp3"],
"matches": ["<all_urls>"]
}],
// @if BROWSER!='firefox'
"minimum_chrome_version": "70",
// @endif
Expand Down
9 changes: 9 additions & 0 deletions src/offscreen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<script src="scripts/offscreen.js"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions src/scripts/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
importScripts('browser-polyfill.min.js', 'feedly.api.js', 'core.js');

async function ensureOffscreen() {
if (chrome.offscreen && !(await chrome.offscreen.hasDocument())) {
await chrome.offscreen.createDocument({
url: 'offscreen.html',
reasons: [chrome.offscreen.Reason.AUDIO_PLAYBACK],
justification: 'play notification sounds'
});
}
}

chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg && msg.type === 'playSound') {
ensureOffscreen().then(() => {
chrome.runtime.sendMessage({offscreen: 'playSound', url: msg.url, volume: msg.volume});
});
}
});
32 changes: 17 additions & 15 deletions src/scripts/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ chrome.webRequest.onCompleted.addListener(function (details) {
}
}, {urls: ["*://*.feedly.com/v3/tags*global.saved*"]});

chrome.browserAction.onClicked.addListener(function () {
chrome.action.onClicked.addListener(function () {
if (appGlobal.isLoggedIn) {
openFeedlyTab();
if(appGlobal.options.resetCounterOnClick){
Expand All @@ -197,9 +197,9 @@ chrome.browserAction.onClicked.addListener(function () {
/* Initialization all parameters and run feeds check */
function initialize() {
if (appGlobal.options.openSiteOnIconClick) {
chrome.browserAction.setPopup({popup: ""});
chrome.action.setPopup({popup: ""});
} else {
chrome.browserAction.setPopup({popup: "popup.html"});
chrome.action.setPopup({popup: "popup.html"});
}
appGlobal.feedlyApiClient.accessToken = appGlobal.options.accessToken;

Expand Down Expand Up @@ -387,9 +387,11 @@ function removeFeedFromCache(feedId) {

/* Plays alert sound */
function playSound(){
var audio = new Audio(appGlobal.options.sound);
audio.volume = appGlobal.options.soundVolume;
audio.play();
chrome.runtime.sendMessage({
type: 'playSound',
url: chrome.runtime.getURL(appGlobal.options.sound),
volume: appGlobal.options.soundVolume
});
}

/* Returns only new feeds and set date of last feed
Expand Down Expand Up @@ -452,16 +454,16 @@ function setBadgeCounter(unreadFeedsCount) {
const thousands = Math.floor(unreadFeedsCountNumber / 1000);
unreadFeedsCount = thousands + "k+";
}
chrome.browserAction.setBadgeText({ text: String(unreadFeedsCountNumber > 0 ? unreadFeedsCount : "")});
chrome.action.setBadgeText({ text: String(unreadFeedsCountNumber > 0 ? unreadFeedsCount : "")});
} else {
chrome.browserAction.setBadgeText({ text: ""});
chrome.action.setBadgeText({ text: ""});
}

if (!unreadFeedsCount && appGlobal.options.grayIconColorIfNoUnread) {
chrome.browserAction.setIcon({ path: appGlobal.icons.inactive }, function () {
chrome.action.setIcon({ path: appGlobal.icons.inactive }, function () {
});
} else {
chrome.browserAction.setIcon({ path: appGlobal.icons.default }, function () {
chrome.action.setIcon({ path: appGlobal.icons.default }, function () {
});
}
}
Expand Down Expand Up @@ -537,7 +539,7 @@ function makeMarkersRequest(parameters){
}
}).then(setBadgeCounter)
.catch(function (e) {
chrome.browserAction.setBadgeText({ text: ""});
chrome.action.setBadgeText({ text: ""});

console.info("Unable to load counters.", e);
});
Expand Down Expand Up @@ -633,17 +635,17 @@ function updateFeeds(silentUpdate) {

/* Stops scheduler, sets badge as inactive and resets counter */
function setInactiveStatus() {
chrome.browserAction.setIcon({ path: appGlobal.icons.inactive }, function () {
chrome.action.setIcon({ path: appGlobal.icons.inactive }, function () {
});
chrome.browserAction.setBadgeText({ text: ""});
chrome.action.setBadgeText({ text: ""});
appGlobal.cachedFeeds = [];
appGlobal.isLoggedIn = false;
stopSchedule();
}

/* Sets badge as active */
function setActiveStatus() {
chrome.browserAction.setBadgeBackgroundColor({color: "#CF0016"});
chrome.action.setBadgeBackgroundColor({color: "#CF0016"});
appGlobal.isLoggedIn = true;
}

Expand Down Expand Up @@ -851,7 +853,7 @@ function markAsRead(feedIds, callback) {
for (let i = 0; i < copyArray.length; i++) {
removeFeedFromCache(copyArray[i]);
}
chrome.browserAction.getBadgeText({}, function (feedsCount) {
chrome.action.getBadgeText({}, function (feedsCount) {
feedsCount = +feedsCount;
if (feedsCount > 0) {
feedsCount -= copyArray.length;
Expand Down
7 changes: 7 additions & 0 deletions src/scripts/offscreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chrome.runtime.onMessage.addListener((msg) => {
if (msg && msg.offscreen === 'playSound') {
const audio = new Audio(msg.url);
audio.volume = msg.volume ?? 1;
audio.play();
}
});
Loading