Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme not being saved upon close/open #8

Closed
justanothercell opened this issue Mar 12, 2023 · 9 comments · Fixed by #43
Closed

Theme not being saved upon close/open #8

justanothercell opened this issue Mar 12, 2023 · 9 comments · Fixed by #43
Assignees
Labels
hacktoberfest ui-bug Bugs/non-working functions in the user interface

Comments

@justanothercell
Copy link

theme resets every time i open

@Spydr06 Spydr06 added the ui-bug Bugs/non-working functions in the user interface label Jun 22, 2023
@toadkarter
Copy link
Contributor

Hi there, I would be happy to take a look at this one if it's still available - if the issue could be assigned to me that would be great.

@Spydr06
Copy link
Owner

Spydr06 commented Oct 1, 2023

sure, thanks for your interest!

@toadkarter
Copy link
Contributor

@Spydr06 Just wanted to check how you wanted to approach this. Basically the way I see it, this bug is caused by two issues:

  • There is currently no way to save a user config, and thus persist settings between sessions; and
  • the GAction for changing the theme is currently automatically initialised on start up with "System Preferences" by default.

For each of the issues I would propose the following:

Saving

I think it should be straightforward enough to add some sort of json / yml config file with the relevant enum that the user wishes to choose for their theme.

I think you are using some form of json for the saved layouts so I think it makes sense to continue using json here? Also, just wanted to check if you had a preference as to where this config should be saved - maybe at the root of the install.

Loading

This one is a little trickier because the logic for selecting a theme is quite closely coupled with the UI code (i.e., gaction_change_theme takes in a SimpleAction parameter and is initialised with default values in the ACTIONS array).

What we can do is extract some of the logic from "gaction_change_theme" into a more generic function called "change_theme", and have "gaction_change_theme" call this - then, in the intialise method of "Application" we can call "change_theme" without having to pass in a SimpleAction, which as far as I can see is a UI specific thing.

The only question remains for me is where the UI value is initialised - because I have tried doing this locally with a hard-coded value and while the theme did change, the UI dropdown was still set to "System Preference". If you could let me know where in the code I could go to change this that would be much appreciated!

Let me know if you are happy with the above approach and I can get cracking on it!

@Spydr06
Copy link
Owner

Spydr06 commented Oct 1, 2023

Yes that's how I'd implement it too it too @toadkarter

  • Saving: json sounds good, since we're, as you already noticed, using it for the .lrsproj and .lrsmod files. toml, which is the Rust-default for stuff like this might be a little sleeker (?), but I think json is perfectly fine.
  • Loading: you have to change the default value in this line, this changes the initial button state. The ACTIONS array is in a lazy_static!{} block, so you can actually add a callback to the settings there and also load the file if not done already

@toadkarter
Copy link
Contributor

Apols for the late reply - yes that all sounds good, I'm working away at it now :)

@Spydr06
Copy link
Owner

Spydr06 commented Oct 1, 2023

@toadkarter awesome, I'm looking forward to it. Have fun :D

@toadkarter
Copy link
Contributor

@Spydr06 I've just finished up the serialization / deserialization part of this task and am moving onto saving / loading the actual theme. I just had two quick questions on this.

  1. Would you recall where the initial default theme is actually being loaded in the project? I tried modifying the value in the ACTIONS array but it doesn't seem like it's having an effect.
  2. Earlier you mentioned that there was a way of adding a callback to the ACTIONS array, where would this go did you mean setup_gactions?

Thanks in advance for your help!

@Spydr06
Copy link
Owner

Spydr06 commented Oct 5, 2023

  1. The standard field in ACTIONS only affects the button state, you have to change the theme itself separately. The theme is "System Preference" by default with ibadwaita.

  2. Since ACTIONS is lazy_static!, this means that it is only evaluated once it's actually used at runtime. This way you can add whatever function you want to get the initial button state (that's what I meant with "callback"). But setup_gactions isn't a bad place either.

@toadkarter
Copy link
Contributor

Excellent, thanks! I will give this a go now

toadkarter added a commit to toadkarter/logicrs that referenced this issue Oct 8, 2023
author toadkarter <vrakhmanin1@gmail.com> 1696714738 +0100
committer toadkarter <vrakhmanin1@gmail.com> 1696751330 +0100

parent 3b28ab6
author toadkarter <vrakhmanin1@gmail.com> 1696714738 +0100
committer toadkarter <vrakhmanin1@gmail.com> 1696751324 +0100

# This is the 1st commit message:

Adds serialized settings file that saves theme state.

# This is the commit message Spydr06#2:

#Adding functionality for saving theme to config file.

# This is the commit message Spydr06#3:

#Loading custom theme if a new window has been created.

# This is the commit message Spydr06#4:

#Setting initial radio button state to what is in the settings when loading Theme.

# This is the commit message Spydr06#5:

#Changing settings file to save in the OS specific config directory.

# This is the commit message Spydr06#6:

#Adding Fedora dependencies to Readme.

# This is the commit message Spydr06#7:

#adding code of conduct

# This is the commit message Spydr06#8:

#edit code of conduct

# This is the commit message Spydr06#9:

#edit code of conduct

# This is the commit message Spydr06#10:

#chore: made Rust CI workflow
# This is the commit message Spydr06#11:

#added explanatory comments to rust_ci.yml
# This is the commit message Spydr06#12:

#updated checkout action

# This is the commit message Spydr06#13:

#used official cargo deny action

# This is the commit message Spydr06#14:

#use nightly toolchain

# This is the commit message Spydr06#15:

#Update INSTALL.md
# This is the commit message Spydr06#16:

#Bump version number
# This is the commit message Spydr06#17:

#Bump version number to `0.1.2`
# This is the commit message Spydr06#18:

#new examples

# This is the commit message Spydr06#19:

#Add macos install instructions
# This is the commit message Spydr06#20:

#ci: added libadwaita build steps to get CI jobs working

# This is the commit message Spydr06#21:

#added nsi script

# This is the commit message Spydr06#22:

#changed directories

# This is the commit message Spydr06#23:

#added relative path

# This is the commit message Spydr06#24:

#Delete nsi script directory
# This is the commit message Spydr06#25:

#Implement mux and demux

# This is the commit message Spydr06#26:

#add docs for mux, demux

# This is the commit message Spydr06#27:

#cargo fmt

#fix clippy issues

encoder decoder examples

fix CI issues with `cargo audit` and `cargo deny`

improve rendering of connection being drawn

add d flip flop, d latch, fix t flip flop

Fix examples, add q and !q to flip flops

Add docs for flip flops

run cargo fmt

fix macos shortcuts

Update README.md

cmd+backspace for deletion on mac

Add build instructions for libadwaita

Fixing up imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest ui-bug Bugs/non-working functions in the user interface
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants