Fix Dock icon not loading — move to onAppear

NSApp.applicationIconImage set in init() was too early; the app
wasn't fully initialized yet. Moved to onAppear where NSApp is ready.
This commit is contained in:
oho 2026-02-13 18:23:55 +01:00
parent 38a99476d6
commit e6246286fb

View file

@ -13,12 +13,6 @@ struct KnowledgeRefineryApp: App {
init() {
// Ensure the app appears in the Dock and can become frontmost
NSApplication.shared.setActivationPolicy(.regular)
// Set custom Dock icon from bundled .icns
if let iconURL = Bundle.module.url(forResource: "AppIcon", withExtension: "icns"),
let icon = NSImage(contentsOf: iconURL) {
NSApplication.shared.applicationIconImage = icon
}
}
var body: some Scene {
@ -28,6 +22,7 @@ struct KnowledgeRefineryApp: App {
.environmentObject(lmMonitor)
.frame(minWidth: 900, minHeight: 600)
.onAppear {
setAppIcon()
autoStartDaemons()
runSelfTestIfRequested()
}
@ -56,6 +51,14 @@ struct KnowledgeRefineryApp: App {
.defaultSize(width: 1300, height: 850)
}
/// Set the Dock icon from the bundled .icns file.
private func setAppIcon() {
if let iconURL = Bundle.module.url(forResource: "AppIcon", withExtension: "icns") {
let icon = NSImage(contentsOf: iconURL)
NSApp.applicationIconImage = icon
}
}
/// Auto-start daemons for all workspaces on app launch.
private func autoStartDaemons() {
for ws in workspaceStore.workspaces {