Skip to content

Commit

Permalink
No version autocomplete on init, removed 19.2.2 change #345
Browse files Browse the repository at this point in the history
  • Loading branch information
victrme committed Apr 7, 2024
1 parent 229c034 commit 7aefd7b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
17 changes: 10 additions & 7 deletions src/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,10 @@ async function startup() {
let { sync, local } = await storage.init()
const OLD_VERSION = sync?.about?.version

// Force trns refresh for everyone this version
if (CURRENT_VERSION === '19.2.2') {
delete local.translations
}

if (OLD_VERSION !== CURRENT_VERSION) {
console.log(`Version change: ${OLD_VERSION} => ${CURRENT_VERSION}`)
sync = upgradeSyncStorage(sync)
delete local.translations
local = upgradeLocalStorage(local)
storage.sync.set(sync)
}

Expand Down Expand Up @@ -99,6 +94,8 @@ async function startup() {
}

function upgradeSyncStorage(data: Sync.Storage): Sync.Storage {
data.about = SYNC_DEFAULT.about

// 19.0.0

if (data.reviewPopup) {
Expand Down Expand Up @@ -139,7 +136,13 @@ function upgradeSyncStorage(data: Sync.Storage): Sync.Storage {
storage.sync.remove('cssHeight')

data = linksDataMigration(data)
data.about = SYNC_DEFAULT.about

return data
}

function upgradeLocalStorage(data: Local.Storage): Local.Storage {
data.translations = undefined
storage.local.remove('translations')

return data
}
Expand Down
16 changes: 6 additions & 10 deletions src/scripts/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ function verifyDataAsSync(data: Keyval) {
data = data ?? {}

for (const key in SYNC_DEFAULT) {
if (!(key in data)) {
const notAbout = key !== 'about'
const missingKey = !(key in data)

if (notAbout && missingKey) {
data[key] = SYNC_DEFAULT[key]
}
}
Expand Down Expand Up @@ -195,8 +198,8 @@ function webext(): Storage {
// This waits for chrome.storage to be stored in a global variable
// that is created in file `webext-storage.js`

//@ts-ignore
const store = startupStorage as AllStorage
//@ts-expect-error
const store: AllStorage = startupStorage
const isReady = (): boolean => 'sync' in store && 'local' in store

if (!isReady()) {
Expand All @@ -207,13 +210,6 @@ function webext(): Storage {
})
}

// ⚠️ before mutating data with verifyData
if (!store?.sync?.about) {
queueMicrotask(() => {
chrome.storage.sync.set({ about: SYNC_DEFAULT.about })
})
}

const sync = verifyDataAsSync(store.sync)
const local = verifyDataAsLocal(store.local)

Expand Down

0 comments on commit 7aefd7b

Please sign in to comment.