Skip to content

Commit dedf7dc

Browse files
author
Ivo Bellin Salarin
committed
feat: dark theme icon
1 parent 8766a24 commit dedf7dc

File tree

9 files changed

+95
-1
lines changed

9 files changed

+95
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "Icon-dark.png",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"filename" : "Icon-dark@2x.png",
10+
"idiom" : "universal",
11+
"scale" : "2x"
12+
},
13+
{
14+
"filename" : "Icon-dark@3x.png",
15+
"idiom" : "universal",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"author" : "xcode",
21+
"version" : 1
22+
}
23+
}
24+
25+
439 Bytes
Loading
911 Bytes
Loading
1.45 KB
Loading

Recap/Assets.xcassets/barIcon.imageset/Contents.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,39 @@
1414
"filename" : "Icon@3x.png",
1515
"idiom" : "universal",
1616
"scale" : "3x"
17+
},
18+
{
19+
"appearances" : [
20+
{
21+
"appearance" : "luminosity",
22+
"value" : "dark"
23+
}
24+
],
25+
"filename" : "Icon-dark.png",
26+
"idiom" : "universal",
27+
"scale" : "1x"
28+
},
29+
{
30+
"appearances" : [
31+
{
32+
"appearance" : "luminosity",
33+
"value" : "dark"
34+
}
35+
],
36+
"filename" : "Icon-dark@2x.png",
37+
"idiom" : "universal",
38+
"scale" : "2x"
39+
},
40+
{
41+
"appearances" : [
42+
{
43+
"appearance" : "luminosity",
44+
"value" : "dark"
45+
}
46+
],
47+
"filename" : "Icon-dark@3x.png",
48+
"idiom" : "universal",
49+
"scale" : "3x"
1750
}
1851
],
1952
"info" : {
439 Bytes
Loading
911 Bytes
Loading
1.45 KB
Loading

Recap/MenuBar/Manager/StatusBar/StatusBarManager.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ protocol StatusBarDelegate: AnyObject {
99
final class StatusBarManager: StatusBarManagerType {
1010
private var statusItem: NSStatusItem?
1111
weak var delegate: StatusBarDelegate?
12+
private var themeObserver: NSObjectProtocol?
1213

1314
init() {
1415
setupStatusItem()
16+
setupThemeObserver()
1517
}
1618

1719
var statusButton: NSStatusBarButton? {
@@ -22,13 +24,44 @@ final class StatusBarManager: StatusBarManagerType {
2224
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
2325

2426
if let button = statusItem?.button {
25-
button.image = NSImage(named: "barIcon")
27+
updateIconForCurrentTheme()
2628
button.target = self
2729
button.action = #selector(handleButtonClick(_:))
2830
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
2931
}
3032
}
3133

34+
private func setupThemeObserver() {
35+
themeObserver = DistributedNotificationCenter.default.addObserver(
36+
forName: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
37+
object: nil,
38+
queue: .main
39+
) { [weak self] _ in
40+
Task { @MainActor in
41+
self?.updateIconForCurrentTheme()
42+
}
43+
}
44+
}
45+
46+
private func updateIconForCurrentTheme() {
47+
guard let button = statusItem?.button else { return }
48+
49+
// Check system-wide dark mode preference
50+
let isDarkMode = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark"
51+
52+
print("🎨 Theme detection: isDarkMode = \(isDarkMode)")
53+
54+
if isDarkMode {
55+
// Use dark mode icon
56+
button.image = NSImage(named: "barIcon-dark")
57+
print("🌙 Using dark mode icon")
58+
} else {
59+
// Use light mode icon
60+
button.image = NSImage(named: "barIcon")
61+
print("☀️ Using light mode icon")
62+
}
63+
}
64+
3265
@objc private func handleButtonClick(_ sender: NSStatusBarButton) {
3366
let event = NSApp.currentEvent
3467
if event?.type == .rightMouseUp {
@@ -60,6 +93,9 @@ final class StatusBarManager: StatusBarManagerType {
6093
}
6194

6295
deinit {
96+
if let observer = themeObserver {
97+
DistributedNotificationCenter.default.removeObserver(observer)
98+
}
6399
statusItem = nil
64100
}
65101
}

0 commit comments

Comments
 (0)