MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / init

Method init

src/app/service/service_worker/system.ts:24–95  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22 ) {}
23
24 init() {
25 const vscodeConnect = new VscodeConnectClient(this.msgSender);
26 this.group.on("connectVSCode", (params) => {
27 return vscodeConnect.connect(params);
28 });
29
30 // 脚本更新删除favicon缓存
31 this.mq.subscribe<TInstallScript>("installScript", (messages) => {
32 if (messages.update) {
33 // 删除旧的favicon缓存
34 cacheInstance.tx("faviconOPFSControl", async () => {
35 const uuid = messages.script.uuid;
36 await this.faviconDAO.delete(uuid);
37 });
38 }
39 });
40
41 // 监听脚本删除,清理favicon缓存
42 this.mq.subscribe<TDeleteScript[]>("deleteScripts", (message) => {
43 cacheInstance.tx("faviconOPFSControl", async () => {
44 const faviconDAO = this.faviconDAO;
45 const cleanupIcons = new Set<string>();
46 // 需要删除的icon
47 const uuids = await Promise.all(
48 message.map(({ uuid }) =>
49 faviconDAO.get(uuid).then((entry) => {
50 const icons = entry?.favicons;
51 if (icons) {
52 for (const icon of icons) {
53 if (icon.icon) {
54 cleanupIcons.add(icon.icon);
55 }
56 }
57 }
58 return uuid;
59 })
60 )
61 );
62 // 删除数据
63 await faviconDAO.deletes(uuids);
64 // 需要保留的icon
65 await faviconDAO.all().then((results) => {
66 for (const entry of results) {
67 for (const icon of entry.favicons) {
68 if (icon.icon) {
69 cleanupIcons.delete(icon.icon);
70 }
71 }
72 }
73 });
74 // 删除opfs缓存
75 await Promise.all(
76 [...cleanupIcons].map((iconUrl) => removeFavicon(`icon_${uuidv5(iconUrl, uuidv5.URL)}.dat`).catch(() => {}))
77 );
78 });
79 });
80
81 // 如果开启了自动连接vscode,则自动连接

Callers 1

initManagerMethod · 0.95

Calls 11

connectMethod · 0.95
removeFaviconFunction · 0.90
txMethod · 0.80
addMethod · 0.80
deletesMethod · 0.80
getVscodeReconnectMethod · 0.80
getVscodeUrlMethod · 0.80
subscribeMethod · 0.65
deleteMethod · 0.65
getMethod · 0.65
onMethod · 0.45

Tested by

no test coverage detected