Skip to content

Conversation

@theoforger
Copy link

Fixes #122.

Description

This PR implements the feature to import, export and reset settings, which can be accessed through the new buttons inside the preference page:

image

Implementation

  • The new class SettingsExport is responsible for all tasks related to this feature.
  • A list of excluded keys are defined. These keys are irrelevant to settings export.

Export

  1. Run dconf dump in a subprocess: code
  2. Remove keys in the excluded list: code
  3. Save to file: code

Reset

  1. Run dconf reset on keys that are not in the excluded list: code

Import

  1. Reset to default: code
    • This makes sure that, if the export file is missing a key, the corresponding option will be set to default
  2. Turn off edge tiling and key binding: code
    • This makes sure the overridden settings are restored back to system before importing anything
  3. Run dconf load: code

Issues/Possible Improvements

  • Due to the workaround used for overridden settings, if the export file is missing the key active-screen-edges or enable-move-keybindings, these two options will remain disabled after import, instead of the default enabled state
  • Choose a specific file extension/suffix for export file

Feedback?

I am still new to coding. Any feedback or advice is appreciated 🙏

@domferr
Copy link
Owner

domferr commented Oct 16, 2024

Hey @theoforger sorry for the late response. Your work is amazing and very well done! Thank you! ⭐
I'm going to use this features for a while to test them! I think this is already well made to land on the next update (not sure if I will name it 13.2 or 14) together with some other features I've implemented in the past weeks.

@domferr
Copy link
Owner

domferr commented Oct 16, 2024

A quick update for you. I just discovered that some of the things you are doing via a subprocess can be done by using a Gio.Setting object. I'm leaving some comments so you know which one can be simplified and made more reliable by avoiding the use of a subprocess

@theoforger
Copy link
Author

Thanks for the review ❤️ ! I'll look into Gio.Setting. It does seem a lot easier than subprocesses.

Just in case you missed it, I left a comment on the issue about some strange behavoir I observed. Let me know if I should file them as a separate issue.

Also, any thoughts on these two?

Issues/Possible Improvements

  • Due to the workaround used for overridden settings, if the export file is missing the key active-screen-edges or enable-move-keybindings, these two options will remain disabled after import, instead of the default enabled state
  • Choose a specific file extension/suffix for export file

@domferr
Copy link
Owner

domferr commented Oct 18, 2024

Thanks for the review ❤️ ! I'll look into Gio.Setting. It does seem a lot easier than subprocesses.

Just in case you missed it, I left a comment on the issue about some strange behavoir I observed. Let me know if I should file them as a separate issue.

Hey thank you! I didn't see you comment there. I left a reply there with all the details, thank you for spotting these bugs!

Choose a specific file extension/suffix for export file

What do you think about a simple .txt file?

Due to the workaround used for overridden settings, if the export file is missing the key active-screen-edges or enable-move-keybindings, these two options will remain disabled after import, instead of the default enabled state

Hmmmm, I'll investigate, hope to understand how to fix this soon!


// Flush overridden settings back into system
Settings.set_active_screen_edges(false);
Settings.set_enable_move_keybindings(false);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Due to the workaround used for overridden settings, if the export file is missing the key active-screen-edges or enable-move-keybindings, these two options will remain disabled after import, instead of the default enabled state

The reason behind this is that, during the import of settings, the settings are reset and then active-screen-edges and enable-move-keybindings are set to false.

I see you want to flush all the overridden settings back into system, you could use SettingsOverride.get().restoreAll()

Copy link
Author

@theoforger theoforger Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate the suggestion!

SettingsOverride.get().restoreAll() works except for one situation: If either of these toggles are enabled both before and after the import, the overridden settings remain restored.

I can think of two solutions:

  • If the state of either is enabled both before and after import:
    a. Apply overrides again (is there a function for this?), or
    b. Toggle it off and on

What do you think?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what do you mean with "the overridden settings remain restored"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of overriden-settings is only populated when you enable the toggle.

In this case, SettingsOverride.get().restoreAll() restores the overridden settings, but it doesn't get populated again since the state of the toggle is unchanged.

