From 5b1e2f0938f03f551773680a164c3c2c83e2997d Mon Sep 17 00:00:00 2001 From: Mike Crittenden Date: Tue, 30 Apr 2024 21:20:05 -0400 Subject: [PATCH] Add notification for missing settings --- app/manifest.json | 1 + app/options/options.vue | 17 ++++++----------- app/scripts/service_worker.js | 20 +++++++++++++++++++- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/manifest.json b/app/manifest.json index 64e8141..003796c 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -124,6 +124,7 @@ "management", "debugger", "scripting", + "notifications", "activeTab" ], "host_permissions": ["*://*/*"], diff --git a/app/options/options.vue b/app/options/options.vue index 9967c08..a2ed402 100644 --- a/app/options/options.vue +++ b/app/options/options.vue @@ -356,20 +356,15 @@ export default { } }; - async function loadKeys() { - const savedKeys = await chrome.storage.local.get('keys'); - if (savedKeys.keys) { + const savedKeys = await chrome.storage.local.get('keys') + if (savedKeys.keys) { this.keys = [...JSON.parse(savedKeys.keys)]; - } else { - // Fallback to localStorage if chrome.storage.local has no keys. - // This supports the manifest v2 to v3 migratoin path. - this.keys = localStorage.shortkeys ? JSON.parse(localStorage.shortkeys).keys : [{}]; - } + } else { + // Fallback to localStorage if chrome.storage.local has no keys. + // This supports the manifest v2 to v3 migratoin path. + this.keys = localStorage.shortkeys ? JSON.parse(localStorage.shortkeys).keys : [{}]; } - loadKeys(); - - chrome.bookmarks.getTree(processBookmarks) }, }; diff --git a/app/scripts/service_worker.js b/app/scripts/service_worker.js index f048ed3..60f42aa 100644 --- a/app/scripts/service_worker.js +++ b/app/scripts/service_worker.js @@ -384,12 +384,30 @@ browser.commands.onCommand.addListener(function (command) { }) browser.runtime.onMessage.addListener(function (request, sender, sendResponse) { + chrome.notifications.onButtonClicked.addListener((notificationId, buttonIndex) => { + if (notificationId === 'settingsNotification' && buttonIndex === 0) { + // Open the options page if exists + chrome.runtime.openOptionsPage(); + } + }); const action = request.action if (action === 'getKeys') { (async () => { const currentUrl = request.url const keysFromStorage = await chrome.storage.local.get("keys") - const settings = { keys: JSON.parse(keysFromStorage.keys) } + const settings = {} + if (keysFromStorage.keys) { + settings.keys = JSON.parse(keysFromStorage.keys) + } else { + chrome.notifications.create('settingsNotification', { + type: 'basic', + iconUrl: '/images/icon_128.png', + title: 'Shortkeys upgraded', + message: 'Action needed: re-save your shortcuts to continue using them.', + requireInteraction: true, + buttons: [{title: "Open and re-save settings"}] + }); + } let keys = [] if (settings.keys.length > 0) {