@@ -16,7 +16,7 @@ import { ScriptManager } from '../script/manager';
1616import { Grant , Api , IPostMessage , IGrantListener , ConfirmParam , PermissionParam , FreedCallback } from './interface' ;
1717import { v4 as uuidv4 } from 'uuid'
1818import { ValueModel } from '@App/model/value' ;
19- import { LOGGER_LEVEL_INFO } from '@App/model/do/logger' ;
19+ import { LOGGER_LEVEL , LOGGER_LEVEL_INFO } from '@App/model/do/logger' ;
2020import { Permission } from '@App/model/do/permission' ;
2121import { Script } from '@App/model/do/script' ;
2222import { Value } from '@App/model/do/value' ;
@@ -344,10 +344,12 @@ export class BackgroundGrant {
344344 // 处理下一个
345345 const next = ( ) => {
346346 // 一个打开确定,一群不打开只监听消息
347- const confirm = list . pop ( ) ;
348- if ( confirm ) {
349- void App . Cache . set ( 'confirm:info:' + confirm . uuid , confirm ) ;
350- chrome . tabs . create ( { url : chrome . runtime . getURL ( 'confirm.html?uuid=' + confirm . uuid ) } ) ;
347+ const item = list . pop ( ) ;
348+ if ( item ) {
349+ void App . Cache . set ( 'confirm:info:' + item . uuid , [ item , list . length ] ) ;
350+ chrome . tabs . create ( { url : chrome . runtime . getURL ( 'confirm.html?uuid=' + item . uuid ) } ) ;
351+ } else {
352+ void App . Cache . del ( 'confirm:window:' + confirm . permission + ':list:' + script . id . toString ( ) ) ;
351353 }
352354 }
353355 const listener = async ( param : IPermissionConfirm ) => {
@@ -919,31 +921,31 @@ export class BackgroundGrant {
919921 silent : details . silent ,
920922 progress : details . progress
921923 } ;
922- chrome . notifications . update ( id , options ) ;
924+ chrome . notifications . update ( < string > id , options ) ;
923925 return resolve ( undefined ) ;
924926 } ) ;
925927 }
926928
927929 @BackgroundGrant . GMFunction ( { default : true , background : true } )
928930 protected CAT_setLastRuntime ( grant : Grant , post : IPostMessage ) : Promise < any > {
929931 return new Promise ( resolve => {
930- this . scriptMgr . setLastRuntime ( grant . id , grant . params [ 0 ] ) ;
932+ void this . scriptMgr . setLastRuntime ( grant . id , < number > grant . params [ 0 ] ) ;
931933 return resolve ( undefined ) ;
932934 } ) ;
933935 }
934936
935937 @BackgroundGrant . GMFunction ( { default : true , background : true } )
936938 protected CAT_setRunError ( grant : Grant , post : IPostMessage ) : Promise < any > {
937939 return new Promise ( resolve => {
938- this . scriptMgr . setRunError ( grant . id , grant . params [ 0 ] , grant . params [ 1 ] ) ;
940+ void this . scriptMgr . setRunError ( grant . id , < string > grant . params [ 0 ] , < number > grant . params [ 1 ] ) ;
939941 return resolve ( undefined ) ;
940942 } ) ;
941943 }
942944
943945 @BackgroundGrant . GMFunction ( { default : true , background : true } )
944946 protected CAT_runComplete ( grant : Grant , post : IPostMessage ) : Promise < any > {
945947 return new Promise ( resolve => {
946- this . scriptMgr . setRunComplete ( grant . id ) ;
948+ void this . scriptMgr . setRunComplete ( grant . id ) ;
947949 return resolve ( undefined ) ;
948950 } ) ;
949951 }
@@ -954,7 +956,7 @@ export class BackgroundGrant {
954956 if ( grant . params . length == 0 ) {
955957 return reject ( 'param is null' ) ;
956958 }
957- App . Log . Logger ( grant . params [ 1 ] ?? LOGGER_LEVEL_INFO , 'GM_log' , grant . params [ 0 ] , grant . name , grant . id ) ;
959+ App . Log . Logger ( < LOGGER_LEVEL > grant . params [ 1 ] ?? LOGGER_LEVEL_INFO , 'GM_log' , < string > grant . params [ 0 ] , grant . name , grant . id ) ;
958960 AppEvent . trigger ( ListenGmLog , {
959961 level : grant . params [ 1 ] ?? LOGGER_LEVEL_INFO ,
960962 scriptId : grant . id ,
@@ -967,36 +969,39 @@ export class BackgroundGrant {
967969 @BackgroundGrant . GMFunction ( )
968970 protected GM_setValue ( grant : Grant , post : IPostMessage , script ?: Script ) : Promise < any > {
969971 //getValue直接从缓存中返回了,无需编写
970- return new Promise ( async resolve => {
971- const [ key , value ] = grant . params ;
972- let model : Value | undefined ;
973- if ( script ?. metadata [ 'storagename' ] ) {
974- model = await this . valueModel . findOne ( { storageName : script . metadata [ 'storagename' ] [ 0 ] , key : key } ) ;
975- } else {
976- model = await this . valueModel . findOne ( { scriptId : script ?. id , key : key } ) ;
977- }
978- if ( ! model ) {
979- model = {
980- id : 0 ,
981- scriptId : script ?. id || 0 ,
982- storageName : ( script ?. metadata [ 'storagename' ] && script ?. metadata [ 'storagename' ] [ 0 ] ) || '' ,
983- key : key ,
984- value : value ,
985- createtime : new Date ( ) . getTime ( )
972+ return new Promise ( resolve => {
973+ const hanlder = async ( ) => {
974+ const [ key , value ] = grant . params ;
975+ let model : Value | undefined ;
976+ if ( script ?. metadata [ 'storagename' ] ) {
977+ model = await this . valueModel . findOne ( { storageName : script . metadata [ 'storagename' ] [ 0 ] , key : key } ) ;
978+ } else {
979+ model = await this . valueModel . findOne ( { scriptId : script ?. id , key : key } ) ;
980+ }
981+ if ( ! model ) {
982+ model = {
983+ id : 0 ,
984+ scriptId : script ?. id || 0 ,
985+ storageName : ( script ?. metadata [ 'storagename' ] && script ?. metadata [ 'storagename' ] [ 0 ] ) || '' ,
986+ key : key ,
987+ value : value ,
988+ createtime : new Date ( ) . getTime ( )
989+ }
990+ } else {
991+ model . value = value ;
992+ }
993+
994+ if ( value === undefined ) {
995+ void this . valueModel . delete ( model . id ) ;
996+ AppEvent . trigger ( ScriptValueChange , { model, tabid : grant . tabId } ) ;
997+ return resolve ( undefined ) ;
986998 }
987- } else {
988- model . value = value ;
989- }
990999
991- if ( value === undefined ) {
992- this . valueModel . delete ( model . id ) ;
1000+ void this . valueModel . save ( model ) ;
9931001 AppEvent . trigger ( ScriptValueChange , { model, tabid : grant . tabId } ) ;
994- return resolve ( undefined ) ;
1002+ resolve ( undefined ) ;
9951003 }
996-
997- this . valueModel . save ( model ) ;
998- AppEvent . trigger ( ScriptValueChange , { model, tabid : grant . tabId } ) ;
999- resolve ( undefined ) ;
1004+ void hanlder ( ) ;
10001005 } )
10011006 }
10021007
@@ -1021,7 +1026,8 @@ export class BackgroundGrant {
10211026 regex = regex . replace ( '*' , '(?:^|.*?)' )
10221027 }
10231028 regex = regex . replace ( / \/ / g, '\\/' ) ;
1024- ret += `if(/${ regex } /.test(url)){return "${ val . proxyServer . scheme ?. toUpperCase ( ) || 'HTTP' } ${ val . proxyServer . host } ` + ( val . proxyServer . port ? ':' + val . proxyServer . port : '' ) + '"}\n' ;
1029+ ret += `if(/${ regex } /.test(url)){return "${ val . proxyServer . scheme ?. toUpperCase ( ) || 'HTTP' } ${ val . proxyServer . host } ` +
1030+ ( val . proxyServer . port ? ':' + val . proxyServer . port . toString ( ) : '' ) + '"}\n' ;
10251031 } ) ;
10261032 } ) ;
10271033 }
@@ -1052,7 +1058,7 @@ export class BackgroundGrant {
10521058 } )
10531059 protected CAT_setProxy ( grant : Grant , post : IPostMessage ) : Promise < any > {
10541060 return new Promise ( resolve => {
1055- BackgroundGrant . proxyRule . set ( grant . id , grant . params [ 0 ] ) ;
1061+ BackgroundGrant . proxyRule . set ( grant . id , < CAT_Types . ProxyRule [ ] > grant . params [ 0 ] ) ;
10561062 App . Log . Debug ( 'background' , 'enable proxy' , grant . name ) ;
10571063 chrome . proxy . settings . set ( {
10581064 value : {
@@ -1102,6 +1108,7 @@ export class BackgroundGrant {
11021108 button : 'left' ,
11031109 clickCount : 1
11041110 } , ( result ) => {
1111+ console . log ( result ) ;
11051112 } ) ;
11061113 } ) ;
11071114 } else {
@@ -1120,6 +1127,7 @@ export class BackgroundGrant {
11201127 button : 'left' ,
11211128 clickCount : 1
11221129 } , ( result ) => {
1130+ console . log ( result ) ;
11231131 } ) ;
11241132 } ) ;
11251133 } ) ;
@@ -1130,18 +1138,18 @@ export class BackgroundGrant {
11301138 }
11311139
11321140 protected static textarea : HTMLElement = document . createElement ( 'textarea' ) ;
1133- public static clipboardData : any ;
1141+ public static clipboardData : { type ?: string , data : string } | undefined ;
11341142
11351143 @BackgroundGrant . GMFunction ( {
11361144 listener : ( ) => {
11371145 document . body . appendChild ( BackgroundGrant . textarea ) ;
11381146 document . addEventListener ( 'copy' , ( e : ClipboardEvent ) => {
1139- if ( ! BackgroundGrant . clipboardData ) {
1147+ if ( ! BackgroundGrant . clipboardData || ! e . clipboardData ) {
11401148 return ;
11411149 }
11421150 e . preventDefault ( ) ;
11431151 const { type, data } = BackgroundGrant . clipboardData ;
1144- ( < any > e ) . clipboardData . setData ( type || 'text/plain' , data ) ;
1152+ e . clipboardData . setData ( type || 'text/plain' , data ) ;
11451153 BackgroundGrant . clipboardData = undefined ;
11461154 } )
11471155 }
0 commit comments