Skip to content

Commit b2db97b

Browse files
committed
Add custom tray menu icon support
1 parent 4c0ef86 commit b2db97b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

SupportCompanion/AppDelegate.swift

+13-3
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate {
186186

187187
class TrayMenuManager {
188188
static let shared = TrayMenuManager()
189-
189+
let appStateManager = AppStateManager.shared
190+
let fileManager = FileManager.default
190191
private var statusItem: NSStatusItem
191192

192193
private init() {
@@ -196,8 +197,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate {
196197

197198
func updateTrayIcon(hasUpdates: Bool) {
198199
let iconName = "MenuIcon"
199-
guard let baseIcon = NSImage(named: iconName) else {
200-
Logger.shared.logDebug("Failed to load tray icon: \(iconName)")
200+
let iconPath = appStateManager.preferences.trayMenuBrandingIconPath
201+
var baseIcon: NSImage?
202+
203+
if !iconPath.isEmpty && fileManager.fileExists(atPath: iconPath) {
204+
baseIcon = NSImage(contentsOfFile: iconPath)
205+
} else {
206+
baseIcon = NSImage(named: iconName)
207+
}
208+
209+
guard let baseIcon = baseIcon else {
210+
Logger.shared.logError("Error: Failed to load tray menu icon")
201211
return
202212
}
203213

SupportCompanion/Preferences.swift

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class Preferences: ObservableObject {
8080
@AppStorage("CustomCardsMenuLabel") var customCardsMenuLabel: String = ""
8181

8282
@AppStorage("CustomCardsMenuIcon") var customCardsMenuIcon: String = ""
83+
84+
@AppStorage("TrayMenuBrandingIconPath") var trayMenuBrandingIconPath: String = ""
8385

8486
// MARK: - Actions
8587

0 commit comments

Comments
 (0)