Skip to content

Commit

Permalink
fix(background): ensure default storage is populated; fix popup crash (
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi committed Jun 14, 2024
1 parent 3cb58cd commit 05e582f
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/background/services/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,8 @@ export class Background {
}

bindPermissionsHandler() {
const permissions = this.browser.permissions
const checkPermissions = async () => {
try {
const status = await permissions.contains(PERMISSION_HOSTS)
this.storage.setHostPermissionStatus(status)
} catch (error) {
this.logger.error(error)
}
}

void checkPermissions()
permissions.onAdded.addListener(checkPermissions)
permissions.onRemoved.addListener(checkPermissions)
this.browser.permissions.onAdded.addListener(this.checkPermissions)
this.browser.permissions.onRemoved.addListener(this.checkPermissions)
this.events.on('storage.host_permissions_update', async ({ status }) => {
this.logger.info('permission changed', { status })
// TODO: change icon here in future
Expand All @@ -179,6 +168,17 @@ export class Background {
await this.storage.populate()
await this.openPaymentsService.genererateKeys()
}
await this.checkPermissions()
})
}

checkPermissions = async () => {
try {
this.logger.debug('checking hosts permission')
const status = await this.browser.permissions.contains(PERMISSION_HOSTS)
this.storage.setHostPermissionStatus(status)
} catch (error) {
this.logger.error(error)
}
}
}

0 comments on commit 05e582f

Please sign in to comment.