MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / init

Method init

src/app/service/service_worker/runtime.ts:404–680  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

402 }
403
404 init() {
405 if (deliveryStorage === chrome.storage.session) {
406 this.setSessionAccessLevel();
407 }
408 // 启动gm api
409 const permission = new PermissionVerify(this.group.group("permission"), this.mq);
410 this.gmApi = new GMApi(
411 this.systemConfig,
412 permission,
413 this.group,
414 this.msgSender,
415 this.mq,
416 this.value,
417 new GMExternalDependencies(this)
418 );
419 permission.init();
420 this.gmApi.start();
421
422 this.group.on("stopScript", this.stopScript.bind(this));
423 this.group.on("runScript", this.runScript.bind(this));
424 this.group.on("pageLoad", this.pageLoad.bind(this));
425
426 // 监听脚本开启
427 this.mq.subscribe<TEnableScript[]>("enableScripts", async (data) => {
428 const unregisteyUuids = [] as string[];
429 for (const { uuid, enable } of data) {
430 const script = await this.scriptDAO.get(uuid);
431 if (!script) {
432 this.logger.error("script enable failed, script not found", {
433 uuid: uuid,
434 });
435 continue;
436 }
437 if (enable !== (script.status === SCRIPT_STATUS_ENABLE)) {
438 // 防止启用停止状态冲突
439 this.logger.error("script enable status conflicts", {
440 uuid: uuid,
441 });
442 continue;
443 }
444 // 如果是普通脚本, 在service worker中进行注册
445 // 如果是后台脚本, 在offscreen中进行处理
446 // 脚本类别不会更改
447 if (script.type === SCRIPT_TYPE_NORMAL) {
448 // 加载页面脚本
449 if (enable) {
450 await this.updateResourceOnScriptChange(script);
451 } else {
452 unregisteyUuids.push(uuid);
453 }
454 }
455 }
456 await this.unregistryPageScripts(unregisteyUuids);
457 });
458
459 // 监听脚本安装
460 this.mq.subscribe<TInstallScript>("installScript", async (data) => {
461 const script = await this.scriptDAO.get(data.script.uuid);

Callers 1

initManagerMethod · 0.95

Calls 15

setSessionAccessLevelMethod · 0.95
initMethod · 0.95
unregistryPageScriptsMethod · 0.95
unregisterUserscriptsMethod · 0.95
registerUserscriptsMethod · 0.95
updateIconMethod · 0.95
loadBlacklistMethod · 0.95
waitInitMethod · 0.95
initUserAgentDataMethod · 0.95

Tested by

no test coverage detected