Hope that clears things out!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uuuuhhhh! I understand what do you mean...
Thanks a million, I believe that toggling it off and on, as you suggested, could be the best workaround (there isn't a function to override again). Can you put a comment near this workaround to remember these details in the future? Thanks again!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. Will do!

@theoforger
Copy link
Author

I noticed the fallback states for several get functions in src/settings/settings.ts don't match with the default states of the corresponding options. For example, get_enable_move_keybindings falls back to false, while the actual option defaults to enabled if the dconf key enable_move_keybindings is not present.

Is this intentional or an oversight?

Context: I'm trying to use these functions to determine the states before/after import.

@domferr
Copy link
Owner

domferr commented Oct 22, 2024

I noticed the fallback states for several get functions in src/settings/settings.ts don't match with the default states of the corresponding options. For example, get_enable_move_keybindings falls back to false, while the actual option defaults to enabled if the dconf key enable_move_keybindings is not present.

Is this intentional or an oversight?

Context: I'm trying to use these functions to determine the states before/after import.

This was intentional at that time, however there isn't any reason anymore. Because of that, it would be better that the dconf's defaults matches with settings.ts's defaults. Thank you for spotting that!

@theoforger
Copy link
Author

theoforger commented Oct 22, 2024

I just pushed some more code. But the workaround is not working right now. This is getting more complicated than I thought haha.

From my testing, Settings.set_enable_move_keybindings(false) restores overridden-settings back to system just fine, but Settings.set_enable_move_keybindings(true) doesn't populate overridden-settings.

The same goes for screen edges. Toggling it on in the GUI does the trick. It only doesn't work if I use the setter function to enable it.

Edit: Forgot to mention I added these two setter functions myself. Maybe I missed something there 😄

@domferr
Copy link
Owner

domferr commented Oct 22, 2024

Hey thank you! I gave a look at your code and it seems great to me! It's unfortunate you still have that bug 😢

However, considering that I was planning a major release (v14) in the near future I wish to include your amazing changes as well. Because of that, I'm changing the target of your pull request from main to the branch named 13.2 (sorry, at the beginning I thought to do version 13.2 but now I changed my mind to version 14 ahahah)

Can you tell me if you have the same bug? That branch includes the changes made to fix the bugs you spotted, maybe they are related! Thank you once again for this amazing work ❤️

Another question, as much important as the other one: is it ok for you if I cite you and put a link to your GitHub account in the release notes which will include your changes? 😃

Edit: Forgot to mention I added these two setter functions myself. Maybe I missed something there 😄

I looked at them, and you did it perfectly, so the bug is somewhere else 🤔. I'll investigate and come back to you if I have news!

@domferr domferr changed the base branch from main to 13.2 October 22, 2024 17:51
@theoforger
Copy link
Author

Strange. Now I'm getting this error when I try to open the settings page:

ImportError: Unable to load file from: resource:///org/gnome/shell/extensions/extension.js (The resource at “/org/gnome/shell/extensions/extension.js” does not exist)

Stack trace:
  _init/GLib.MainLoop.prototype.runAsync/</<@resource:///org/gnome/gjs/modules/core/overrides/GLib.js:266:34
  

I'm using GNOME 46 on Fedora 40 if that's relevant. And thanks for being patient with me haha 😄

@domferr
Copy link
Owner

domferr commented Oct 23, 2024

Strange. Now I'm getting this error when I try to open the settings page:

ImportError: Unable to load file from: resource:///org/gnome/shell/extensions/extension.js (The resource at “/org/gnome/shell/extensions/extension.js” does not exist)

Stack trace:
  _init/GLib.MainLoop.prototype.runAsync/</<@resource:///org/gnome/gjs/modules/core/overrides/GLib.js:266:34
  

I'm using GNOME 46 on Fedora 40 if that's relevant. And thanks for being patient with me haha 😄

Hey! I'm so sorry, that's my mistake 😢

I fixed this, you should see a new commit in the target branch (13.2)

@theoforger
Copy link
Author

Can you tell me if you have the same bug? That branch includes the changes made to fix the bugs you spotted, maybe they are related! Thank you once again for this amazing work ❤️

I just tested and this bug still exists 😢

Another question, as much important as the other one: is it ok for you if I cite you and put a link to your GitHub account in the release notes which will include your changes? 😃

Of course, I'm okay with it 👍 (Sorry I missed this earlier)

@domferr
Copy link
Owner

domferr commented Oct 23, 2024

Hey, I have good news for you. From my tests, I think I fixed the problem you had!

The idea is the following, when settings are reset:

  1. set to false the settings about keybinding and active screen edges (enable_move_keybindings and active-screen-edges)
  2. restore all the overridden settings. This will revert what was overridden back to the system. At this stage the settings overridden-settings becomes empty
  3. finally reset all the settings. This will trigger all the work needed to override the settings

When settings are imported, resetting will override all the settings as well. If the imported file contains a false value for enable_move_keybindings or active-screen-edges, they are updated and this triggers the update of overridden-settings as well. Thank you for suggesting this idea about "turning off and back on" 😄.

You will see that I also made some changes to how the settings are overridden and how they are reverted: it is now more robust and I believe that code was not good at all and it was causing issues as well.

@theoforger
Copy link
Author

Fantastic job! I tested it and everything seemed to work properly. I should've thought of restoring the keys during resets haha.

Anyway I'll change the PR status to ready 🎉

@theoforger theoforger marked this pull request as ready for review October 23, 2024 18:41
@domferr
Copy link
Owner

domferr commented Oct 24, 2024

Amazing work @theoforger ! Thank you once again, I'll merge and include your changes in the upcoming version of Tiling Shell. You can expect it being released today or tomorrow, depending on the time needed by GSE to review. Can't wait to see people enjoy all the features you implemented! ❤️

Edit: I left the hacktoberfest-accepted label in case you are interested into it 😄

@domferr domferr merged commit ca8006a into domferr:13.2 Oct 24, 2024
@domferr domferr added the enhancement New feature or request label Oct 24, 2024
@theoforger
Copy link
Author

And thanks for guiding me along the way! It's been such a pleasure working with you ❤️

@thyttan
Copy link

thyttan commented Oct 24, 2024

I was a little confused about how the file should be named, but worked out that "example.txt" worked. Maybe the Files-window could be pre-filled with e.g "tiling-shell-exported-settings.txt" as the file name.

Just a suggestion.

@theoforger
Copy link
Author

@thyttan I think it's a great idea. I noticed the name confusion as well during development and tried to solve it with a filter. For some reason it didn't seem to do anything. Pre-filling might be the better solution here. 👍

@domferr We can use Gtk.FileChooserDialog.set_current_name. So just add something like:

fc.set_current_name('tiling-shell-settings.txt');

What do you think?

@domferr
Copy link
Owner

domferr commented Oct 30, 2024

Hey @theoforger @thyttan I think this is a must have addition! @theoforger I tested your suggestion and it works perfectly, thanks! Next release will include this change 🔜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Import/export Tiling Shell settings

3 participants