oficina / calendar Public

Make menu bar visibility configurable without redundant preference writes

Co-authored-by: Codex <codex~paul@keymail.dev>
codex agent, operated by paul@keymail.dev 4383ef900235680b0c8da0805560f00dc1117cfc parent c70d3c5
2 files changed, +8 −2
  • native/apple/Sources/CalendarApp/CalendarApp.swift +3 −1
  • native/apple/Sources/CalendarKit/CalendarSettingsView.swift +5 −1
diff --git a/native/apple/Sources/CalendarApp/CalendarApp.swift b/native/apple/Sources/CalendarApp/CalendarApp.swift
index 6f89fa7..505d6bc 100644
--- a/native/apple/Sources/CalendarApp/CalendarApp.swift
+++ b/native/apple/Sources/CalendarApp/CalendarApp.swift
@@ -7,6 +7,7 @@ import AppKit
@main struct CalendarApp: App {
@StateObject private var connection = NativeConnection(defaultServer: "https://calendar.oficina.works")
+ @AppStorage("calendar.showMenuBar") private var showMenuBar = true
@State private var model = CalendarModel()
var body: some Scene {
WindowGroup("Calendar", id: "calendar") {
@@ -26,7 +27,8 @@ import AppKit
#endif
#if os(macOS)
Settings { CalendarSettingsView() }
- MenuBarExtra("Oficina Calendar", systemImage: "calendar") {
+ // MenuBarExtra can echo its current visibility; avoid a UserDefaults update loop.
+ MenuBarExtra("Oficina Calendar", systemImage: "calendar", isInserted: Binding(get: { showMenuBar }, set: { if showMenuBar != $0 { showMenuBar = $0 } })) {
if let client = connection.client {
CalendarMenuView(client: client, model: model).tint(Color(red: 0.78, green: 0.22, blue: 0.29))
} else {
diff --git a/native/apple/Sources/CalendarKit/CalendarSettingsView.swift b/native/apple/Sources/CalendarKit/CalendarSettingsView.swift
index 8b1d4f2..a0fad8b 100644
--- a/native/apple/Sources/CalendarKit/CalendarSettingsView.swift
+++ b/native/apple/Sources/CalendarKit/CalendarSettingsView.swift
@@ -2,9 +2,13 @@ import SwiftUI
public struct CalendarSettingsView: View {
@AppStorage("calendar.timeZoneOverride") private var override = ""
+ @AppStorage("calendar.showMenuBar") private var showMenuBar = true
public init() {}
public var body: some View {
Form {
+ #if os(macOS)
+ Section { Toggle("Show calendar in menu bar", isOn: $showMenuBar) }
+ #endif
Section {
Toggle("Use system time zone", isOn: Binding(
get: { override.isEmpty },
@@ -23,7 +27,7 @@ public struct CalendarSettingsView: View {
}
}.formStyle(.grouped).navigationTitle("Calendar settings")
#if os(macOS)
- .frame(width: 460, height: 240)
+ .frame(width: 460, height: 300)
#endif
}
}