Oliver-Akins / file-hider

A plugin for https://obsidian.md that allows hiding specific files and folders from the file explorer.
MIT License
60 stars 12 forks source link

Shows all hidden files and folders upon Obsidian restart + have to toggle the command twice for it to work #21

Closed raisabelatrix closed 1 year ago

raisabelatrix commented 1 year ago

Plugin Version

1.1.0

Obsidian Version

0.15.9

Affected Platforms

Windows

Expected Behaviour

  1. I set a file/folder to be hidden
  2. I toggle on File Hider once
  3. Files/folders are automatically hidden
  4. Files/folders remain hidden even after restarting Obsidian

Actual Behaviour

  1. After every Obsidian launch, I see all the hidden files and folders again
  2. Have to toggle the File Hider command via command palette. Toggling it once won't work. I have to do it twice
  3. Files/folders are hidden
  4. After restarting Obsidian, hidden files/folders are shown again

Steps to Reproduce

  1. Hide a file/folder
  2. Restart Obsidian
  3. See supposedly hidden file/folder
  4. Right-clicking to hide it again won't work because context menu will only show "unhide folder/file"
  5. Toggle the File Hider command twice
  6. File/folder is finally hidden
  7. Restart Obsidian and the file/folder automatically unhides
Lennon-ruthven commented 1 year ago

Same issue, but using Obsidian ver. 0.16.2

tprotopopescu commented 1 year ago

Same issue too on Linux with Obsidian 0.15.9

tuberbacon commented 1 year ago

Same issue on Windows 10, Obsidian 1.0.0

ChiaraSand commented 1 year ago

Same issue with macOS 12.6, File Hider 1.1.0, Obsidian 1.0.0 (also had this issue in previous Obsidian versions)

KennethRamsey commented 1 year ago

same issue, i believe it started doing this for me after i enabled File & Links > Detect All Extensions. i could be wrong about that.

janbaykara commented 1 year ago

Same here. macOS + Version 1.1.9 (Installer 1.1.8)

leroycharles commented 1 year ago

Same issue, under Ubuntu 22.04.1LTS, Obsidian 1.1.9, File Hider 1.1.0 Bug can be 'corrected' if File & Links > Detect All Extensions is disable. @KennethRamsey @raisabelatrix

KennethRamsey commented 1 year ago

sorry @leroycharles but that does not fix the issue for me. I'm on windows 10.

jess1k commented 1 year ago

I think I've found the issue. When the plugin loads and changePathVisibility is called for every hidden path, the Files plugin sidebar dom nodes aren't loaded yet.

This was probably introduced in the latest version, as the plugin now uses inline styles rather than a stylesheet, where this would be no problem at all.

A temporary fix is to sleep a few milliseconds before invoking this.app.workspace.onLayoutReady, allowing the Files core plugin to load.

So, for everyone who just wants the plugin to work: open .obsidian/plugins/OA-file-hider/main.js in your vault and add the following line before the this.app.workspace.onLayoutReady call (l. 191): yield sleep(1000); and reopen your vault.

If that doesn't work, try increasing the number of milliseconds; it just increases the delay when the files are hidden on vault open.

tuberbacon commented 1 year ago

So, for everyone who just wants the plugin to work: open .obsidian/plugins/OA-file-hider/main.js in your vault and add the following line before the this.app.workspace.onLayoutReady call (l. 191): yield sleep(1000); and reopen your vault.

I tried out this solution. With a sleep of 1500 the hidden files do stay hidden after a restart, so your conclusion is right. Unfortunately this introduces another, possibly worse, bug: in any other subsequent launch of Obsidian every file and folder under Files is completely gone (not deleted, just not showing up) and will only reappear after deleting the new yield sleep(1500); line and rolling back to the original main.js.

Tested on Obsidian 1.1.9 on Windows 10

jess1k commented 1 year ago

