fixing unloading bug

This commit is contained in:
caffae 2024-12-11 14:23:28 +08:00
parent 15d02fea0c
commit 40408efbf4
5 changed files with 44 additions and 21 deletions

2
.gitignore vendored
View file

@ -22,3 +22,5 @@ data.json
.DS_Store
release.zip
.aider*
.env

View file

@ -1,7 +1,7 @@
{
"id": "current-folder-notes-pamphlet",
"name": "Current Folder Notes",
"version": "1.7.1",
"version": "1.7.2",
"minAppVersion": "1.5.11",
"description": "Shows a list of notes in the current folder, and allows you to filter the titles to include or exclude notes.",
"author": "Pamela Wang",

View file

@ -8,7 +8,7 @@
color: var(--text-small);
text-decoration: none;
font-size: var(--font-ui-medium);
font-family: var(--font-interface-theme);
/* font-family: var(--font-interface-theme); */
line-height: var(--line-height-tight);
}

31
main.ts
View file

@ -25,31 +25,14 @@ const DEFAULT_SETTINGS: Partial<CurrentFolderNotesDisplaySettings> = {
export default class CurrentFolderNotesDisplay extends Plugin {
settings: CurrentFolderNotesDisplaySettings;
private leaves: WorkspaceLeaf[] = [];
fileChangeHandler(file: TFile) {
if (file instanceof TFile && file.path === this.file.path) {
this.load();
}
this.panes = []; // Initialize the array in the constructor
// Close all tracked panes when the plugin is unloaded
for (const pane of this.panes) {
if (!pane.isDetached()) {
pane.detach();
}
}
this.panes = []; // Clear the array after closing the panes
// ... existing code ...
}
async onload() {
await this.loadSettings();
// Example of opening a pane and adding it to the panes array
const leaf = this.app.workspace.getLeaf('tab');
await leaf.setViewState({ type: 'markdown' });
this.panes.push(leaf); // Add the pane to the panes array
async onload() {
await this.loadSettings();
@ -103,10 +86,19 @@ export default class CurrentFolderNotesDisplay extends Plugin {
this.refreshView();
}));
// when I switch active files, update the view
// this.registerEvent(this.app.workspace.on('active-leaf-change', async (leaf) => {
// this.refreshView();
// }));
}
onunload() {
console.log('unloading plugin');
this.leaves.forEach(leaf => {
leaf.detach();
});
@ -125,7 +117,8 @@ export default class CurrentFolderNotesDisplay extends Plugin {
// in the right sidebar for it
leaf = workspace.getRightLeaf(false);
if (leaf) {
await leaf.setViewState({ type: VIEW_TYPE_CURRENT_FOLDER_NOTES_DISPLAY, active: true });
await leaf.setViewState({ type: VIEW_TYPE_CURRENT_FOLDER_NOTES_DISPLAY, active: true });
this.leaves.push(leaf);
}
}

View file

@ -0,0 +1,28 @@
# minor version bump
npm version patch
# create the current_release directory if it does not exist
mkdir -p current-folder-notes
# make a copy of the main.js, manifest.json, and styles.css files in another folder
cp main.js current-folder-notes
cp manifest.json current-folder-notes
cp styles.css current-folder-notes
rm -f "/Users/caffae/Notes/Char V4/.obsidian/plugins/Current Folder Notes/main.js"
rm -f "/Users/caffae/Notes/Char V4/.obsidian/plugins/Current Folder Notes/manifest.json"
rm -f "/Users/caffae/Notes/Char V4/.obsidian/plugins/Current Folder Notes/styles.css"
cp main.js "/Users/caffae/Notes/Char V4/.obsidian/plugins/Current Folder Notes"
cp manifest.json "/Users/caffae/Notes/Char V4/.obsidian/plugins/Current Folder Notes"
cp styles.css "/Users/caffae/Notes/Char V4/.obsidian/plugins/Current Folder Notes"
# compress the current_release folder into a zip file
# zip -r release.zip current_release
zip -vr current-folder-notes.zip current-folder-notes -x "*.DS_Store"
mv current-folder-notes.zip release.zip
# remove the current_release folder
# rm -rf current-folder-notes