Skip to content

Commit

Permalink
fix: require manual intervention or browser restart after auto update
Browse files Browse the repository at this point in the history
workaround for 1881820

(resolves #1477, #1470)
  • Loading branch information
mbnuqw committed Mar 4, 2024
1 parent 64e7323 commit 403f33d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/bg/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Permissions } from 'src/services/permissions'
import { Snapshots } from 'src/services/snapshots'
import { Sidebar } from 'src/services/sidebar'
import { Info } from 'src/services/info'
import { versionToInt } from 'src/services/info.actions'
import { Menu } from 'src/services/menu'
import { Styles } from 'src/services/styles'
import { WebReq } from 'src/services/web-req'
Expand Down Expand Up @@ -115,6 +116,12 @@ void (async function main() {

initToolbarButton()

browser.runtime.onUpdateAvailable.addListener(details => {
const currentVersion = versionToInt(browser.runtime.getManifest().version)
const newVersion = versionToInt(details.version)
if (newVersion <= currentVersion) browser.runtime.reload()
})

Logs.info(`Init end: ${performance.now() - ts}ms`)
})()

Expand Down
9 changes: 9 additions & 0 deletions src/services/info.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,12 @@ export async function loadCurrentTabInfo(): Promise<void> {
const tab = await browser.tabs.getCurrent()
Info.currentTabId = tab.id
}

export function versionToInt(version: string): number {
const parsed = version.split('.').map(n => parseInt(n))
const major = isNaN(parsed[0]) ? 0 : parsed[0]
const minor = isNaN(parsed[1]) ? 0 : parsed[1]
const patch = isNaN(parsed[2]) ? 0 : parsed[2]
const nightly = isNaN(parsed[3]) ? 0 : parsed[3]
return nightly + patch * 1_000 + minor * 1_000_000 + major * 1_000_000_000
}

0 comments on commit 403f33d

Please sign in to comment.