Skip to content

Commit

Permalink
fixing unloading bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Caffa committed Dec 11, 2024
1 parent 15d02fe commit 40408ef
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ data.json
.DS_Store

release.zip
.aider*
.env
2 changes: 1 addition & 1 deletion current-folder-notes/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion current-folder-notes/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
31 changes: 12 additions & 19 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
});



Expand All @@ -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);
}
}

Expand Down
28 changes: 28 additions & 0 deletions prepareForGitReleaseNreplace.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 40408ef

Please sign in to comment.