|
1 | 1 | import type { App } from "obsidian"; |
2 | | -import { PluginSettingTab } from "obsidian"; |
| 2 | +import { Notice, PluginSettingTab } from "obsidian"; |
| 3 | +import { log } from "src/logger"; |
3 | 4 | import type BreadcrumbsPlugin from "src/main"; |
4 | 5 | import { mount, unmount } from "svelte"; |
5 | 6 | import EdgeFieldSettings from "../components/settings/EdgeFieldSettings.svelte"; |
@@ -60,13 +61,50 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { |
60 | 61 | display(): void { |
61 | 62 | const { containerEl, plugin } = this; |
62 | 63 |
|
63 | | - for (const c of this.components) void unmount(c); |
| 64 | + const old_components = this.components; |
64 | 65 | this.components = []; |
65 | 66 |
|
66 | | - containerEl.empty(); |
| 67 | + void Promise.all(old_components.map((c) => unmount(c))).catch( |
| 68 | + (error) => { |
| 69 | + log.error("BreadcrumbsSettingTab.unmount threw >", error); |
| 70 | + }, |
| 71 | + ); |
67 | 72 |
|
| 73 | + containerEl.empty(); |
68 | 74 | containerEl.addClass("BC-settings-tab"); |
69 | 75 |
|
| 76 | + try { |
| 77 | + this._build(containerEl, plugin); |
| 78 | + } catch (error) { |
| 79 | + log.error("BreadcrumbsSettingTab.display threw >", error); |
| 80 | + new Notice( |
| 81 | + "Breadcrumbs: failed to render settings tab. See developer console and report at https://github.com/SkepticMystic/breadcrumbs/issues", |
| 82 | + ); |
| 83 | + |
| 84 | + containerEl.empty(); |
| 85 | + containerEl.addClass("BC-settings-tab"); |
| 86 | + |
| 87 | + const fallback = containerEl.createDiv({ cls: "p-4" }); |
| 88 | + fallback.createEl("h3", { |
| 89 | + text: "Breadcrumbs settings failed to load", |
| 90 | + }); |
| 91 | + fallback.createEl("p", { |
| 92 | + text: String( |
| 93 | + (error as Error)?.stack ?? |
| 94 | + (error as Error)?.message ?? |
| 95 | + error, |
| 96 | + ), |
| 97 | + cls: "text-muted", |
| 98 | + }); |
| 99 | + |
| 100 | + const retry = fallback.createEl("button", { |
| 101 | + text: "Reload settings", |
| 102 | + }); |
| 103 | + retry.onclick = () => this.display(); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + private _build(containerEl: HTMLElement, plugin: BreadcrumbsPlugin): void { |
70 | 108 | this.components.push( |
71 | 109 | mount(EdgeFieldSettings, { |
72 | 110 | props: { plugin }, |
@@ -215,7 +253,13 @@ export class BreadcrumbsSettingTab extends PluginSettingTab { |
215 | 253 | hide() { |
216 | 254 | void this.plugin.flushPendingSettings(); |
217 | 255 |
|
218 | | - for (const c of this.components) void unmount(c); |
| 256 | + const old_components = this.components; |
219 | 257 | this.components = []; |
| 258 | + |
| 259 | + void Promise.all(old_components.map((c) => unmount(c))).catch( |
| 260 | + (error) => { |
| 261 | + log.error("BreadcrumbsSettingTab.unmount threw >", error); |
| 262 | + }, |
| 263 | + ); |
220 | 264 | } |
221 | 265 | } |
0 commit comments