From 07395402c7474dbbdede73fb1e250bb4e9abd603 Mon Sep 17 00:00:00 2001 From: kairi003 Date: Thu, 9 Mar 2023 06:42:51 +0900 Subject: [PATCH] Add: Update notification Notification when extensions are updated. You can open Releases on GitHub or Uninstall. --- src/background.js | 34 ++++++++++++++++++++++++++++++++++ src/manifest.json | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/background.js b/src/background.js index adc43c5..af2df71 100644 --- a/src/background.js +++ b/src/background.js @@ -13,3 +13,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; + } + } +}); \ No newline at end of file diff --git a/src/manifest.json b/src/manifest.json index e419a82..467511d 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -5,7 +5,8 @@ "manifest_version": 3, "permissions": [ "activeTab", - "cookies" + "cookies", + "notifications" ], "host_permissions": [""], "action": {