Skip to content

Commit

Permalink
feat(script): 新增可以设置不被软件配置同步覆盖的设置,修复智慧树学习记录刷新后清空的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Oct 21, 2023
1 parent ea38c69 commit b35f87f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ export interface Config<T extends keyof ConfigTagMap = keyof ConfigTagMap, V = a
/** 在元素上方创建一个分隔元素 */
separator?: string;
onload?: (this: ConfigTagMap[T], el: ConfigElement<T>) => void;
/**
* 额外的数据,可以由程序自定义并解析
*/
extra?: any;
}
30 changes: 25 additions & 5 deletions packages/scripts/src/projects/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const BackgroundProject = Project.create({
show();
}
}),
app: new Script({
appConfigSync: new Script({
name: '🔄️ 软件配置同步',
namespace: 'background.app',
url: [['所有页面', /./]],
Expand Down Expand Up @@ -234,6 +234,22 @@ export const BackgroundProject = Project.create({
}
}

// 排除那些不用同步的配置
for (const project of definedProjects()) {
for (const key in project.scripts) {
if (Object.prototype.hasOwnProperty.call(project.scripts, key)) {
const script = project.scripts[key];
for (const ck in script.configs) {
if (Object.prototype.hasOwnProperty.call(script.configs, ck)) {
if (script.configs[ck].extra.appConfigSync === false) {
Reflect.deleteProperty(res, $.namespaceKey(script.namespace, ck));
}
}
}
}
}
}

// 同步所有的配置
for (const key in res) {
if (Object.prototype.hasOwnProperty.call(res, key)) {
Expand All @@ -242,10 +258,14 @@ export const BackgroundProject = Project.create({
}

// 锁定面板
for (const projects of definedProjects()) {
for (const key in projects.scripts) {
if (Object.prototype.hasOwnProperty.call(projects.scripts, key)) {
const script = projects.scripts[key];
for (const project of definedProjects()) {
// 排除后台脚本的锁定
if (project === BackgroundProject) {
continue;
}
for (const key in project.scripts) {
if (Object.prototype.hasOwnProperty.call(project.scripts, key)) {
const script = project.scripts[key];
const originalRender = script.onrender;
// 重新定义渲染函数。在渲染后添加锁定面板的代码
script.onrender = ({ panel, header }) => {
Expand Down
7 changes: 5 additions & 2 deletions packages/scripts/src/projects/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ export const CommonProject = Project.create({
}
}),
apps: new Script({
name: '📱 其他应用',
name: '📱 拓展应用',
url: [['', /.*/]],
namespace: 'common.apps',
configs: {
Expand All @@ -923,7 +923,10 @@ export const CommonProject = Project.create({
* 题库缓存
*/
localQuestionCaches: {
defaultValue: [] as QuestionCache[]
defaultValue: [] as QuestionCache[],
extra: {
appConfigSync: false
}
}
},
methods() {
Expand Down
5 changes: 4 additions & 1 deletion packages/scripts/src/projects/zhs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ export const ZHSProject = Project.create({
/** 学习时间 */
time: number;
}[];
}[]
}[],
extra: {
appConfigSync: false
}
},
stopTime: {
label: '定时停止',
Expand Down

0 comments on commit b35f87f

Please sign in to comment.