Skip to content

Commit

Permalink
Merge pull request #9 from kairi003/feature/update-notification
Browse files Browse the repository at this point in the history
Add: Update notification
  • Loading branch information
kairi003 authored Mar 8, 2023
2 parents 5d6d42f + 0739540 commit d2be192
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,37 @@ const updateBadgeCounter = async () => {
chrome.cookies.onChanged.addListener(updateBadgeCounter);
chrome.tabs.onUpdated.addListener(updateBadgeCounter);
chrome.tabs.onActivated.addListener(updateBadgeCounter);


// Update notification
chrome.runtime.onInstalled.addListener(({ previouVersion, reason }) => {
if (reason == 'update') {
const currentVersion = chrome.runtime.getManifest().version;
chrome.notifications.create('updated', {
type: 'basic',
title: 'Get cookies.txt LOCALLY',
message: `Updated from ${previouVersion} to ${currentVersion}`,
iconUrl: '/images/icon128.png',
buttons: [
{ title: 'Github Releases' },
{ title: 'Uninstall' }]
});
}
});

// Update notification's button handler
chrome.notifications.onButtonClicked.addListener((notificationId, buttonIndex) => {
console.log(notificationId, buttonIndex);
if (notificationId === 'updated') {
switch (buttonIndex) {
case 0:
chrome.tabs.create({
url: "https://github.com/kairi003/Get-cookies.txt-LOCALLY/releases"
});
break;
case 1:
chrome.management.uninstallSelf({ showConfirmDialog: true });
break;
}
}
});
3 changes: 2 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"manifest_version": 3,
"permissions": [
"activeTab",
"cookies"
"cookies",
"notifications"
],
"host_permissions": ["<all_urls>"],
"action": {
Expand Down

0 comments on commit d2be192

Please sign in to comment.