I tried out this solution. With a sleep of 1500 the hidden files do stay hidden after a restart, so your conclusion is right. Unfortunately this introduces another, possibly worse, bug: in any other subsequent launch of Obsidian every file and folder under Files is completely gone (not deleted, just not showing up) and will only reappear after deleting the new yield sleep(1500); line and rolling back to the original main.js.

Tested on Obsidian 1.1.9 on Windows 10

When you look at the source code, what you're describing makes absolutely no sense; all it does is defer the plugin load.

For me it works perfectly, on Obsidian 1.1.9 on macOS 13.1.

You could try to reproduce this on a clean vault; perhaps another plugin or theme is interfering here.

tprotopopescu commented 1 year ago

This works for me too, on Obsidian 1.1.9 and Linux, opensuse 15.4

I did encounter a small side issue: I was trying out theMAKE.md plugin, and while this solution worked to hide folders in the make.md file list it did not hide them in the core file explorer. When I disable the make.md plugin this works as expected.

jess1k commented 1 year ago

@Oliver-Akins If I revert to 9d24a134e1fa6a9cf7dd8da68328eb5b432438bc (prior to the implementation of inline-styles), the following issues appear to be resolved:

Would you accept a PR in which we return to a stylesheet-based solution, because I believe that using a MutationObserver here to keep the inline-styles would not only make it more complex, but I'm also not sure if it would solve #23.

jess1k commented 1 year ago

I did encounter a small side issue: I was trying out theMAKE.md plugin, and while this solution worked to hide folders in the make.md file list it did not hide them in the core file explorer. When I disable the make.md plugin this works as expected.

Try changing let n = document.querySelector(`[data-path="${path}"]`); (l. 130) to let n = document.querySelector(`.nav-folder-children [data-path="${path}"]`);

This should limit this plugin to the core file explorer.

Oliver-Akins commented 1 year ago

@jess1k Yeah, I'm open to PRs if anyone wants to submit them and then I can publish release(s) as needed

tprotopopescu commented 1 year ago

I did encounter a small side issue: I was trying out theMAKE.md plugin, and while this solution worked to hide folders in the make.md file list it did not hide them in the core file explorer. When I disable the make.md plugin this works as expected.

Try changing let n = document.querySelector(`[data-path="${path}"]`); (l. 130) to let n = document.querySelector(`.nav-folder-children [data-path="${path}"]`);

This should limit this plugin to the core file explorer.

Thank you very much for this! This works to hide the file in the file explorer.

I have now noticed that files do not stay hidden. After some time files and folders that are hidden at startup have reappeared. I haven't yet managed to pin down if it something I am doing or if it just happens after some amount of time has passed.

snattack commented 1 year ago

Can confirm this is an issue on all my systems: two different macOS Monterey (one Intel, one M1) and Windows 10, using the same vault. Files are unhidden upon restart. Triggering the command twice hides them.

I currently only use this for hiding _resource-folders.

KosmosisDire commented 1 year ago

Replacing the whole onLayoutReady block on line 191 with this works much more consistently and is basically instantaneous. No need to worry about waiting for 1 or 2 seconds for things to hide or load.

this.app.workspace.onLayoutReady(() => {
  setTimeout(() => {
    for (const path of this.settings.hiddenList) {
      changePathVisibility(path, this.settings.hidden);
    }
  }, 0);
});
tprotopopescu commented 1 year ago

Thanks, this works much faster, but it only hides things that would be visible when Obsidian loads. For instance I use the plugin to hide some sub-folders of a folder. If the folder would be expanded when Obsidian opens the sub-folders are hidden. But if the folder is collapsed when Obsidian opens and I expand it after the sub-folders that should be hidden are visible.

Oliver-Akins commented 1 year ago

This has been implemented by @KosmosisDire and a new release has been published (1.1.1)

marsvet commented 1 year ago

I think this bug is still present because I am still experiencing it.

KosmosisDire commented 1 year ago

There is still a bug affecting folders that are nested in root folders. Folders on the first level work fine.