stop assuming leftRibbon is always there
This commit is contained in:
1 parent
2cbc29c4e9
commit
afe4707c5a
1 file changed
+15
-4
@@ -25,12 +25,21 @@ module.exports = class RibbonOrderLock extends Plugin {
|
|||||||
|
|
||||||
onunload() {
|
onunload() {
|
||||||
this.observer?.disconnect();
|
this.observer?.disconnect();
|
||||||
this.app.workspace.leftRibbon.onChange = this.originalOnChange;
|
const ribbon = this.getRibbon();
|
||||||
|
if (ribbon) {
|
||||||
|
ribbon.onChange = this.originalOnChange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getRibbon() {
|
||||||
|
return this.app.workspace.leftRibbon ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
observeRibbon() {
|
observeRibbon() {
|
||||||
const ribbon = this.app.workspace.leftRibbon;
|
const ribbon = this.getRibbon();
|
||||||
|
if (!ribbon) return;
|
||||||
const containerEl = ribbon.ribbonItemsEl;
|
const containerEl = ribbon.ribbonItemsEl;
|
||||||
|
if (!containerEl) return;
|
||||||
|
|
||||||
this.observer = new MutationObserver(() => this.debouncedEnforce());
|
this.observer = new MutationObserver(() => this.debouncedEnforce());
|
||||||
this.observer.observe(containerEl, { childList: true });
|
this.observer.observe(containerEl, { childList: true });
|
||||||
@@ -39,7 +48,8 @@ module.exports = class RibbonOrderLock extends Plugin {
|
|||||||
// hook the ribbon's own onChange so drags and hide/show toggles update
|
// hook the ribbon's own onChange so drags and hide/show toggles update
|
||||||
// our saved order automatically, same as Obsidian's native reorder does
|
// our saved order automatically, same as Obsidian's native reorder does
|
||||||
patchRibbon() {
|
patchRibbon() {
|
||||||
const ribbon = this.app.workspace.leftRibbon;
|
const ribbon = this.getRibbon();
|
||||||
|
if (!ribbon) return;
|
||||||
|
|
||||||
const original = ribbon.onChange.bind(ribbon);
|
const original = ribbon.onChange.bind(ribbon);
|
||||||
this.originalOnChange = original;
|
this.originalOnChange = original;
|
||||||
@@ -53,7 +63,8 @@ module.exports = class RibbonOrderLock extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enforceOrder() {
|
enforceOrder() {
|
||||||
const ribbon = this.app.workspace.leftRibbon;
|
const ribbon = this.getRibbon();
|
||||||
|
if (!ribbon) return;
|
||||||
|
|
||||||
const order = this.settings.order;
|
const order = this.settings.order;
|
||||||
if (order.length === 0) {
|
if (order.length === 0) {
|
||||||
|
|||||||
Reference in new issue
Block a user