Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
此 PR 改进了 ScriptCat 扩展的脚本注册状态管理机制。旧代码使用简单的布尔值 registered 来追踪注册状态,无法区分"未注册"、"已注册"和"已反注册"三种不同状态。新代码引入了三态枚举 RuntimeRegisterCode(UNSET/REGISTER_DONE/UNREGISTER_DONE),使状态转换更加清晰准确。
核心改进:
- 引入三态状态机(UNSET、REGISTER_DONE、UNREGISTER_DONE)替代布尔值,准确追踪注册生命周期
- 修正反注册逻辑:UNSET 状态现在也会触发反注册操作,避免浏览器残留未知注册状态的脚本
- 改进注册失败处理:注册失败时状态回退到 UNSET 而非保持错误的 REGISTER_DONE 状态
Changes:
- 用
RuntimeRegisterCode枚举(UNSET/REGISTER_DONE/UNREGISTER_DONE)替代简单布尔值registered - 修正
unregisterUserscripts():当状态为 UNSET 或 REGISTER_DONE 时执行反注册,避免重复调用 - 增强
registerUserscripts()错误处理:追踪注册失败并相应更新状态
Comments suppressed due to low confidence (1)
src/app/service/service_worker/runtime.ts:961
- 当单个脚本注册失败(非重复ID错误)时,应该设置
failed = true,否则最终状态会错误地设置为REGISTER_DONE而不是UNSET。这会导致注册失败的情况没有被正确追踪。建议在 else 分支中添加failed = true;。
} else {
this.logger.error("register error", Logger.E(e));
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
有 userScript 和 scripting 。如果 userScript 失败, registerState则为 UNSET
UNSET 时,需要反注册一下
反注册过才会设为 UNREGISTER_DONE
UNREGISTER_DONE 的话就不会再重覆执行 unregister
注册成功后会设为 REGISTER_DONE
不成功则设回 UNSET
這樣清晰說明了 scriptcat執行了的動作 而非 瀏覽器本身狀態