@@ -384,7 +384,7 @@ export class ScriptService {
384384 const logger = this . logger . with ( {
385385 name : script . name ,
386386 uuid : script . uuid ,
387- version : script . metadata . version ! [ 0 ] ,
387+ version : script . metadata . version ?. [ 0 ] || "0.0" ,
388388 upsertBy,
389389 } ) ;
390390 let update = false ;
@@ -803,15 +803,8 @@ export class ScriptService {
803803 logger . error ( "parse metadata failed" ) ;
804804 return false ;
805805 }
806- const newVersion = metadata . version && metadata . version [ 0 ] ;
807- if ( ! newVersion ) {
808- logger . error ( "parse version failed" , { version : metadata . version } ) ;
809- return false ;
810- }
811- let oldVersion = script . metadata . version && script . metadata . version [ 0 ] ;
812- if ( ! oldVersion ) {
813- oldVersion = "0.0.0" ;
814- }
806+ const newVersion = metadata . version ?. [ 0 ] || "0.0" ;
807+ const oldVersion = script . metadata . version ?. [ 0 ] || "0.0" ;
815808 // 对比版本大小
816809 if ( ltever ( newVersion , oldVersion ) ) {
817810 return false ;
@@ -902,7 +895,8 @@ export class ScriptService {
902895 }
903896
904897 shouldIgnoreUpdate ( script : Script , newMeta : Partial < Record < string , string [ ] > > | null ) {
905- return script . ignoreVersion === newMeta ?. version ?. [ 0 ] ;
898+ const newVersion = newMeta ?. version ?. [ 0 ] ;
899+ return typeof newVersion === "string" && script . ignoreVersion === newVersion ;
906900 }
907901
908902 // 用于定时自动检查脚本更新
@@ -1139,7 +1133,6 @@ export class ScriptService {
11391133 }
11401134
11411135 requestCheckUpdate ( uuid : string ) {
1142- // src/pages/options/routes/ScriptList.tsx
11431136 return this . checkUpdateAvailable ( uuid ) . then ( ( script ) => {
11441137 if ( script ) {
11451138 // 如有更新则打开更新画面进行更新
@@ -1148,56 +1141,15 @@ export class ScriptService {
11481141 }
11491142 return false ;
11501143 } ) ;
1151-
1152- // 没有空值 case
1153- /*
1154- if (uuid) {
1155- return this.checkUpdateAvailable(uuid).then((script) => {
1156- if (script) {
1157- // 如有更新则打开更新画面进行更新
1158- this.openUpdatePage(script, "user");
1159- return true;
1160- }
1161- return false;
1162- });
1163- } else {
1164- // 批量检查更新
1165- InfoNotification("检查更新", "正在检查所有的脚本更新");
1166- this.scriptDAO
1167- .all()
1168- .then(async (scripts) => {
1169- // 检查是否有更新
1170- const results = await this.checkUpdatesAvailable(
1171- scripts.map((script) => script.uuid),
1172- {
1173- MIN_DELAY: 300,
1174- MAX_DELAY: 800,
1175- }
1176- );
1177- return Promise.all(
1178- scripts.map((script, i) => {
1179- const result = results[i];
1180- if (result) {
1181- // 如有更新则打开更新画面进行更新
1182- this.openUpdatePage(script, "user");
1183- }
1184- })
1185- );
1186- })
1187- .then(() => {
1188- InfoNotification("检查更新", "所有脚本检查完成");
1189- });
1190- return Promise.resolve(true); // 无视检查结果,立即回传true
1191- }
1192- */
11931144 }
11941145
11951146 isInstalled ( { name, namespace } : { name : string ; namespace : string } ) : Promise < App . IsInstalledResponse > {
1147+ // 用於 window.external
11961148 return this . scriptDAO . findByNameAndNamespace ( name , namespace ) . then ( ( script ) => {
11971149 if ( script ) {
11981150 return {
11991151 installed : true ,
1200- version : script . metadata . version && script . metadata . version [ 0 ] ,
1152+ version : script . metadata . version ?. [ 0 ] || "0.0" ,
12011153 } as App . IsInstalledResponse ;
12021154 }
12031155 return { installed : false } as App . IsInstalledResponse ;
0 commit comments