ecustic / obsidian-file-color

An Obsidian plugin for setting colors on folders and files in the file tree.
MIT License
122 stars 9 forks source link

Simple Fix for switching Workplaces #26

Open k0hacuu opened 10 months ago

k0hacuu commented 10 months ago

Simple Fix for switching Workplaces

I started using this plugin recently and really liked how it looked. I also wanted to use the homepage plugin with workspaces but found that when switching to different workspaces the colors go away. This is the issue described in #21 and #7 I've never used javascript before but wanted to see if I could do something. I noticed when I change a color on the palette in settings after switching to a different workspace the colors worked again.

Code

I looked in src/modules/SettingsPanel/index.tsx and saw that when saving, plugin.saveSettings() and plugin.generateColorStyles() were being run. I added these to the layout change event and everything works. I then realised the settings don't need (and should not be) saved when the workplace switches, and just using generateColorStyles() was enough.

Changes:

I added this.generateColorStyles() to this.app.workspace.on('layout-change', ...) event.

Compatibility

Tested with the homepage plugin and the workspace plus plugin. Tested using below folder structure with Cascade Colors and Color Background turned on. color-file-fix

This is my first pull request, any feedback is appreciated :smile:

rol4400 commented 10 months ago

Tested it, works well

Steven8Tang commented 6 months ago

Found this happened again in the updates version. May I know if there is similar?

GuyNoirPI713 commented 5 months ago

I apologize if this is a simple question but I have absolutely no experience coding and don't know where to paste this, but I really want to fix my file color plugin. I'm on a windows if that helps at all. I see the src/plugin... in the commit. is that a reference to what you happened to name your own vault. I figured if I have to edit anything it'll be in the plugins folder. When I find the file color folder I don't see a .ts file just some json files, the css, and the javascript file and I'm completely lost where to paste that code into the script file if that's what I'm looking for.

Ragnik01 commented 5 months ago

@GuyNoirPI713 Since my coding experience is also basically non-existent take this with a grain of salt, but I got it to work by manually editing the code. In the plugins folder (where you found the .json files) you open the main.js file and Ctrl+F for 'layout-change'. That should only give you one result and point you in the right place. Then you can edit the code based on the difference as seen here:

https://github.com/ecustic/obsidian-file-color/pull/26/files

Hope that helps. :)