Add SimpleTopBar menu bar app with collapsible background app list

This commit is contained in:
2026-09-26 22:37:09 +08:00
commit 41a5917b42
12 changed files with 843 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
import SwiftUI
import AppKit
import ServiceManagement
@main
struct SimpleTopBarApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
var body: some Scene {
MenuBarExtra("SimpleTopBar", systemImage: "menubar.rectangle") {
TopBarView(model: AppListModel.shared)
}
.menuBarExtraStyle(.window)
}
}
final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
if CommandLine.arguments.contains("--self-test") {
runSelfTest()
return
}
// Single instance: stale copies keep a menu bar icon around after an
// update and swallow clicks meant for the new instance.
let myPid = ProcessInfo.processInfo.processIdentifier
let others = NSRunningApplication.runningApplications(withBundleIdentifier: "dev.tzgyn.simpletopbar")
.filter { $0.processIdentifier != myPid }
for other in others {
other.forceTerminate()
}
AppListModel.shared.start()
}
}
enum LoginItem {
static var isEnabled: Bool {
SMAppService.mainApp.status == .enabled
}
static func toggle() -> Bool {
let service = SMAppService.mainApp
do {
if service.status == .enabled {
try service.unregister()
} else {
try service.register()
}
return true
} catch {
return false
}
}
}