11import axios from "axios" ;
2- import { MessageCallback , MsgCenter } from "@App/apps/msg-center/msg-center" ;
3- import { AppEvent , ScriptExec , ScriptRunStatusChange , ScriptStatusChange , ScriptStop , ScriptUninstall , ScriptReinstall , ScriptValueChange , TabRemove , RequestTabRunScript , ScriptInstall , RequestInstallInfo , ScriptCheckUpdate , RequestConfirmInfo , ListenGmLog , SubscribeUpdate , Unsubscribe , SubscribeCheckUpdate , ImportFile , OpenImportFileWindow , RequestImportFile } from "@App/apps/msg-center/event" ;
4- import { dealScript , get , Page , randomString } from "@App/pkg/utils" ;
2+ import { MsgCenter } from "@App/apps/msg-center/msg-center" ;
3+ import { AppEvent , ScriptExec , ScriptRunStatusChange , ScriptStatusChange , ScriptStop , ScriptUninstall , ScriptReinstall , ScriptValueChange , TabRemove , RequestTabRunScript , ScriptInstall , RequestInstallInfo , ScriptCheckUpdate , RequestConfirmInfo , ListenGmLog , SubscribeUpdate , Unsubscribe , SubscribeCheckUpdate , ImportFile , OpenImportFileWindow , RequestImportFile , ScriptInstallByURL } from "@App/apps/msg-center/event" ;
4+ import { dealScript , get , randomString } from "@App/pkg/utils" ;
55import { App } from "../app" ;
66import { UrlMatch } from "@App/pkg/match" ;
77import { ValueModel } from "@App/model/value" ;
@@ -21,9 +21,10 @@ import { SyncModel } from "@App/model/sync";
2121import { SyncAction , SyncData } from "@App/model/do/sync" ;
2222import { File } from "@App/model/do/back" ;
2323import { v4 as uuidv4 } from "uuid" ;
24+ import { Manager } from "@App/pkg/apps/manager" ;
2425
2526// 脚本管理器,收到控制器消息进行实际的操作
26- export class ScriptManager {
27+ export class ScriptManager extends Manager {
2728
2829 protected scriptModel = new ScriptModel ( ) ;
2930 protected subscribeModel = new SubscribeModel ( ) ;
@@ -86,6 +87,7 @@ export class ScriptManager {
8687 public listen ( ) {
8788
8889 // 消息监听处理
90+ this . listenerMessage ( ScriptInstallByURL , this . installScriptByURL ) ;
8991 this . listenerMessage ( ScriptInstall , this . scriptInstall )
9092 this . listenerMessage ( ScriptReinstall , this . scriptReinstall )
9193 this . listenerMessage ( ScriptUninstall , ( body ) => { return this . scriptUninstall ( body , false ) } )
@@ -124,7 +126,11 @@ export class ScriptManager {
124126 if ( hash . indexOf ( "bypass=true" ) != - 1 ) {
125127 return ;
126128 }
127- this . installScript ( req . tabId , req . url ) ;
129+ this . installScriptByURL ( req . url ) . catch ( ( ) => {
130+ chrome . tabs . update ( req . tabId , {
131+ url : req . url + "#bypass=true" ,
132+ } ) ;
133+ } ) ;
128134 return { redirectUrl : "javascript:void 0" } ;
129135 } ,
130136 {
@@ -138,18 +144,19 @@ export class ScriptManager {
138144 ) ;
139145 }
140146
141- public async installScript ( tabid : number , url : string ) {
142- let info = await loadScriptByUrl ( url ) ;
143- if ( info ) {
144- App . Cache . set ( "install:info:" + info . uuid , info ) ;
145- chrome . tabs . create ( {
146- url : "install.html?uuid=" + info . uuid ,
147- } ) ;
148- } else {
149- chrome . tabs . update ( tabid , {
150- url : url + "#bypass=true" ,
151- } ) ;
152- }
147+ public async installScriptByURL ( url : string ) {
148+ return new Promise ( async ( resolve , reject ) => {
149+ let info = await loadScriptByUrl ( url ) ;
150+ if ( info ) {
151+ App . Cache . set ( "install:info:" + info . uuid , info ) ;
152+ chrome . tabs . create ( {
153+ url : "install.html?uuid=" + info . uuid ,
154+ } ) ;
155+ resolve ( true ) ;
156+ } else {
157+ reject ( false ) ;
158+ }
159+ } ) ;
153160 }
154161
155162 // 监听来自AppEvent的事件和连接来自其它地方的长链接,转发AppEvent的事件
@@ -176,16 +183,6 @@ export class ScriptManager {
176183 } )
177184 }
178185
179- public listenerMessage ( topic : string , callback : MessageCallback ) {
180- MsgCenter . listenerMessage ( topic , async ( body , send , sender ) => {
181- let ret = < any > callback . call ( this , body , send , sender )
182- if ( ret instanceof Promise ) {
183- ret = await ret ;
184- }
185- send ( ret ) ;
186- } ) ;
187- }
188-
189186 public requestConfirmInfo ( uuid : string ) : Promise < ConfirmParam > {
190187 return new Promise ( resolve => {
191188 let info = App . Cache . get ( "confirm:info:" + uuid ) ;
0 commit comments