fix: obsidian return null after opening
Adding a little sleep (50ms) to wait for the dom after opening obsidian
This commit is contained in:
parent
90ae7b0041
commit
858173e980
1 changed files with 17 additions and 16 deletions
33
src/main.ts
33
src/main.ts
|
|
@ -7,7 +7,7 @@ import { changePathVisibility } from './utils';
|
||||||
interface FileHiderSettings {
|
interface FileHiderSettings {
|
||||||
hidden: boolean;
|
hidden: boolean;
|
||||||
hiddenList: string[];
|
hiddenList: string[];
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
export default class FileHider extends Plugin {
|
export default class FileHider extends Plugin {
|
||||||
|
|
@ -20,7 +20,6 @@ export default class FileHider extends Plugin {
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
|
|
||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
this.app.workspace.on(`file-menu`, (menu, file) => {
|
this.app.workspace.on(`file-menu`, (menu, file) => {
|
||||||
if (file instanceof TFolder) {
|
if (file instanceof TFolder) {
|
||||||
|
|
@ -39,34 +38,36 @@ export default class FileHider extends Plugin {
|
||||||
this.settings.hiddenList.push(file.path);
|
this.settings.hiddenList.push(file.path);
|
||||||
this.saveSettings();
|
this.saveSettings();
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
menu.addItem((i) => {
|
menu.addItem((i) => {
|
||||||
if (this.settings.hiddenList.includes(file.path)) {
|
if (this.settings.hiddenList.includes(file.path)) {
|
||||||
i.setTitle(`Unhide File`)
|
i.setTitle(`Unhide File`)
|
||||||
.setIcon(`eye`)
|
.setIcon(`eye`)
|
||||||
.onClick((e) => {
|
.onClick(() => {
|
||||||
this.unhidePath(file.path);
|
this.unhidePath(file.path);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
i.setTitle(`Hide File`)
|
i.setTitle(`Hide File`)
|
||||||
.setIcon(`eye-off`)
|
.setIcon(`eye-off`)
|
||||||
.onClick((e) => {
|
.onClick(() => {
|
||||||
changePathVisibility(file.path, this.settings.hidden);
|
changePathVisibility(file.path, this.settings.hidden);
|
||||||
this.settings.hiddenList.push(file.path);
|
this.settings.hiddenList.push(file.path);
|
||||||
this.saveSettings();
|
this.saveSettings();
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this.app.workspace.onLayoutReady(() => {
|
|
||||||
|
this.app.workspace.onLayoutReady( async () => {
|
||||||
|
await sleep(50)
|
||||||
for (const path of this.settings.hiddenList) {
|
for (const path of this.settings.hiddenList) {
|
||||||
changePathVisibility(path, this.settings.hidden);
|
await changePathVisibility(path, this.settings.hidden);
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
new VisibilityToggleCommand(this);
|
new VisibilityToggleCommand(this);
|
||||||
|
|
@ -88,19 +89,19 @@ export default class FileHider extends Plugin {
|
||||||
/*
|
/*
|
||||||
Enables/Disables the file visibility based. (gets the stylesheet if needed)
|
Enables/Disables the file visibility based. (gets the stylesheet if needed)
|
||||||
*/
|
*/
|
||||||
toggleVisibility() {
|
async toggleVisibility() {
|
||||||
this.settings.hidden = !this.settings.hidden;
|
this.settings.hidden = !this.settings.hidden;
|
||||||
for (const path of this.settings.hiddenList) {
|
for (const path of this.settings.hiddenList) {
|
||||||
changePathVisibility(path, this.settings.hidden);
|
changePathVisibility(path, this.settings.hidden);
|
||||||
};
|
}
|
||||||
this.saveSettings();
|
await this.saveSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
unhidePath(path: string) {
|
async unhidePath(path: string) {
|
||||||
let i = this.settings.hiddenList.indexOf(path);
|
let i = this.settings.hiddenList.indexOf(path);
|
||||||
this.settings.hiddenList.splice(i, 1);
|
this.settings.hiddenList.splice(i, 1);
|
||||||
changePathVisibility(path, false);
|
changePathVisibility(path, false);
|
||||||
this.saveSettings();
|
await this.saveSettings();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -123,4 +124,4 @@ class FileHiderSettingsTab extends PluginSettingTab {
|
||||||
VisibilityToggleSetting.create(this.plugin, container);
|
VisibilityToggleSetting.create(this.plugin, container);
|
||||||
ManageHiddenPaths.create(this.plugin, container);
|
ManageHiddenPaths.create(this.plugin, container);
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue