@@ -159,6 +159,18 @@ export class RuntimeService {
159159 this . deleteScriptMatch ( uuid ) ;
160160 } ) ;
161161
162+ // 监听offscreen环境初始化, 初始化完成后, 再将后台脚本运行起来
163+ this . mq . subscribe ( "preparationOffscreen" , ( ) => {
164+ this . scriptDAO . all ( ) . then ( ( list ) => {
165+ list . forEach ( ( script ) => {
166+ if ( script . type === SCRIPT_TYPE_NORMAL ) {
167+ return ;
168+ }
169+ this . mq . publish ( "enableScript" , { uuid : script . uuid , enable : script . status === SCRIPT_STATUS_ENABLE } ) ;
170+ } ) ;
171+ } ) ;
172+ } ) ;
173+
162174 this . systemConfig . addListener ( "enable_script" , ( enable ) => {
163175 this . isEnableUserscribe = enable ;
164176 if ( enable ) {
@@ -211,18 +223,6 @@ export class RuntimeService {
211223 }
212224
213225 async registerUserscripts ( ) {
214- // 监听offscreen环境初始化, 初始化完成后, 再将后台脚本运行起来
215- this . mq . subscribe ( "preparationOffscreen" , ( ) => {
216- this . scriptDAO . all ( ) . then ( ( list ) => {
217- list . forEach ( ( script ) => {
218- if ( script . type === SCRIPT_TYPE_NORMAL ) {
219- return ;
220- }
221- this . mq . publish ( "enableScript" , { uuid : script . uuid , enable : script . status === SCRIPT_STATUS_ENABLE } ) ;
222- } ) ;
223- } ) ;
224- } ) ;
225-
226226 // 将开启的脚本发送一次enable消息
227227 const list = await this . scriptDAO . all ( ) ;
228228 let messageFlag = await this . getMessageFlag ( ) ;
0 commit comments