mirror of
https://github.com/sean2077/obsidian-dynamic-theme-background.git
synced 2026-07-22 06:44:57 +00:00
fix: resolve ESLint errors for Obsidian plugin validation
- Fix floating promises by adding void operator (20 locations) - Change console.log to console.debug (2 locations) - Remove unnecessary async keywords from methods without await - Fix async/await issues in modal callbacks - Update all API provider deinit() methods to return Promise.resolve() - Change Vault.delete() to FileManager.trashFile() - Remove unnecessary escape characters in regex - Configure ESLint v9 flat config with eslint-plugin-obsidianmd - Delete legacy .eslintrc and .eslintignore files All Required errors from Obsidian validation bot have been fixed.
This commit is contained in:
parent
8dc60046a7
commit
d3663dc7bc
20 changed files with 3015 additions and 279 deletions
|
|
@ -1,3 +0,0 @@
|
|||
node_modules/
|
||||
|
||||
main.js
|
||||
23
.eslintrc
23
.eslintrc
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"env": { "node": true },
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"no-prototype-builtins": "off",
|
||||
"@typescript-eslint/no-empty-function": "off"
|
||||
}
|
||||
}
|
||||
25
eslint.config.js
Normal file
25
eslint.config.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// eslint.config.js
|
||||
import obsidianmd from "eslint-plugin-obsidianmd";
|
||||
import tsParser from "@typescript-eslint/parser";
|
||||
|
||||
export default [
|
||||
{
|
||||
files: ["**/*.ts"],
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
parserOptions: {
|
||||
project: "./tsconfig.json",
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
obsidianmd,
|
||||
},
|
||||
rules: {
|
||||
// The recommended rules from eslint-plugin-obsidianmd
|
||||
...obsidianmd.configs.recommended,
|
||||
|
||||
// Override: 降低 UI sentence case 的严格程度,因为表情符号会导致误报
|
||||
"obsidianmd/ui/sentence-case": ["warn", { enforceCamelCaseLower: false }],
|
||||
},
|
||||
},
|
||||
];
|
||||
3057
package-lock.json
generated
3057
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -3,10 +3,13 @@
|
|||
"version": "2.8.3",
|
||||
"description": "A plugin for Obsidian that dynamically changes the background based on time of day and user settings.",
|
||||
"main": "main.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs",
|
||||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
||||
"fmt": "prettier --write src/**/*.ts",
|
||||
"lint": "eslint src --ext .ts",
|
||||
"lint:fix": "eslint src --ext .ts --fix",
|
||||
"lint:css": "stylelint \"**/*.css\"",
|
||||
"fix:css": "stylelint \"**/*.css\" --fix"
|
||||
},
|
||||
|
|
@ -14,18 +17,21 @@
|
|||
"author": "",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.3.1",
|
||||
"@types/node": "^24.7.2",
|
||||
"@typescript-eslint/eslint-plugin": "^8.46.0",
|
||||
"@typescript-eslint/parser": "^8.42.0",
|
||||
"all-contributors-cli": "^6.26.1",
|
||||
"builtin-modules": "^5.0.0",
|
||||
"esbuild": "^0.25.10",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-obsidianmd": "^0.1.8",
|
||||
"obsidian": "latest",
|
||||
"prettier": "latest",
|
||||
"stylelint": "^16.25.0",
|
||||
"stylelint-config-idiomatic-order": "^10.0.0",
|
||||
"stylelint-config-recommended": "^17.0.0",
|
||||
"stylelint-config-standard": "^39.0.1",
|
||||
"stylelint-config-idiomatic-order": "^10.0.0",
|
||||
"stylelint-order": "^7.0.0",
|
||||
"tslib": "^2.5.0",
|
||||
"typescript": "^5.9.3"
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export function createNextBackgroundCommand(plugin: DynamicThemeBackgroundPlugin
|
|||
plugin.settings.currentIndex = (plugin.settings.currentIndex + 1) % plugin.settings.backgrounds.length;
|
||||
plugin.background = plugin.settings.backgrounds[plugin.settings.currentIndex];
|
||||
plugin.updateStyleCss();
|
||||
plugin.saveSettings();
|
||||
void plugin.saveSettings();
|
||||
new Notice(
|
||||
t("command_next_bg_notice", {
|
||||
bgName: plugin.background.name,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ export function createOpenSettingsCommand(plugin: DynamicThemeBackgroundPlugin):
|
|||
id: "open-dtb-settings-tab",
|
||||
name: t("command_open_settings_tab_name"),
|
||||
callback: () => {
|
||||
plugin.activateView();
|
||||
void plugin.activateView();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export function createToggleCommand(plugin: DynamicThemeBackgroundPlugin): Comma
|
|||
name: t("command_toggle_name"),
|
||||
callback: () => {
|
||||
plugin.settings.enabled = !plugin.settings.enabled;
|
||||
plugin.saveSettings();
|
||||
void plugin.saveSettings();
|
||||
|
||||
if (plugin.settings.enabled) {
|
||||
plugin.startBackgroundManager();
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ export class BackgroundModal extends Modal {
|
|||
.setLimits(0, 30, 1)
|
||||
.setDynamicTooltip()
|
||||
.setValue(this.blurDepth ?? this.bgItem.blurDepth ?? this.plugin.settings.blurDepth)
|
||||
.onChange(async (value: number) => {
|
||||
.onChange((value: number) => {
|
||||
this.blurDepth = value;
|
||||
})
|
||||
)
|
||||
|
|
@ -175,7 +175,7 @@ export class BackgroundModal extends Modal {
|
|||
button
|
||||
.setIcon("reset")
|
||||
.setTooltip(t("reset_blur_tooltip"))
|
||||
.onClick(async () => {
|
||||
.onClick(() => {
|
||||
// 清空每背景覆盖,让其回退到全局
|
||||
this.blurDepth = undefined;
|
||||
this.bgItem.blurDepth = undefined as any;
|
||||
|
|
@ -191,7 +191,7 @@ export class BackgroundModal extends Modal {
|
|||
.setLimits(0, 1.5, 0.01)
|
||||
.setDynamicTooltip()
|
||||
.setValue(this.brightness4Bg ?? this.bgItem.brightness4Bg ?? this.plugin.settings.brightness4Bg)
|
||||
.onChange(async (value: number) => {
|
||||
.onChange((value: number) => {
|
||||
this.brightness4Bg = value;
|
||||
})
|
||||
)
|
||||
|
|
@ -199,7 +199,7 @@ export class BackgroundModal extends Modal {
|
|||
button
|
||||
.setIcon("reset")
|
||||
.setTooltip(t("reset_brightness_tooltip"))
|
||||
.onClick(async () => {
|
||||
.onClick(() => {
|
||||
// 清空每背景覆盖,让其回退到全局
|
||||
this.brightness4Bg = undefined;
|
||||
this.bgItem.brightness4Bg = undefined as any;
|
||||
|
|
@ -215,7 +215,7 @@ export class BackgroundModal extends Modal {
|
|||
.setLimits(0, 2, 0.01)
|
||||
.setDynamicTooltip()
|
||||
.setValue(this.saturate4Bg ?? this.bgItem.saturate4Bg ?? this.plugin.settings.saturate4Bg)
|
||||
.onChange(async (value: number) => {
|
||||
.onChange((value: number) => {
|
||||
this.saturate4Bg = value;
|
||||
})
|
||||
)
|
||||
|
|
@ -223,7 +223,7 @@ export class BackgroundModal extends Modal {
|
|||
button
|
||||
.setIcon("reset")
|
||||
.setTooltip(t("reset_saturate_tooltip"))
|
||||
.onClick(async () => {
|
||||
.onClick(() => {
|
||||
// 清空每背景覆盖,让其回退到全局
|
||||
this.saturate4Bg = undefined;
|
||||
this.bgItem.saturate4Bg = undefined as any;
|
||||
|
|
@ -237,7 +237,7 @@ export class BackgroundModal extends Modal {
|
|||
overlayRow.addColorPicker((picker) =>
|
||||
picker
|
||||
.setValue(this.bgColorDark ?? this.bgItem.bgColorDark ?? this.plugin.settings.bgColorDark)
|
||||
.onChange(async (value: string) => {
|
||||
.onChange((value: string) => {
|
||||
this.bgColorDark = value;
|
||||
})
|
||||
);
|
||||
|
|
@ -248,7 +248,7 @@ export class BackgroundModal extends Modal {
|
|||
.setValue(
|
||||
this.bgColorOpacityDark ?? this.bgItem.bgColorOpacityDark ?? this.plugin.settings.bgColorOpacityDark
|
||||
)
|
||||
.onChange(async (value: number) => {
|
||||
.onChange((value: number) => {
|
||||
this.bgColorOpacityDark = value;
|
||||
})
|
||||
);
|
||||
|
|
@ -257,7 +257,7 @@ export class BackgroundModal extends Modal {
|
|||
overlayRow.addColorPicker((picker) =>
|
||||
picker
|
||||
.setValue(this.bgColorLight ?? this.bgItem.bgColorLight ?? this.plugin.settings.bgColorLight)
|
||||
.onChange(async (value: string) => {
|
||||
.onChange((value: string) => {
|
||||
this.bgColorLight = value;
|
||||
})
|
||||
);
|
||||
|
|
@ -270,7 +270,7 @@ export class BackgroundModal extends Modal {
|
|||
this.bgItem.bgColorOpacityLight ??
|
||||
this.plugin.settings.bgColorOpacityLight
|
||||
)
|
||||
.onChange(async (value: number) => {
|
||||
.onChange((value: number) => {
|
||||
this.bgColorOpacityLight = value;
|
||||
})
|
||||
);
|
||||
|
|
@ -278,7 +278,7 @@ export class BackgroundModal extends Modal {
|
|||
button
|
||||
.setIcon("reset")
|
||||
.setTooltip(t("reset_bg_mask_color_tooltip"))
|
||||
.onClick(async () => {
|
||||
.onClick(() => {
|
||||
// 清空每背景遮罩覆盖,让其回退到全局
|
||||
this.bgColorDark = undefined;
|
||||
this.bgColorOpacityDark = undefined;
|
||||
|
|
@ -318,7 +318,7 @@ export class BackgroundModal extends Modal {
|
|||
);
|
||||
dropdown
|
||||
.setValue(this.bgSize ?? this.bgItem.bgSize ?? this.plugin.settings.bgSize)
|
||||
.onChange(async (value: "cover" | "contain" | "auto" | "intelligent") => {
|
||||
.onChange((value: "cover" | "contain" | "auto" | "intelligent") => {
|
||||
this.bgSize = value;
|
||||
});
|
||||
|
||||
|
|
@ -328,7 +328,7 @@ export class BackgroundModal extends Modal {
|
|||
button
|
||||
.setIcon("reset")
|
||||
.setTooltip(t("reset_bg_size_tooltip"))
|
||||
.onClick(async () => {
|
||||
.onClick(() => {
|
||||
// 清空每背景覆盖,让其回退到全局
|
||||
this.bgSize = undefined;
|
||||
this.bgItem.bgSize = undefined as any;
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ export function confirm(app: App, message: string): Promise<boolean> {
|
|||
return new Promise((resolve) => {
|
||||
new ConfirmModal(app, {
|
||||
message,
|
||||
onConfirm: async () => resolve(true),
|
||||
onCancel: async () => resolve(false),
|
||||
onConfirm: () => resolve(true),
|
||||
onCancel: () => resolve(false),
|
||||
}).open();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
apiManager.createApi(apiConfig);
|
||||
}
|
||||
|
||||
console.log("Dynamic Theme Background plugin loaded");
|
||||
console.debug("Dynamic Theme Background plugin loaded");
|
||||
}
|
||||
|
||||
onunload() {
|
||||
|
|
@ -73,7 +73,7 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
// 清理所有注册的API实例(包括状态管理器中的所有订阅)
|
||||
apiManager.deleteAllApis();
|
||||
|
||||
console.log("Dynamic Theme Background plugin unloaded");
|
||||
console.debug("Dynamic Theme Background plugin unloaded");
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
|
|
@ -99,7 +99,7 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
} else {
|
||||
// 如果不存在,则创建新的 leaf
|
||||
const leaf = this.app.workspace.getLeaf("tab");
|
||||
await leaf.setViewState({
|
||||
void leaf.setViewState({
|
||||
type: DTB_SETTINGS_VIEW_TYPE,
|
||||
active: true,
|
||||
});
|
||||
|
|
@ -125,19 +125,19 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
this.statusBar.setText("🌈 DTB");
|
||||
this.statusBar.addClass("dtb-status-bar");
|
||||
this.statusBar.setAttribute("title", t("status_bar_title"));
|
||||
this.statusBar.addEventListener("click", async (evt) => {
|
||||
this.statusBar.addEventListener("click", (evt) => {
|
||||
if (evt.button === 0) {
|
||||
await this.applyRandomWallpaper();
|
||||
void this.applyRandomWallpaper();
|
||||
}
|
||||
});
|
||||
this.statusBar.addEventListener("auxclick", async (evt) => {
|
||||
this.statusBar.addEventListener("auxclick", (evt) => {
|
||||
if (evt.button === 1) {
|
||||
await this.activateView();
|
||||
void this.activateView();
|
||||
}
|
||||
});
|
||||
this.statusBar.addEventListener("contextmenu", async (evt) => {
|
||||
this.statusBar.addEventListener("contextmenu", (evt) => {
|
||||
evt.preventDefault();
|
||||
await this.saveBackground();
|
||||
void this.saveBackground();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
}
|
||||
|
||||
// 立即执行一次更新
|
||||
this.updateBackground(true);
|
||||
void this.updateBackground(true);
|
||||
|
||||
if (this.settings.mode === "time-based") {
|
||||
// 时段模式:使用 setTimeout,计算到下一个时段的时间
|
||||
|
|
@ -178,8 +178,8 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
// 间隔模式:使用 setInterval
|
||||
const intervalMs = this.settings.intervalMinutes * 60000;
|
||||
this.intervalId = this.registerInterval(
|
||||
window.setInterval(async () => {
|
||||
await this.updateBackground(false);
|
||||
window.setInterval(() => {
|
||||
void this.updateBackground(false);
|
||||
}, intervalMs)
|
||||
);
|
||||
|
||||
|
|
@ -195,7 +195,7 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
}
|
||||
|
||||
// 时段规则下的背景更新循环,通过 setTimeout 实现
|
||||
async startTimeBasedManager() {
|
||||
startTimeBasedManager(): void {
|
||||
const scheduleNext = () => {
|
||||
const nextRuleChange = this.getNextRuleChangeTime();
|
||||
if (nextRuleChange) {
|
||||
|
|
@ -204,8 +204,8 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
// 确保延迟时间为正数,最少1秒
|
||||
const actualDelay = Math.max(delay, 1000);
|
||||
|
||||
this.timeoutId = window.setTimeout(async () => {
|
||||
await this.updateBackground(false);
|
||||
this.timeoutId = window.setTimeout(() => {
|
||||
void this.updateBackground(false);
|
||||
// 此处应该刷新设置页中的时间规则列表
|
||||
this.refreshActiveTimeRules();
|
||||
scheduleNext(); // 递归调度下一个时段
|
||||
|
|
@ -219,8 +219,8 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
} else {
|
||||
// 如果没有下一个时段,24小时后重新检查
|
||||
this.timeoutId = window.setTimeout(
|
||||
async () => {
|
||||
await this.updateBackground(false);
|
||||
() => {
|
||||
void this.updateBackground(false);
|
||||
scheduleNext();
|
||||
},
|
||||
24 * 60 * 60 * 1000
|
||||
|
|
@ -270,7 +270,7 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
// API失败时回退到本地背景
|
||||
this.settings.currentIndex = (this.settings.currentIndex + 1) % this.settings.backgrounds.length;
|
||||
this.background = this.settings.backgrounds[this.settings.currentIndex];
|
||||
this.saveSettings();
|
||||
void this.saveSettings();
|
||||
needsUpdate = true;
|
||||
}
|
||||
break;
|
||||
|
|
@ -385,7 +385,7 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
}
|
||||
|
||||
// 异步加载图片并更新尺寸
|
||||
this.loadImageAndUpdateSize(resourcePath, screenRatio);
|
||||
void this.loadImageAndUpdateSize(resourcePath, screenRatio);
|
||||
|
||||
return "contain"; // 默认返回contain,异步更新后会重新渲染
|
||||
} catch (error) {
|
||||
|
|
@ -522,7 +522,7 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
}
|
||||
|
||||
// 默认图片名为 bg.name + .jpg , 并规范化路径 移除禁止的字符: \ / : * ? " < > |
|
||||
const imageName = bg.name.replace(/[\\\/:\*\?"<>\|]/g, "_") + ".jpg";
|
||||
const imageName = bg.name.replace(/[\\/:*?"<>|]/g, "_") + ".jpg";
|
||||
const localPath = `${folderPath}/${imageName}`;
|
||||
|
||||
// 判断路径是否存在,如果存在,由用户确定是否覆盖
|
||||
|
|
@ -545,7 +545,7 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
|
||||
// 如果需要覆盖,则先删除旧文件
|
||||
if (file) {
|
||||
await this.app.vault.delete(file);
|
||||
await this.app.fileManager.trashFile(file);
|
||||
}
|
||||
await this.app.vault.createBinary(localPath, arrayBuffer);
|
||||
|
||||
|
|
@ -586,7 +586,7 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
loadingNotice.hide();
|
||||
|
||||
if (!wallpaperImages || wallpaperImages.length === 0) {
|
||||
console.warn(`DTB: No images returned from API: ${selectedApi.getName}`);
|
||||
console.warn(`DTB: No images returned from API: ${selectedApi.getName()}`);
|
||||
return null;
|
||||
}
|
||||
const randomImage = wallpaperImages[Math.floor(Math.random() * wallpaperImages.length)];
|
||||
|
|
@ -634,7 +634,7 @@ export default class DynamicThemeBackgroundPlugin extends Plugin {
|
|||
if (bg.remoteUrl) {
|
||||
// 这里恢复备份, 按理在这做不太合适
|
||||
bg.value = bg.remoteUrl;
|
||||
this.saveSettings(); // 保存设置
|
||||
void this.saveSettings(); // 保存设置
|
||||
return `url("${bg.remoteUrl}")`;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -156,13 +156,13 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
button
|
||||
.setIcon("refresh-cw")
|
||||
.setTooltip(t("reload_plugin_tooltip"))
|
||||
.onClick(async () => {
|
||||
.onClick(() => {
|
||||
// 重新启动背景管理器
|
||||
if (this.plugin.settings.enabled) {
|
||||
this.plugin.startBackgroundManager();
|
||||
}
|
||||
// 强制更新当前背景
|
||||
this.plugin.updateBackground(true);
|
||||
void this.plugin.updateBackground(true);
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -442,13 +442,13 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
.addButton((button) => {
|
||||
button.setButtonText(t("clear_time_rules_button"));
|
||||
button.setTooltip(t("clear_time_rules_tooltip"));
|
||||
button.onClick(async () => {
|
||||
button.onClick(() => {
|
||||
new ConfirmModal(this.app, {
|
||||
message: t("confirm_clear_time_rules"),
|
||||
onConfirm: async () => {
|
||||
onConfirm: () => {
|
||||
this.plugin.settings.timeRules = [];
|
||||
this.plugin.startBackgroundManager(); // 重新启动背景管理器以应用更改
|
||||
await this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
this.displayModeSettings();
|
||||
},
|
||||
}).open();
|
||||
|
|
@ -457,10 +457,10 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
.addButton((button) => {
|
||||
button.setButtonText(t("reset_time_rules_button"));
|
||||
button.setTooltip(t("reset_time_rules_tooltip"));
|
||||
button.onClick(async () => {
|
||||
button.onClick(() => {
|
||||
this.plugin.settings.timeRules = this.defaultSettings.timeRules;
|
||||
this.plugin.startBackgroundManager(); // 重新启动背景管理器以应用更改
|
||||
await this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
this.displayModeSettings();
|
||||
});
|
||||
});
|
||||
|
|
@ -570,20 +570,20 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
},
|
||||
});
|
||||
|
||||
return dropdown.setValue(rule.backgroundId).onChange(async (value) => {
|
||||
return dropdown.setValue(rule.backgroundId).onChange((value) => {
|
||||
rule.backgroundId = value;
|
||||
await this.plugin.saveSettings();
|
||||
this.plugin.updateBackground(true);
|
||||
void this.plugin.saveSettings();
|
||||
void this.plugin.updateBackground(true);
|
||||
});
|
||||
})
|
||||
.addButton((button) =>
|
||||
button.setButtonText(t("button_edit")).onClick(() => this.showTimeRuleModal(rule))
|
||||
)
|
||||
.addButton((button) =>
|
||||
button.setButtonText(t("button_delete")).onClick(async () => {
|
||||
button.setButtonText(t("button_delete")).onClick(() => {
|
||||
this.plugin.settings.timeRules = this.plugin.settings.timeRules.filter((r) => r.id !== rule.id);
|
||||
this.plugin.startBackgroundManager(); // 重新启动背景管理器以应用更改
|
||||
await this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
this.displayTimeRules();
|
||||
})
|
||||
);
|
||||
|
|
@ -674,7 +674,7 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
});
|
||||
valueInput.oninput = () => {
|
||||
this.plugin.settings.localBackgroundFolder = valueInput.value;
|
||||
this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
};
|
||||
const browseButton = imageFolderInputContainer.createEl("button", {
|
||||
type: "button",
|
||||
|
|
@ -685,7 +685,7 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
const modal = new ImageFolderSuggestModal(this.app, (imagePath: string) => {
|
||||
valueInput.value = imagePath;
|
||||
this.plugin.settings.localBackgroundFolder = imagePath;
|
||||
this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
});
|
||||
modal.open();
|
||||
};
|
||||
|
|
@ -723,7 +723,7 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
}
|
||||
|
||||
// 显示添加或编辑背景的模态窗口
|
||||
private async showAddBackgroundModal(type: "image" | "color" | "gradient") {
|
||||
private showAddBackgroundModal(type: "image" | "color" | "gradient"): void {
|
||||
// 创建一个新的背景项,初始值为空
|
||||
const bg: BackgroundItem = {
|
||||
id: "",
|
||||
|
|
@ -755,7 +755,7 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
}
|
||||
|
||||
// 显示编辑背景的模态窗口
|
||||
private async showEditBackgroundModal(bg: BackgroundItem, index: number) {
|
||||
private showEditBackgroundModal(bg: BackgroundItem, index: number): void {
|
||||
const modal = new BackgroundModal(this.app, this.plugin, bg, async (newBg: BackgroundItem) => {
|
||||
if (!newBg.name.trim() || !newBg.value.trim()) {
|
||||
new Notice(t("notice_name_and_value_required"));
|
||||
|
|
@ -922,8 +922,8 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
};
|
||||
|
||||
// 保存按钮
|
||||
actions.createEl("button", { text: t("button_save") }).onclick = async () => {
|
||||
await this.plugin.saveBackground(bg);
|
||||
actions.createEl("button", { text: t("button_save") }).onclick = () => {
|
||||
void this.plugin.saveBackground(bg);
|
||||
};
|
||||
|
||||
// 编辑按钮
|
||||
|
|
@ -932,12 +932,12 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
};
|
||||
|
||||
// 删除按钮
|
||||
actions.createEl("button", { text: t("button_delete") }).onclick = async () => {
|
||||
actions.createEl("button", { text: t("button_delete") }).onclick = () => {
|
||||
// 使用 filter 方法删除
|
||||
this.plugin.settings.backgrounds = this.plugin.settings.backgrounds.filter(
|
||||
(b: BackgroundItem) => b.id !== bg.id
|
||||
);
|
||||
await this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
// 这里仅需刷新背景列表和时间规则列表
|
||||
this.displayBackgrounds();
|
||||
this.displayTimeRules();
|
||||
|
|
@ -1098,7 +1098,7 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
.addExtraButton((button) => {
|
||||
button.setIcon("refresh-cw");
|
||||
button.setTooltip(t("restore_default_apis_tooltip"));
|
||||
button.onClick(async () => {
|
||||
button.onClick(() => {
|
||||
// 重新生成默认设置以获取最新的默认 API
|
||||
const defaultApis = this.defaultSettings.wallpaperApis;
|
||||
|
||||
|
|
@ -1113,7 +1113,7 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
}
|
||||
new Notice(t("restore_default_apis_success"));
|
||||
|
||||
await this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
this.displayWallpaperApiSettings();
|
||||
});
|
||||
});
|
||||
|
|
@ -1280,14 +1280,14 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
})
|
||||
)
|
||||
.addButton((button) =>
|
||||
button.setButtonText(t("button_delete")).onClick(async () => {
|
||||
button.setButtonText(t("button_delete")).onClick(() => {
|
||||
// 删除API实例
|
||||
apiManager.deleteApi(apiConfig.id);
|
||||
// 删除插件设置中的API配置
|
||||
this.plugin.settings.wallpaperApis = this.plugin.settings.wallpaperApis.filter(
|
||||
(api) => api.id !== apiConfig.id
|
||||
);
|
||||
await this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
this.displayWallpaperApis();
|
||||
})
|
||||
);
|
||||
|
|
@ -1315,12 +1315,12 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
params: {},
|
||||
};
|
||||
|
||||
const modal = new WallpaperApiEditorModal(this.app, emptyConfig, async (apiConfig) => {
|
||||
const modal = new WallpaperApiEditorModal(this.app, emptyConfig, (apiConfig) => {
|
||||
// 创建新的API实例
|
||||
apiManager.createApi(apiConfig);
|
||||
// 添加到插件设置中
|
||||
this.plugin.settings.wallpaperApis.push(apiConfig);
|
||||
await this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
// 这里仅需刷新 api 列表
|
||||
this.displayWallpaperApis();
|
||||
});
|
||||
|
|
@ -1330,12 +1330,12 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
|
||||
// 显示编辑壁纸API的模态窗口
|
||||
private showEditWallpaperApiModal(apiConfig: WallpaperApiConfig, index: number) {
|
||||
const modal = new WallpaperApiEditorModal(this.app, apiConfig, async (updatedConfig) => {
|
||||
const modal = new WallpaperApiEditorModal(this.app, apiConfig, (updatedConfig) => {
|
||||
// 有可能api类型也修改了,干脆重新创建API实例覆盖原来的
|
||||
apiManager.createApi(updatedConfig);
|
||||
|
||||
this.plugin.settings.wallpaperApis[index] = updatedConfig;
|
||||
await this.plugin.saveSettings();
|
||||
void this.plugin.saveSettings();
|
||||
// 这里仅需刷新 api 列表
|
||||
this.displayWallpaperApis();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ export class DTBSettingsView extends ItemView {
|
|||
this.settingTab.containerEl = container as HTMLElement;
|
||||
this.settingTab.display();
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async onClose(): Promise<void> {
|
||||
|
|
@ -56,5 +57,6 @@ export class DTBSettingsView extends ItemView {
|
|||
this.settingTab.containerEl.empty();
|
||||
}
|
||||
this.settingTab = null; // 释放引用,帮助垃圾回收
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ export class ApiStateManager {
|
|||
*/
|
||||
notify(apiId: string, state: ApiState): void {
|
||||
// 立即返回,异步执行所有回调以避免阻塞调用者
|
||||
setTimeout(async () => {
|
||||
setTimeout(() => {
|
||||
const callbackPromises: Promise<void>[] = [];
|
||||
|
||||
for (const { subscriber, callback } of this.listeners.values()) {
|
||||
|
|
@ -76,7 +76,7 @@ export class ApiStateManager {
|
|||
|
||||
// 并发执行所有回调,但不等待结果(火后即忘模式)
|
||||
if (callbackPromises.length > 0) {
|
||||
Promise.all(callbackPromises).catch((error) => {
|
||||
void Promise.all(callbackPromises).catch((error) => {
|
||||
console.warn("DTB: Unexpected error in state notification batch:", error);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,9 +116,9 @@ export class CustomApi extends BaseWallpaperApi {
|
|||
}
|
||||
}
|
||||
|
||||
async deinit(): Promise<boolean> {
|
||||
deinit(): Promise<boolean> {
|
||||
if (!this.initialized) {
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
// 清理缓存数据
|
||||
|
|
@ -127,7 +127,7 @@ export class CustomApi extends BaseWallpaperApi {
|
|||
this.currentPage = 1;
|
||||
|
||||
this.initialized = false;
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
async updateImageCache(): Promise<boolean> {
|
||||
|
|
|
|||
|
|
@ -251,9 +251,9 @@ export class PexelsApi extends BaseWallpaperApi {
|
|||
}
|
||||
}
|
||||
|
||||
async deinit(): Promise<boolean> {
|
||||
deinit(): Promise<boolean> {
|
||||
if (!this.initialized) {
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
// 清理缓存数据
|
||||
|
|
@ -262,7 +262,7 @@ export class PexelsApi extends BaseWallpaperApi {
|
|||
this.currentPage = 1;
|
||||
|
||||
this.initialized = false;
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
async updateImageCache(): Promise<boolean> {
|
||||
|
|
|
|||
|
|
@ -333,9 +333,9 @@ export class PixabayApi extends BaseWallpaperApi {
|
|||
}
|
||||
}
|
||||
|
||||
async deinit(): Promise<boolean> {
|
||||
deinit(): Promise<boolean> {
|
||||
if (!this.initialized) {
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
// 清理缓存数据
|
||||
|
|
@ -344,7 +344,7 @@ export class PixabayApi extends BaseWallpaperApi {
|
|||
this.currentPage = 1;
|
||||
|
||||
this.initialized = false;
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
async updateImageCache(): Promise<boolean> {
|
||||
|
|
|
|||
|
|
@ -263,11 +263,11 @@ export class Qihoo360Api extends BaseWallpaperApi {
|
|||
}
|
||||
}
|
||||
|
||||
async deinit(): Promise<boolean> {
|
||||
deinit(): Promise<boolean> {
|
||||
this.initialized = false;
|
||||
this.categoriesCache = [];
|
||||
this.hotSearchCache = [];
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
async updateImageCache(): Promise<boolean> {
|
||||
|
|
|
|||
|
|
@ -246,9 +246,9 @@ export class UnsplashApi extends BaseWallpaperApi {
|
|||
}
|
||||
}
|
||||
|
||||
async deinit(): Promise<boolean> {
|
||||
deinit(): Promise<boolean> {
|
||||
if (!this.initialized) {
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
// 清理缓存数据
|
||||
|
|
@ -257,7 +257,7 @@ export class UnsplashApi extends BaseWallpaperApi {
|
|||
this.currentPage = 1;
|
||||
|
||||
this.initialized = false;
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
async updateImageCache(): Promise<boolean> {
|
||||
|
|
|
|||
|
|
@ -325,9 +325,9 @@ export class WallhavenApi extends BaseWallpaperApi {
|
|||
return true;
|
||||
}
|
||||
|
||||
async deinit(): Promise<boolean> {
|
||||
deinit(): Promise<boolean> {
|
||||
if (!this.initialized) {
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
// 清理缓存数据
|
||||
|
|
@ -336,7 +336,7 @@ export class WallhavenApi extends BaseWallpaperApi {
|
|||
this.currentPage = 1;
|
||||
|
||||
this.initialized = false;
|
||||
return true;
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
async updateImageCache(): Promise<boolean> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue