Skip to content

Commit

Permalink
fix detection of closed tab
Browse files Browse the repository at this point in the history
  • Loading branch information
blackforestboi committed May 13, 2024
1 parent 92cb06d commit 7d5fa9b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
Expand Up @@ -112,7 +112,6 @@ import browser, { Browser } from 'webextension-polyfill'
import { isUrlYTVideo } from '@worldbrain/memex-common/lib/utils/youtube-url'
import debounce from 'lodash/debounce'
import { PremiumPlans } from '@worldbrain/memex-common/lib/subscriptions/availablePowerups'
import { AIActionAllowed } from '@worldbrain/memex-common/lib/subscriptions/storage'
import type { HighlightColor } from '@worldbrain/memex-common/lib/common-ui/components/highlightColorPicker/types'

const SHOW_ISOLATED_VIEW_KEY = `show-isolated-view-notif`
Expand Down
20 changes: 5 additions & 15 deletions src/summarization-llm/background/index.ts
Expand Up @@ -79,23 +79,23 @@ export default class SummarizeBackground {
}

async saveActiveTabId(hasKey: boolean, AImodel: AImodels) {
this.options.browserAPIs.tabs.onRemoved.removeListener(this.onTabClosed)
this.options.browserAPIs.tabs.onRemoved.addListener(this.onTabClosed)
const isAlreadySaved = await updateTabAISessions(
this.options.browserAPIs,
)

if (isAlreadySaved) {
return
return true
} else {
await AIActionAllowed(
return await AIActionAllowed(
this.options.browserAPIs,
this.options.analyticsBG,
hasKey,
true,
AImodel,
)
}

this.options.browserAPIs.tabs.onRemoved.addListener(this.onTabClosed)
}

onTabClosed = (tabId, removeInfo) => {
Expand All @@ -117,17 +117,7 @@ export default class SummarizeBackground {
promptData,
},
) => {
await this.saveActiveTabId(apiKey?.length > 0, AImodel)

let isAllowed = null

isAllowed = await AIActionAllowed(
this.options.browserAPIs,
this.options.analyticsBG,
apiKey?.length > 0,
true,
AImodel,
)
let isAllowed = await this.saveActiveTabId(apiKey?.length > 0, AImodel)

if (!isAllowed) {
return
Expand Down

0 comments on commit 7d5fa9b

Please sign in to comment.