@@ -14,7 +14,9 @@ import { proxyUpdateRunStatus } from "../offscreen/client";
1414import { BgExecScriptWarp } from "../content/exec_warp" ;
1515import ExecScript , { ValueUpdateData } from "../content/exec_script" ;
1616import { getStorageName } from "@App/pkg/utils/utils" ;
17- import { EmitEventRequest } from "../service_worker/runtime" ;
17+ import { EmitEventRequest , ScriptLoadInfo } from "../service_worker/runtime" ;
18+ import { CATRetryError } from "../content/exec_warp" ;
19+ import { getMetadataStr , getUserConfigStr } from "@App/pkg/utils/script" ;
1820
1921export class Runtime {
2022 cronJob : Map < string , Array < CronJob > > = new Map ( ) ;
@@ -24,7 +26,7 @@ export class Runtime {
2426 logger : Logger ;
2527
2628 retryList : {
27- script : ScriptRunResouce ;
29+ script : ScriptLoadInfo ;
2830 retryTime : number ;
2931 } [ ] = [ ] ;
3032
@@ -55,7 +57,7 @@ export class Runtime {
5557 } , 5000 ) ;
5658 }
5759
58- joinRetryList ( script : ScriptRunResouce ) {
60+ joinRetryList ( script : ScriptLoadInfo ) {
5961 if ( script . nextruntime ) {
6062 this . retryList . push ( {
6163 script,
@@ -80,13 +82,16 @@ export class Runtime {
8082 if ( this . execScripts . has ( script . uuid ) ) {
8183 await this . disableScript ( script . uuid ) ;
8284 }
85+ const loadScript = script as ScriptLoadInfo ;
86+ loadScript . metadataStr = getMetadataStr ( script . code ) || "" ;
87+ loadScript . userConfigStr = getUserConfigStr ( script . code ) || "" ;
8388 if ( script . type === SCRIPT_TYPE_BACKGROUND ) {
8489 // 后台脚本直接运行起来
85- return this . execScript ( script ) ;
90+ return this . execScript ( loadScript ) ;
8691 } else {
8792 // 定时脚本加入定时任务
8893 await this . stopCronJob ( script . uuid ) ;
89- return this . crontabScript ( script ) ;
94+ return this . crontabScript ( loadScript ) ;
9095 }
9196 }
9297
@@ -103,7 +108,7 @@ export class Runtime {
103108 }
104109
105110 // 执行脚本
106- async execScript ( script : ScriptRunResouce , execOnce ?: boolean ) {
111+ async execScript ( script : ScriptLoadInfo , execOnce ?: boolean ) {
107112 const logger = this . logger . with ( { script : script . uuid , name : script . name } ) ;
108113 if ( this . execScripts . has ( script . uuid ) ) {
109114 // 释放掉资源
@@ -158,7 +163,7 @@ export class Runtime {
158163 return ret ;
159164 }
160165
161- crontabScript ( script : ScriptRunResouce ) {
166+ crontabScript ( script : ScriptLoadInfo ) {
162167 // 执行定时脚本 运行表达式
163168 if ( ! script . metadata . crontab ) {
164169 throw new Error ( script . name + " - 错误的crontab表达式" ) ;
@@ -209,7 +214,7 @@ export class Runtime {
209214 return ! flag ;
210215 }
211216
212- crontabExec ( script : ScriptRunResouce , oncePos : number ) {
217+ crontabExec ( script : ScriptLoadInfo , oncePos : number ) {
213218 if ( oncePos ) {
214219 return ( ) => {
215220 // 没有最后一次执行时间表示之前都没执行过,直接执行
@@ -289,7 +294,10 @@ export class Runtime {
289294 if ( exec ) {
290295 await this . stopScript ( script . uuid ) ;
291296 }
292- return this . execScript ( script , true ) ;
297+ const loadScript = script as ScriptLoadInfo ;
298+ loadScript . metadataStr = getMetadataStr ( script . code ) || "" ;
299+ loadScript . userConfigStr = getUserConfigStr ( script . code ) || "" ;
300+ return this . execScript ( loadScript , true ) ;
293301 }
294302
295303 valueUpdate ( data : ValueUpdateData ) {
0 commit comments