Skip to content

Commit

Permalink
Window/Schema: Remember Selected Settings (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foldex committed Nov 4, 2022
1 parent f802358 commit f898764
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
34 changes: 34 additions & 0 deletions data/io.github.Foldex.AdwSteamGtk.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="adwaita-steam-gtk">
<schema id="io.github.Foldex.AdwSteamGtk" path="/io/github/Foldex/AdwSteamGtk/">

<key name="window-controls-options" type="s">
<default>"Default"</default>
<choices>
<choice value="Default"/>
<choice value="Right-All"/>
<choice value="Left"/>
<choice value="Left-All"/>
<choice value="None"/>
</choices>
</key>

<key name="web-theme-options" type="s">
<default>"Base"</default>
<choices>
<choice value="Base"/>
<choice value="Full"/>
<choice value="None"/>
</choices>
</key>

<key name="qr-login-options" type="s">
<default>"Show"</default>
<choices>
<choice value="Show"/>
<choice value="Hover Only"/>
<choice value="Hide"/>
</choices>
</key>

<key name="whats-new-switch" type="b">
<default>false</default>
</key>

</schema>
</schemalist>
30 changes: 30 additions & 0 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,43 @@ class AdwaitaSteamGtkWindow(Gtk.ApplicationWindow):

whats_new_switch = Gtk.Template.Child()

settings = Gio.Settings.new("io.github.Foldex.AdwSteamGtk")

def __init__(self, **kwargs):
super().__init__(**kwargs)

self.make_action("install", self.install_theme)
self.make_action("retry_dl", self.retry_check)

self.load_config()
self.check_latest_release()

def load_config(self):
options = {
"win_controls": self.config_to_pos('window-controls-options', self.window_controls_options),
"web_theme": self.config_to_pos('web-theme-options', self.web_theme_options),
"qr_login": self.config_to_pos('qr-login-options', self.qr_login_options),
"whats_new": self.settings.get_boolean('whats-new-switch')
}

self.window_controls_options.set_selected(options["win_controls"])
self.web_theme_options.set_selected(options["web_theme"])
self.qr_login_options.set_selected(options["qr_login"])
self.whats_new_switch.set_active(options["whats_new"])

def save_config(self, options):
self.settings.set_string("window-controls-options", options['win_controls'])
self.settings.set_string("web-theme-options", options['web_theme'])
self.settings.set_string("qr-login-options", options['qr_login'])
self.settings.set_boolean("whats-new-switch", options['whats_new'])

def config_to_pos(self, config, comborow):
string = self.settings.get_string(config)
for pos,s in enumerate(comborow.get_model()):
if string == s.get_string():
return pos
return 0

def make_action(self, action, func):
install_action = Gio.SimpleAction(name=action)
install_action.connect("activate", func)
Expand Down Expand Up @@ -81,6 +110,7 @@ def install_theme(self, action, _):

if ret:
t = Adw.Toast(title="Theme Installed", priority="high", timeout=2)
self.save_config(options)
else:
t = Adw.Toast(title=msg, priority="high")

Expand Down

0 comments on commit f898764

Please sign in to comment.