Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
feat: Support refreshing on workspace load
Browse files Browse the repository at this point in the history
  • Loading branch information
pjeby authored and kometenstaub committed Jul 1, 2022
1 parent 9b533c2 commit 659ed5e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"cross-env": "^7.0.3",
"css-minify": "^2.0.0",
"esbuild": "0.14.3",
"monkey-around": "^2.3.0",
"obsidian": "^0.14.8",
"prettier": "2.5.1",
"sass": "^1.49.9",
Expand Down
18 changes: 16 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Platform, Plugin, WorkspaceLeaf } from 'obsidian';
import { Platform, Plugin, Workspace, WorkspaceLeaf } from 'obsidian';
import { around } from "monkey-around";
import type {
baseButton,
enabledButton,
Expand All @@ -20,6 +21,12 @@ import {
} from './utils';
import { lucideIcons } from './lucide';

declare module "obsidian" {
interface Workspace {
onLayoutChange(): void // tell plugins the layout changed
}
}

const DEFAULT_SETTINGS: TopBarButtonsSettings = {
enabledButtons: [],
desktop: false,
Expand Down Expand Up @@ -186,6 +193,13 @@ export default class TopBarButtonsPlugin extends Plugin {
});

if (Platform.isMobile || this.settings.desktop) {
const self = this;
this.register(around(Workspace.prototype, {
changeLayout(old) { return async function changeLayout(this: Workspace, ws: any){
await old.call(this, ws);
self.addButtonsToAllLeaves();
}}
}));
this.registerEvent(
this.app.workspace.on('file-open', () => {
const activeLeaf = app.workspace.getLeaf(false);
Expand All @@ -211,7 +225,7 @@ export default class TopBarButtonsPlugin extends Plugin {

addButtonsToAllLeaves() {
app.workspace.iterateAllLeaves(leaf => this.addButtonsToLeaf(leaf));
(app.workspace as any).onLayoutChange();
app.workspace.onLayoutChange();
}

addButtonsToLeaf(leaf: WorkspaceLeaf) {
Expand Down

0 comments on commit 659ed5e

Please sign in to comment.