fix: improve timeout handling and update descriptions for clarity

This commit is contained in:
Mara 2025-11-07 00:29:38 +01:00
parent 63dd5ede96
commit 75412fb721
5 changed files with 14 additions and 8 deletions

View file

@ -171,7 +171,11 @@ export class ColorCompiler {
folder: TFolder,
fileExplorer = this.getFileExplorerView()
) {
if (!fileExplorer) {
if (
!fileExplorer ||
!fileExplorer.containerEl ||
fileExplorer.containerEl.getAttr("data-type") === "undefined"
) {
console.warn("File explorer view not found");
return;
}
@ -181,10 +185,10 @@ export class ColorCompiler {
);
let timeout = 0;
const maxTimeout = this.getTimeout() || 50;
const maxTimeout = this.getTimeout();
while (treeItems.length === 0 && timeout < maxTimeout) {
// biome-ignore lint/correctness/noUndeclaredVariables: sleep is a global function in obsidian
await sleep(100);
await sleep(10);
treeItems = fileExplorer.containerEl.querySelectorAll(
`.tree-item.nav-folder > .nav-folder-title[data-path="${folder.path}"]`
);

View file

@ -49,7 +49,7 @@
"explain": "Globally, the plugin will loop until it found the node at {{- code}}.",
"invalid": "Please set a valid number",
"mobile": "Mobile",
"mobileDesc": "It will take {{- calc}}s until it will stop searching node.",
"mobileDesc": "It will take {{- calc}}s until it will stop searching node. Also, it allows to wait for the explorer to be ready.",
"reload": "Requires reloading Obsidian or the plugin.",
"title": "Timeout"
},

View file

@ -49,7 +49,7 @@
"explain": "Globalement, le plugin effectuera une boucle jusqu'à ce qu'il trouve le nœud à {{- code}}.",
"invalid": "Please set a valid number",
"mobile": "Mobile",
"mobileDesc": "Il faudra {{- calc}} secondes avant que la recherche du nœud s'arrête.",
"mobileDesc": "Il faudra {{- calc}} secondes avant que la recherche du nœud s'arrête. Cela permet aussi d'attendre que l'explorateur soit prêt.",
"reload": "Nécessite un rechargement d'Obsidian ou du plugin.",
"title": "Timeout"
},

View file

@ -55,6 +55,8 @@ export default class SimpleColoredFolder extends Plugin {
);
}
const folders = this.compiler.getFolder();
// biome-ignore lint/correctness/noUndeclaredVariables: sleep is a global function in obsidian
if (this.app.isMobile) await sleep(this.settings.maxTimeout.mobile);
await this.compiler.injectDataPath(folders);
await this.compiler.injectStyles(true, folders);
this.app.vault.on("create", async (file) => {

View file

@ -51,7 +51,7 @@ export class SimpleColoredFolderSettingTab extends PluginSettingTab {
const timeOutdesc = sanitizeHTMLToDom(
`${i18next.t("settings.timeout.desc")}<br/>${i18next.t("settings.timeout.explain", {
code: "<code>timeout*100ms</code>",
code: "<code>timeout*10ms</code>",
})}<br>${i18next.t("settings.timeout.reload")}`
);
@ -65,7 +65,7 @@ export class SimpleColoredFolderSettingTab extends PluginSettingTab {
.setDesc(
sanitizeHTMLToDom(
`${i18next.t("settings.timeout.mobileDesc", {
calc: `<code>${(this.settings.maxTimeout.mobile * 100) / 1000}s</code>`,
calc: `<code>${(this.settings.maxTimeout.mobile * 10) / 1000}s</code>`,
})}`
)
)
@ -95,7 +95,7 @@ export class SimpleColoredFolderSettingTab extends PluginSettingTab {
.setDesc(
sanitizeHTMLToDom(
`${i18next.t("settings.timeout.mobileDesc", {
calc: `<code>${(this.settings.maxTimeout.desktop * 100) / 1000}s</code>`,
calc: `<code>${(this.settings.maxTimeout.desktop * 10) / 1000}s</code>`,
})}`
)
)