-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathindex.ts
More file actions
33 lines (30 loc) · 1.17 KB
/
index.ts
File metadata and controls
33 lines (30 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { onInstalled } from "@api/chrome/runtime"
import { executeScript } from "@api/chrome/script"
import { createTabAfterCurrent, listTabs } from "@api/chrome/tab"
import metaService from "@service/meta-service"
import { IS_E2E, IS_FROM_STORE } from "@util/constant/environment"
import { getGuidePageUrl } from "@util/constant/url"
import { isBrowserUrl } from "@util/pattern"
import UninstallListener from './uninstall-listener'
async function onFirstInstall() {
metaService.updateInstallTime(new Date())
!IS_E2E && createTabAfterCurrent(getGuidePageUrl())
}
async function reloadContentScript() {
const files = chrome.runtime.getManifest().content_scripts?.[0]?.js
if (!files?.length) {
return
}
const tabs = await listTabs()
tabs.filter(({ url }) => url && !isBrowserUrl(url))
.forEach(({ id: tabId }) => tabId && executeScript(tabId, files))
}
export default function handleInstall() {
onInstalled(async reason => {
reason === "install" && await onFirstInstall()
// Questionnaire for uninstall
new UninstallListener().listen()
// Reload content-script
IS_FROM_STORE && await reloadContentScript()
})
}