Skip to content

Commit 2b46558

Browse files
committed
Move current mode query
1 parent e89ab42 commit 2b46558

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/lightdark/notification_observer.cr

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,15 @@ class NotificationObserver < Croft::Class
1111

1212
export_instance_method "themeChanged:", def theme_changed(notice : Croft::String)
1313
# notification = NSNotification.new(notice)
14-
case current_theme
15-
when /light/i
14+
case Mode.current
15+
when .light?
1616
# 🌝 🌞 🌕 🌙 🌜
1717
puts("🌕 setting #{Mode::Light.theme}") if @verbose
1818
ThemeController.set_theme(Mode::Light)
19-
when /dark/i
19+
when .dark?
2020
# 🌚 🌑
2121
puts("🌑 setting #{Mode::Dark.theme}") if @verbose
2222
ThemeController.set_theme(Mode::Dark)
23-
else
24-
puts("💀 unexpected theme #{current_theme}") if @verbose
25-
end
26-
end
27-
28-
def current_theme : String
29-
style = Croft::UserDefaults.standard_user_defaults[Croft::String.new("AppleInterfaceStyle")].to_s
30-
31-
if style.empty?
32-
"Light"
33-
else
34-
"Dark"
3523
end
3624
end
3725
end

src/mode.cr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "croft"
2+
13
DEFAULT_DARK_THEME = "gruvbox-dark-hard"
24
DEFAULT_LIGHT_THEME = "one-light"
35

@@ -11,4 +13,14 @@ enum Mode
1113
when .light? then ENV.fetch("LIGHTDARK_LIGHT_THEME", DEFAULT_LIGHT_THEME)
1214
end
1315
end
16+
17+
def self.current : Mode
18+
style = Croft::UserDefaults.standard_user_defaults[Croft::String.new("AppleInterfaceStyle")].to_s
19+
20+
if style.empty?
21+
Light
22+
else
23+
Dark
24+
end
25+
end
1426
end

0 commit comments

Comments
 (0)