Files
steipete--codexbar/Sources/CodexBar/HiddenWindowView.swift
T
2026-07-13 12:22:33 +08:00

39 lines
1.6 KiB
Swift

import SwiftUI
struct HiddenWindowView: View {
@Environment(\.openSettings) private var openSettings
var body: some View {
Color.clear
.frame(width: 20, height: 20)
.onReceive(NotificationCenter.default.publisher(for: .codexbarOpenSettings)) { _ in
Task { @MainActor in
self.openSettings()
}
}
.task {
// Migrate keychain items to reduce permission prompts during development (runs off main thread)
await Task.detached(priority: .userInitiated) {
KeychainMigration.migrateIfNeeded()
}.value
}
.onAppear {
if let window = NSApp.windows.first(where: { $0.title == "CodexBarLifecycleKeepalive" }) {
// Make the keepalive window truly invisible and non-interactive.
window.styleMask = [.borderless]
window.collectionBehavior = [.auxiliary, .ignoresCycle, .transient, .canJoinAllSpaces]
window.isExcludedFromWindowsMenu = true
window.level = .floating
window.isOpaque = false
window.alphaValue = 0
window.backgroundColor = .clear
window.hasShadow = false
window.ignoresMouseEvents = true
window.canHide = false
window.setContentSize(NSSize(width: 1, height: 1))
window.setFrameOrigin(NSPoint(x: -5000, y: -5000))
}
}
}
}