mortii / anki-morphs

A MorphMan fork rebuilt from the ground up with a focus on simplicity, performance, and a codebase with minimal technical debt.
https://mortii.github.io/anki-morphs/
Mozilla Public License 2.0
58 stars 9 forks source link

Per-profile settings #143

Closed asayake-b5 closed 8 months ago

asayake-b5 commented 8 months ago

First, thank you for your work, I love anki-morphs and all the niceties it has over morphman already.

The only nitpick I’ve had so far is that when switching profiles, I’ve noticed the settings stay the same, which can cause problems and errors when for instance recalculating when the second profile doesn’t have a certain note type. I think, considering how everything else is so well separated between profiles (and considering morphman had no problems with that) that it is an oversight.

On my end I’ve fixed it by importing a deck with the specific note so it’s not a huge deal because my workflow is very simple (sentence bank profile), but I can imagine other people will start being confused or lost at the sight of an error, or have plain old problems if they have eg. per-language profiles

mortii commented 8 months ago

@asayake-b5 Thanks for the feedback!

I've encountered this problem every single day of development when switching between profiles and it has annoyed me every time.

This problem actually occurs because of how Anki stores add-on settings. Each add-on is allocated one config file that stores settings, it's not per user.

https://github.com/mortii/anki-morphs/blob/2c2c8d45582dd5b20ad51282d8dc740a97c8d524/ankimorphs/config.py#L172-L174

I had just accepted it for what it was, but maybe it's possible to create a hacky workaround that could be made profile specific... I'll look into it!

mortii commented 8 months ago

We could potentially use the 'profile_did_open' hook

name="profile_did_open",
legacy_hook="profileLoaded",
doc="""Executed whenever a user profile has been opened

Please note that this hook will also be called on profile switches, so if you
are looking to simply delay an add-on action in a single-shot manner,
`main_window_did_init` is likely the more suitable choice.
""",

and then load a profile specific config with something like:

profile_config = json.load(mw.profileFolder() + am_profile_config.json)
mw.addonManager.writeConfig(__name__, profile_config)

The major concern I have with this is that it might be tricky to keep the 'am_profile_config.json' files in-sync on updates... But that could be fixable, not sure.

I'll look more into this later.

mortii commented 8 months ago

Okay, I think this should be doable, and it's a good upgrade, so I'll add it to the roadmap.

mortii commented 8 months ago

I won't be shocked if this causes some weird bugs, so let me know if you encounter any. I'll release this shortly.

github-actions[bot] commented 7 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.