Skip to content

Commit

Permalink
feat: Save dark mode setting
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaDve committed May 13, 2021
1 parent e1804cb commit f25064c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
3 changes: 3 additions & 0 deletions data/io.github.seadve.Breathing.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="breathing">
<schema id="io.github.seadve.Breathing" path="/io/github/seadve/Breathing/">
<key type="b" name="dark-mode">
<default>false</default>
</key>
</schema>
</schemalist>
3 changes: 1 addition & 2 deletions data/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
</object>
</child>
<child>
<object class="GtkButton">
<property name="icon-name">light-mode-symbolic</property>
<object class="GtkButton" id="dark_mode_button">
<property name="has-frame">False</property>
<signal name="clicked" handler="on_dark_mode_button_clicked" swapped="no"/>
<style>
Expand Down
1 change: 1 addition & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def do_startup(self):
display, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION,
)

Gio.Settings.new('io.github.seadve.Breathing')
self.setup_actions()

Adw.init()
Expand Down
26 changes: 18 additions & 8 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from gi.repository import Adw, Gtk
from gi.repository import Adw, Gtk, Gio

from breathing.timer import Timer

Expand All @@ -27,7 +27,6 @@

# Add app icons
# Implement translations
# use dark mode in gschema


@Gtk.Template(resource_path='/io/github/seadve/Breathing/ui/window.ui')
Expand All @@ -39,11 +38,18 @@ class BreathingWindow(Adw.ApplicationWindow):
circle1 = Gtk.Template.Child()
circle2 = Gtk.Template.Child()
circle3 = Gtk.Template.Child()
dark_mode_button = Gtk.Template.Child()

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

self.timer = Timer(self.button_stack, self)
self.settings = Gio.Settings("io.github.seadve.Breathing")
self.settings.bind(
"dark-mode", self.get_settings(),
"gtk-application-prefer-dark-theme", Gio.SettingsBindFlags.DEFAULT
)
self.setup_darkmode()

def enlarge_circles(self):
self.circle1.get_style_context().add_class("enlarge1")
Expand Down Expand Up @@ -71,6 +77,13 @@ def set_button_play_mode(self, is_play):
self.main_button.get_style_context().add_class("suggested-action")
self.main_button.get_style_context().remove_class("playing")

def setup_darkmode(self):
dark_mode = self.settings.get_boolean("dark-mode")
if dark_mode:
self.dark_mode_button.set_icon_name("dark-mode-symbolic")
else:
self.dark_mode_button.set_icon_name("light-mode-symbolic")

@Gtk.Template.Callback()
def on_main_button_clicked(self, button):
if self.timer.time == 0:
Expand All @@ -80,12 +93,9 @@ def on_main_button_clicked(self, button):

@Gtk.Template.Callback()
def on_dark_mode_button_clicked(self, button):
if button.get_icon_name() == "light-mode-symbolic":
dark_theme = button.get_icon_name() == "light-mode-symbolic"
if dark_theme:
button.set_icon_name("dark-mode-symbolic")
dark_theme = True
else:
button.set_icon_name("light-mode-symbolic")
self.get_settings()
dark_theme = False
settings = self.get_settings()
settings.set_property("gtk-application-prefer-dark-theme", dark_theme)
self.settings.set_boolean("dark-mode", dark_theme)

0 comments on commit f25064c

Please sign in to comment.