fix: rename timeout settings to maxTimeout and migrate old settings

This commit is contained in:
Mara 2025-11-07 00:09:02 +01:00
parent bc32dce1b0
commit 50a6a82ed4
4 changed files with 20 additions and 15 deletions

View file

@ -157,8 +157,8 @@ export class ColorCompiler {
}
private getTimeout() {
if (this.app.isMobile) return this.settings.timeout.mobile;
return this.settings.timeout.desktop;
if (this.app.isMobile) return this.settings.maxTimeout.mobile;
return this.settings.maxTimeout.desktop;
}
private getFileExplorerView() {
@ -181,13 +181,10 @@ export class ColorCompiler {
);
let timeout = 0;
const maxTimeout = this.getTimeout() || 50; // valeur par défaut
const maxTimeout = this.getTimeout() || 50;
while (treeItems.length === 0 && timeout < maxTimeout) {
// Attendre un peu avant de réessayer
// biome-ignore lint/correctness/noUndeclaredVariables: sleep is a global function in obsidian
await sleep(100);
treeItems = fileExplorer.containerEl.querySelectorAll(
`.tree-item.nav-folder > .nav-folder-title[data-path="${folder.path}"]`
);

View file

@ -16,7 +16,7 @@ export interface SimpleColoredFolderSettings {
* See the first part of the style.css file for more information.
*/
includeStyleInExport: boolean;
timeout: {
maxTimeout: {
mobile: number;
desktop: number;
};
@ -52,7 +52,7 @@ export const DEFAULT_SETTINGS: SimpleColoredFolderSettings = {
exportToCSS: false,
defaultColors: DEFAULT_COLORS,
includeStyleInExport: false,
timeout: {
maxTimeout: {
mobile: 1000,
desktop: 1000,
},

View file

@ -16,6 +16,7 @@ export default class SimpleColoredFolder extends Plugin {
async onload() {
console.log(`[${this.manifest.name}] Loaded`);
await this.loadSettings();
await this.migrateSettings();
//load i18next
await i18next.init({
lng: translationLanguage,
@ -75,7 +76,6 @@ export default class SimpleColoredFolder extends Plugin {
}
async loadSettings() {
const loadedData = await this.loadData();
if (loadedData.timeout instanceof Number) delete loadedData.timeout;
try {
this.settings = merge(
DEFAULT_SETTINGS,
@ -91,4 +91,12 @@ export default class SimpleColoredFolder extends Plugin {
async saveSettings() {
await this.saveData(this.settings);
}
async migrateSettings() {
if ("timeout" in this.settings) {
console.warn("[Simple colored folder] Migrating settings: removing timeout");
delete (this.settings as any)["timeout"];
await this.saveSettings();
}
}
}

View file

@ -65,16 +65,16 @@ export class SimpleColoredFolderSettingTab extends PluginSettingTab {
.setDesc(
sanitizeHTMLToDom(
`${i18next.t("settings.timeout.mobileDesc", {
calc: `<code>${(this.settings.timeout.mobile * 100) / 1000}s</code>`,
calc: `<code>${(this.settings.maxTimeout.mobile * 100) / 1000}s</code>`,
})}`
)
)
.addText((text) => {
text.setValue(this.settings.timeout.mobile.toString());
text.setValue(this.settings.maxTimeout.mobile.toString());
text.inputEl.onblur = async () => {
const value = parseInt(text.getValue(), 10);
if (!isNaN(value)) {
this.settings.timeout.mobile = value;
this.settings.maxTimeout.mobile = value;
await this.plugin.saveSettings();
//remove the error class if present
text.inputEl.classList.remove("spf-error");
@ -95,18 +95,18 @@ export class SimpleColoredFolderSettingTab extends PluginSettingTab {
.setDesc(
sanitizeHTMLToDom(
`${i18next.t("settings.timeout.mobileDesc", {
calc: `<code>${(this.settings.timeout.desktop * 100) / 1000}s</code>`,
calc: `<code>${(this.settings.maxTimeout.desktop * 100) / 1000}s</code>`,
})}`
)
)
.setClass("no-border")
.setClass("left")
.addText((text) => {
text.setValue(this.settings.timeout.desktop.toString());
text.setValue(this.settings.maxTimeout.desktop.toString());
text.inputEl.onblur = async () => {
const value = parseInt(text.getValue(), 10);
if (!isNaN(value)) {
this.settings.timeout.desktop = value;
this.settings.maxTimeout.desktop = value;
await this.plugin.saveSettings();
//remove the error class if present
text.inputEl.classList.remove("spf-error");