Skip to content

Commit

Permalink
add missing key IDs upon update
Browse files Browse the repository at this point in the history
  • Loading branch information
hababr committed Aug 14, 2024
1 parent 856dea0 commit 75d9445
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/scripts/service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import captureScreenshot from './actions/captureScreenshot'
import lastUsedTab from './actions/lastUsedTab'
import { executeScript } from './utils'
import { v4 as uuid } from "uuid"

/* global localStorage, chrome */

Expand Down Expand Up @@ -377,6 +378,16 @@ let handleAction = async (action, request = {}) => {
return true
}

async function checkKeys() {
const keys = JSON.parse((await chrome.storage.local.get("keys")).keys) || []
for (const key of keys) {
if (!key.id) {
key.id = uuid()
}
}
await chrome.storage.local.set({ keys: JSON.stringify(keys) });
}

async function registerUserScript() {
const keys = JSON.parse((await chrome.storage.local.get("keys")).keys) || []
const javascriptActions = keys.filter(key => key.action === "javascript")
Expand Down Expand Up @@ -421,8 +432,9 @@ async function registerUserScript() {

chrome.storage.local.onChanged.addListener(registerUserScript)

chrome.runtime.onInstalled.addListener(function (details) {
chrome.runtime.onInstalled.addListener(async function (details) {
if (details.reason === "update") {
await checkKeys()
registerUserScript()
}
})
Expand Down

0 comments on commit 75d9445

Please sign in to comment.