13 Commits
v1.0.0 ... main

Author SHA1 Message Date
3ecf29f499 1.3.1: fix auto-delete of missing-source mirrors; bump version; add release notes 2025-10-13 11:43:01 +02:00
eb643ac74d Version update 2025-10-10 10:00:57 +02:00
df06564434 BusyMirror 1.3.0: add Mark Private option (global + per-route); version bump and release notes 2025-10-10 09:58:05 +02:00
74b9949610 BusyMirror 1.2.6: always enable Mirror Now when calendars accessible; route/manual decided at runtime 2025-10-10 09:08:26 +02:00
6676e62889 BusyMirror 1.2.5: Mirror Now enables for routes or manual; add computed canRunMirrorNow; version bump 2025-10-10 08:59:59 +02:00
d1fbd4c81f BusyMirror 1.2.4: enable Mirror Now when routes exist; version bump 2025-10-10 08:52:41 +02:00
6ef0feecc1 BusyMirror 1.2.3: reliable settings autosave/restore; remember source/target; @MainActor fixes; reinit EKEventStore after grant; Makefile; changelog + release notes 2025-10-10 08:34:07 +02:00
aac4de3fb3 BusyMirror 1.2.1: fix calendar loading after grant, attendee status filter, main-actor; add Makefile 2025-10-10 07:45:59 +02:00
8f80a5f672 Adding source events filtering 2025-09-29 18:06:34 +02:00
ae40b42e6f Bump version 2025-09-29 17:52:18 +02:00
691575c554 Adding support to save routes 2025-09-29 15:31:11 +02:00
b931f3ba2c Fixed building 2025-09-29 15:18:42 +02:00
53f21492da Fixes 2025-09-29 13:30:45 +02:00
11 changed files with 836 additions and 179 deletions

2
.gitignore vendored
View File

@@ -19,3 +19,5 @@ ExportOptions.plist
# Misc # Misc
*.swp *.swp
*.zip *.zip
*.sha256
dist/

View File

@@ -410,7 +410,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 9;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = BusyMirror/Info.plist; INFOPLIST_FILE = BusyMirror/Info.plist;
@@ -421,7 +421,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MARKETING_VERSION = 1.0.0; MARKETING_VERSION = 1.3.1;
PRODUCT_BUNDLE_IDENTIFIER = com.cqrenet.BusyMirror; PRODUCT_BUNDLE_IDENTIFIER = com.cqrenet.BusyMirror;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES; REGISTER_APP_GROUPS = YES;
@@ -440,7 +440,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 9;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = BusyMirror/Info.plist; INFOPLIST_FILE = BusyMirror/Info.plist;
@@ -451,7 +451,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MARKETING_VERSION = 1.0.0; MARKETING_VERSION = 1.3.1;
PRODUCT_BUNDLE_IDENTIFIER = com.cqrenet.BusyMirror; PRODUCT_BUNDLE_IDENTIFIER = com.cqrenet.BusyMirror;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES; REGISTER_APP_GROUPS = YES;
@@ -465,7 +465,7 @@
buildSettings = { buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)"; BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 2;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 15.5; MACOSX_DEPLOYMENT_TARGET = 15.5;
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
@@ -482,7 +482,7 @@
buildSettings = { buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)"; BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 2;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 15.5; MACOSX_DEPLOYMENT_TARGET = 15.5;
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
@@ -498,7 +498,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 2;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.cqrenet.BusyMirrorUITests; PRODUCT_BUNDLE_IDENTIFIER = com.cqrenet.BusyMirrorUITests;
@@ -513,7 +513,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 2;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.cqrenet.BusyMirrorUITests; PRODUCT_BUNDLE_IDENTIFIER = com.cqrenet.BusyMirrorUITests;

View File

@@ -1,12 +1,13 @@
import SwiftUI import SwiftUI
import EventKit import EventKit
import AppKit import AppKit
import ObjectiveC
/// Placeholder title is configurable via state (see `placeholderTitle`) /// Placeholder title is configurable via state (see `placeholderTitle`)
private let SAME_TIME_TOL_MIN: Double = 5 private let SAME_TIME_TOL_MIN: Double = 5
private let SKIP_ALL_DAY_DEFAULT = true private let SKIP_ALL_DAY_DEFAULT = true
enum OverlapMode: String, CaseIterable, Identifiable { enum OverlapMode: String, CaseIterable, Identifiable, Codable {
case allow, skipCovered, fillGaps case allow, skipCovered, fillGaps
var id: String { rawValue } var id: String { rawValue }
} }
@@ -68,8 +69,13 @@ private func parseMirrorURL(_ url: URL?) -> (srcEventID: String?, occ: Date?, st
var sDate: Date? = nil var sDate: Date? = nil
var eDate: Date? = nil var eDate: Date? = nil
if parts.count >= 3 { srcID = String(parts[2]) } if parts.count >= 3 { srcID = String(parts[2]) }
if parts.count >= 4, let ts = TimeInterval(parts[3]) { occDate = Date(timeIntervalSince1970: ts) } if parts.count >= 4,
if parts.count >= 6, let sTS = TimeInterval(parts[4]), let eTS = TimeInterval(parts[5]) { let ts = TimeInterval(String(parts[3])) {
occDate = Date(timeIntervalSince1970: ts)
}
if parts.count >= 6,
let sTS = TimeInterval(String(parts[4])),
let eTS = TimeInterval(String(parts[5])) {
sDate = Date(timeIntervalSince1970: sTS) sDate = Date(timeIntervalSince1970: sTS)
eDate = Date(timeIntervalSince1970: eTS) eDate = Date(timeIntervalSince1970: eTS)
} }
@@ -94,7 +100,7 @@ struct Block: Hashable {
let occurrence: Date? // occurrenceDate for recurring instances let occurrence: Date? // occurrenceDate for recurring instances
} }
struct Route: Identifiable, Hashable { struct Route: Identifiable, Hashable, Codable {
let id = UUID() let id = UUID()
var sourceID: String var sourceID: String
var targetIDs: Set<String> var targetIDs: Set<String>
@@ -103,6 +109,32 @@ struct Route: Identifiable, Hashable {
var mergeGapHours: Int // per-route merge gap (hours) var mergeGapHours: Int // per-route merge gap (hours)
var overlap: OverlapMode // per-route overlap behavior var overlap: OverlapMode // per-route overlap behavior
var allDay: Bool // per-route mirror all-day var allDay: Bool // per-route mirror all-day
var markPrivate: Bool = false // mark mirrored events as Private (if supported by account)
enum CodingKeys: String, CodingKey { case sourceID, targetIDs, privacy, copyNotes, mergeGapHours, overlap, allDay, markPrivate }
init(sourceID: String, targetIDs: Set<String>, privacy: Bool, copyNotes: Bool, mergeGapHours: Int, overlap: OverlapMode, allDay: Bool, markPrivate: Bool = false) {
self.sourceID = sourceID
self.targetIDs = targetIDs
self.privacy = privacy
self.copyNotes = copyNotes
self.mergeGapHours = mergeGapHours
self.overlap = overlap
self.allDay = allDay
self.markPrivate = markPrivate
}
init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
self.sourceID = try c.decode(String.self, forKey: .sourceID)
self.targetIDs = try c.decode(Set<String>.self, forKey: .targetIDs)
self.privacy = try c.decode(Bool.self, forKey: .privacy)
self.copyNotes = try c.decode(Bool.self, forKey: .copyNotes)
self.mergeGapHours = try c.decode(Int.self, forKey: .mergeGapHours)
self.overlap = try c.decode(OverlapMode.self, forKey: .overlap)
self.allDay = try c.decode(Bool.self, forKey: .allDay)
self.markPrivate = (try? c.decode(Bool.self, forKey: .markPrivate)) ?? false
}
} }
struct ContentView: View { struct ContentView: View {
@@ -115,14 +147,24 @@ struct ContentView: View {
@State private var sourceID: String? = nil @State private var sourceID: String? = nil
@State private var targetIDs = Set<String>() @State private var targetIDs = Set<String>()
@State private var routes: [Route] = [] @State private var routes: [Route] = []
@State private var daysForward: Int = 7 @AppStorage("daysForward") private var daysForward: Int = 7
@State private var daysBack: Int = 1 @AppStorage("daysBack") private var daysBack: Int = 1
@State private var mergeGapMin: Int = 0 @State private var mergeGapMin: Int = 0
@State private var mergeGapHours: Int = 0 @AppStorage("mergeGapHours") private var mergeGapHours: Int = 0
@State private var hideDetails = true // Privacy ON by default -> use "Busy" @AppStorage("hideDetails") private var hideDetails: Bool = true // Privacy ON by default -> use "Busy"
@State private var copyDescription = false // Only applies when hideDetails == false @AppStorage("copyDescription") private var copyDescription: Bool = false // Only applies when hideDetails == false
@State private var overlapMode: OverlapMode = .allow @AppStorage("markPrivate") private var markPrivate: Bool = false // If ON, set event Private (server-side) when mirroring
@State private var mirrorAllDay = false @AppStorage("mirrorAllDay") private var mirrorAllDay: Bool = false
@AppStorage("overlapMode") private var overlapModeRaw: String = OverlapMode.allow.rawValue
@AppStorage("filterByWorkHours") private var filterByWorkHours: Bool = false
@AppStorage("workHoursStart") private var workHoursStart: Int = 9
@AppStorage("workHoursEnd") private var workHoursEnd: Int = 17
@AppStorage("excludedTitleFilters") private var excludedTitleFiltersRaw: String = ""
@AppStorage("mirrorAcceptedOnly") private var mirrorAcceptedOnly: Bool = false
var overlapMode: OverlapMode {
get { OverlapMode(rawValue: overlapModeRaw) ?? .allow }
nonmutating set { overlapModeRaw = newValue.rawValue }
}
@State private var writeEnabled = false // dry-run unless checked @State private var writeEnabled = false // dry-run unless checked
@State private var logText = "Ready." @State private var logText = "Ready."
@State private var isRunning = false @State private var isRunning = false
@@ -132,9 +174,17 @@ struct ContentView: View {
// into the same target more than once across multiple routes within a // into the same target more than once across multiple routes within a
// single "Mirror Now" click. // single "Mirror Now" click.
@State private var sessionGuard = Set<String>() @State private var sessionGuard = Set<String>()
@State private var titlePrefix: String = "🪞 " // global title prefix for mirrored placeholders @AppStorage("titlePrefix") private var titlePrefix: String = "🪞 " // global title prefix for mirrored placeholders
@State private var placeholderTitle: String = "Busy" // global customizable placeholder title @AppStorage("placeholderTitle") private var placeholderTitle: String = "Busy" // global customizable placeholder title
@State private var autoDeleteMissing: Bool = true // delete mirrors whose source instance no longer exists @AppStorage("autoDeleteMissing") private var autoDeleteMissing: Bool = true // delete mirrors whose source instance no longer exists
// Mirrors can run either by manual selection (source + at least one target)
// or using predefined routes. This derived flag controls the Mirror Now button.
private var canRunMirrorNow: Bool {
// Enable Mirror Now whenever calendars are available and permission is granted.
// The action itself chooses between routes or manual selection.
return hasAccess && !isRunning && !calendars.isEmpty
}
private static let intFormatter: NumberFormatter = { private static let intFormatter: NumberFormatter = {
let f = NumberFormatter() let f = NumberFormatter()
@@ -144,6 +194,14 @@ struct ContentView: View {
return f return f
}() }()
private static let hourFormatter: NumberFormatter = {
let f = NumberFormatter()
f.numberStyle = .none
f.minimum = 0
f.maximum = 24
return f
}()
// Deterministic ordering to keep indices stable across runs // Deterministic ordering to keep indices stable across runs
private func sortedCalendars(_ cals: [EKCalendar]) -> [EKCalendar] { private func sortedCalendars(_ cals: [EKCalendar]) -> [EKCalendar] {
return cals.sorted { a, b in return cals.sorted { a, b in
@@ -153,6 +211,17 @@ struct ContentView: View {
} }
} }
private var excludedTitleFilterList: [String] {
excludedTitleFiltersRaw
.split { $0 == "\n" || $0 == "," }
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
.filter { !$0.isEmpty }
}
private var excludedTitleFilterTerms: [String] {
excludedTitleFilterList.map { $0.lowercased() }
}
private func rebuildSelectionsFromIDs() { private func rebuildSelectionsFromIDs() {
// Map IDs -> indices in current calendars // Map IDs -> indices in current calendars
var idToIndex: [String:Int] = [:] var idToIndex: [String:Int] = [:]
@@ -239,18 +308,60 @@ struct ContentView: View {
copyNotes: copyDescription, copyNotes: copyDescription,
mergeGapHours: mergeGapHours, mergeGapHours: mergeGapHours,
overlap: overlapMode, overlap: overlapMode,
allDay: mirrorAllDay) allDay: mirrorAllDay,
markPrivate: markPrivate)
routes.append(r) routes.append(r)
}.disabled(isRunning || calendars.isEmpty || targetIDs.isEmpty) }
Button("Clear") { routes.removeAll() }.disabled(isRunning || routes.isEmpty) .disabled(isRunning || calendars.isEmpty || targetIDs.isEmpty)
Button("Clear") { routes.removeAll() }
.disabled(isRunning || routes.isEmpty)
} }
if routes.isEmpty { if routes.isEmpty {
Text("No routes yet. Pick a Source and Targets above, then click Add from current selection.") Text("No routes yet. Pick a Source and Targets above, then click Add from current selection.")
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
} else { } else {
ForEach(Array(routes.enumerated()), id: \.element.id) { idx, route in ForEach($routes, id: \.id) { routeBinding in
routeCard(for: routeBinding)
}
}
}
}
@ViewBuilder
private func routeCard(for routeBinding: Binding<Route>) -> some View {
let route = routeBinding.wrappedValue
VStack(alignment: .leading, spacing: 4) { VStack(alignment: .leading, spacing: 4) {
HStack(alignment: .firstTextBaseline, spacing: 8) { HStack(alignment: .firstTextBaseline, spacing: 8) {
sourceSummaryView(for: route)
Text("→ Targets:")
targetSummaryView(for: route)
Spacer()
Toggle("Private", isOn: routeBinding.privacy)
.help("If ON, mirror as \(titlePrefix)\(placeholderTitle) with no notes. If OFF, mirror source title (and optionally notes).")
separatorDot()
mergeGapField(for: routeBinding)
Toggle("Copy desc", isOn: routeBinding.copyNotes)
.disabled(isRunning || route.privacy)
.help("If ON and Private is OFF, copy the source events notes/description into the placeholder.")
Toggle("Mark Private", isOn: routeBinding.markPrivate)
.disabled(isRunning)
.help("If ON, attempt to mark mirrored events as Private on the server (e.g., Exchange). Titles still use your prefix and source title.")
overlapPicker(for: routeBinding)
.disabled(isRunning)
Toggle("All-day", isOn: routeBinding.allDay)
.disabled(isRunning)
.help("Mirror all-day events for this source.")
separatorDot()
Button(role: .destructive) { removeRoute(id: route.id) } label: { Text("Remove") }
}
}
.padding(6)
.background(.quaternary.opacity(0.1))
.cornerRadius(6)
}
@ViewBuilder
private func sourceSummaryView(for route: Route) -> some View {
Text("Source:") Text("Source:")
if let sCal = calendars.first(where: { $0.calendarIdentifier == route.sourceID }) { if let sCal = calendars.first(where: { $0.calendarIdentifier == route.sourceID }) {
HStack(spacing: 6) { HStack(spacing: 6) {
@@ -260,7 +371,10 @@ struct ContentView: View {
} else { } else {
Text(labelForCalendar(id: route.sourceID)).bold() Text(labelForCalendar(id: route.sourceID)).bold()
} }
Text("→ Targets:") }
@ViewBuilder
private func targetSummaryView(for route: Route) -> some View {
ScrollView(.horizontal, showsIndicators: false) { ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 10) { HStack(spacing: 10) {
ForEach(route.targetIDs.sorted(by: <), id: \.self) { tid in ForEach(route.targetIDs.sorted(by: <), id: \.self) { tid in
@@ -276,55 +390,41 @@ struct ContentView: View {
} }
} }
.frame(maxWidth: 420) .frame(maxWidth: 420)
Spacer() }
Toggle("Private", isOn: Binding(get: { routes[idx].privacy }, set: { routes[idx].privacy = $0 }))
.help("If ON, mirror as \(titlePrefix)\(placeholderTitle) with no notes. If OFF, mirror source title (and optionally notes).") @ViewBuilder
Text("·").foregroundStyle(.secondary) private func mergeGapField(for routeBinding: Binding<Route>) -> some View {
HStack(spacing: 6) { HStack(spacing: 6) {
Text("Merge gap:") Text("Merge gap:")
TextField("0", value: Binding( TextField("0", value: routeBinding.mergeGapHours, formatter: Self.intFormatter)
get: { routes[idx].mergeGapHours },
set: { routes[idx].mergeGapHours = max(0, $0) }
), formatter: Self.intFormatter)
.frame(width: 48) .frame(width: 48)
.disabled(isRunning) .disabled(isRunning)
.help("Merge adjacent source events separated by ≤ this many hours (e.g., flight legs). 0 = no merge.") .help("Merge adjacent source events separated by ≤ this many hours (e.g., flight legs). 0 = no merge.")
Text("h").foregroundStyle(.secondary) Text("h").foregroundStyle(.secondary)
} }
Toggle("Copy desc", isOn: Binding( }
get: { routes[idx].copyNotes },
set: { routes[idx].copyNotes = $0 } @ViewBuilder
)) private func overlapPicker(for routeBinding: Binding<Route>) -> some View {
.disabled(isRunning || routes[idx].privacy)
.help("If ON and Private is OFF, copy the source events notes/description into the placeholder.")
HStack(spacing: 6) { HStack(spacing: 6) {
Text("Overlap:") Text("Overlap:")
Picker("Overlap", selection: Binding( Picker("Overlap", selection: routeBinding.overlap) {
get: { routes[idx].overlap }, ForEach(OverlapMode.allCases) { mode in
set: { routes[idx].overlap = $0 } Text(mode.rawValue).tag(mode)
)) { }
ForEach(OverlapMode.allCases) { m in Text(m.rawValue).tag(m) }
} }
.frame(width: 160) .frame(width: 160)
.help("allow = always place; skipCovered = skip if target already has a block covering the time; fillGaps = only fill uncovered gaps within the source block.") .help("allow = always place; skipCovered = skip if target already has a block covering the time; fillGaps = only fill uncovered gaps within the source block.")
} }
.disabled(isRunning) }
Toggle("Allday", isOn: Binding(
get: { routes[idx].allDay }, @ViewBuilder
set: { routes[idx].allDay = $0 } private func separatorDot() -> some View {
))
.disabled(isRunning)
.help("Mirror allday events for this source.")
Text("·").foregroundStyle(.secondary) Text("·").foregroundStyle(.secondary)
Button(role: .destructive) { routes.remove(at: idx) } label: { Text("Remove") }
}
}
.padding(6)
.background(.quaternary.opacity(0.1))
.cornerRadius(6)
}
}
} }
private func removeRoute(id: UUID) {
routes.removeAll { $0.id == id }
} }
@ViewBuilder @ViewBuilder
@@ -340,8 +440,8 @@ struct ContentView: View {
.frame(width: 60) .frame(width: 60)
.disabled(isRunning) .disabled(isRunning)
} }
.onChange(of: daysBack) { _, v in daysBack = max(0, v) } .onChange(of: daysBack) { v in daysBack = max(0, v) }
.onChange(of: daysForward) { _, v in daysForward = max(0, v) } .onChange(of: daysForward) { v in daysForward = max(0, v) }
HStack(spacing: 8) { HStack(spacing: 8) {
Text("Default merge gap:") Text("Default merge gap:")
TextField("0", value: $mergeGapHours, formatter: Self.intFormatter) TextField("0", value: $mergeGapHours, formatter: Self.intFormatter)
@@ -349,7 +449,7 @@ struct ContentView: View {
.disabled(isRunning) .disabled(isRunning)
Text("hours").foregroundStyle(.secondary) Text("hours").foregroundStyle(.secondary)
} }
.onChange(of: mergeGapHours) { _, newVal in .onChange(of: mergeGapHours) { newVal in
mergeGapMin = max(0, newVal * 60) mergeGapMin = max(0, newVal * 60)
} }
Toggle("Hide details (use \"Busy\" title)", isOn: $hideDetails) Toggle("Hide details (use \"Busy\" title)", isOn: $hideDetails)
@@ -357,11 +457,15 @@ struct ContentView: View {
Toggle("Copy description when mirroring", isOn: $copyDescription) Toggle("Copy description when mirroring", isOn: $copyDescription)
.disabled(isRunning || hideDetails) .disabled(isRunning || hideDetails)
Toggle("Mark mirrored events as Private (if supported)", isOn: $markPrivate)
.disabled(isRunning)
Toggle("Mirror all-day events", isOn: $mirrorAllDay) Toggle("Mirror all-day events", isOn: $mirrorAllDay)
.disabled(isRunning) .disabled(isRunning)
Picker("Overlap mode", selection: $overlapMode) { Toggle("Mirror accepted events only", isOn: $mirrorAcceptedOnly)
.disabled(isRunning)
Picker("Overlap mode", selection: $overlapModeRaw) {
ForEach(OverlapMode.allCases) { mode in ForEach(OverlapMode.allCases) { mode in
Text(mode.rawValue).tag(mode) Text(mode.rawValue).tag(mode.rawValue)
} }
} }
.pickerStyle(.segmented) .pickerStyle(.segmented)
@@ -382,12 +486,64 @@ struct ContentView: View {
.disabled(isRunning) .disabled(isRunning)
} }
Toggle("Limit mirroring to work hours", isOn: $filterByWorkHours)
.disabled(isRunning)
.onChange(of: filterByWorkHours) { _ in saveSettingsToDefaults() }
if filterByWorkHours {
VStack(alignment: .leading, spacing: 4) {
HStack(spacing: 8) {
Text("Start hour:")
TextField("9", value: $workHoursStart, formatter: Self.hourFormatter)
.frame(width: 48)
.disabled(isRunning)
Text("End hour:")
TextField("17", value: $workHoursEnd, formatter: Self.hourFormatter)
.frame(width: 48)
.disabled(isRunning)
Text("(local time)").foregroundStyle(.secondary)
}
Text("Events starting outside this range are skipped; end hour is exclusive.")
.foregroundStyle(.secondary)
.font(.footnote)
}
.onChange(of: workHoursStart) { _ in
clampWorkHours()
saveSettingsToDefaults()
}
.onChange(of: workHoursEnd) { _ in
clampWorkHours()
saveSettingsToDefaults()
}
}
VStack(alignment: .leading, spacing: 6) {
Text("Skip source titles (one per line)")
TextEditor(text: $excludedTitleFiltersRaw)
.font(.body)
.frame(minHeight: 80)
.disabled(isRunning)
.overlay(
RoundedRectangle(cornerRadius: 6)
.stroke(Color.secondary.opacity(0.3))
)
Text("Matches are case-insensitive and apply before mirroring.")
.foregroundStyle(.secondary)
.font(.footnote)
}
.onChange(of: excludedTitleFiltersRaw) { _ in saveSettingsToDefaults() }
Toggle("Write to calendars (disable for Dry-Run)", isOn: $writeEnabled) Toggle("Write to calendars (disable for Dry-Run)", isOn: $writeEnabled)
.disabled(isRunning) .disabled(isRunning)
// Insert auto-delete toggle after writeEnabled // Insert auto-delete toggle after writeEnabled
Toggle("Auto-delete mirrors if source is removed", isOn: $autoDeleteMissing) Toggle("Auto-delete mirrors if source is removed", isOn: $autoDeleteMissing)
.disabled(isRunning) .disabled(isRunning)
HStack(spacing: 12) {
Button("Export Settings…") { exportSettings() }
Button("Import Settings…") { importSettings() }
}
.padding(.vertical, 4)
HStack { HStack {
Button(isRunning ? "Running…" : "Mirror Now") { Button(isRunning ? "Running…" : "Mirror Now") {
@@ -400,11 +556,6 @@ struct ContentView: View {
for r in routes { for r in routes {
// Resolve source index and target IDs for this route // Resolve source index and target IDs for this route
if let sIdx = indexForCalendar(id: r.sourceID) { if let sIdx = indexForCalendar(id: r.sourceID) {
sourceIndex = sIdx
sourceID = r.sourceID
targetIDs = r.targetIDs
// Belt-and-suspenders: ensure source is not in targets even if UI state is stale
targetIDs.remove(r.sourceID)
// Save globals // Save globals
let prevPrivacy = hideDetails let prevPrivacy = hideDetails
let prevCopy = copyDescription let prevCopy = copyDescription
@@ -412,27 +563,37 @@ struct ContentView: View {
let prevGapM = mergeGapMin let prevGapM = mergeGapMin
let prevOverlap = overlapMode let prevOverlap = overlapMode
let prevAllDay = mirrorAllDay let prevAllDay = mirrorAllDay
// Apply per-route // Apply per-route state changes on MainActor
await MainActor.run {
sourceIndex = sIdx
sourceID = r.sourceID
targetIDs = r.targetIDs
// Belt-and-suspenders: ensure source is not in targets even if UI state is stale
targetIDs.remove(r.sourceID)
hideDetails = r.privacy hideDetails = r.privacy
copyDescription = r.copyNotes copyDescription = r.copyNotes
mergeGapHours = max(0, r.mergeGapHours) mergeGapHours = max(0, r.mergeGapHours)
mergeGapMin = mergeGapHours * 60 mergeGapMin = mergeGapHours * 60
overlapMode = r.overlap overlapModeRaw = r.overlap.rawValue
mirrorAllDay = r.allDay mirrorAllDay = r.allDay
markPrivate = r.markPrivate
}
await runMirror() await runMirror()
await MainActor.run {
// Restore globals // Restore globals
hideDetails = prevPrivacy hideDetails = prevPrivacy
copyDescription = prevCopy copyDescription = prevCopy
mergeGapHours = prevGapH mergeGapHours = prevGapH
mergeGapMin = prevGapM mergeGapMin = prevGapM
overlapMode = prevOverlap overlapModeRaw = prevOverlap.rawValue
mirrorAllDay = prevAllDay mirrorAllDay = prevAllDay
} }
} }
} }
} }
} }
.disabled(isRunning || targetSelections.isEmpty || calendars.isEmpty) }
.disabled(!canRunMirrorNow)
Button("Cleanup Placeholders") { Button("Cleanup Placeholders") {
if writeEnabled { if writeEnabled {
@@ -446,9 +607,11 @@ struct ContentView: View {
} else { } else {
for r in routes { for r in routes {
if let sIdx = indexForCalendar(id: r.sourceID) { if let sIdx = indexForCalendar(id: r.sourceID) {
await MainActor.run {
sourceIndex = sIdx sourceIndex = sIdx
sourceID = r.sourceID sourceID = r.sourceID
targetIDs = r.targetIDs targetIDs = r.targetIDs
}
await runCleanup() await runCleanup()
} }
} }
@@ -514,9 +677,11 @@ struct ContentView: View {
} else { } else {
for r in routes { for r in routes {
if let sIdx = indexForCalendar(id: r.sourceID) { if let sIdx = indexForCalendar(id: r.sourceID) {
await MainActor.run {
sourceIndex = sIdx sourceIndex = sIdx
sourceID = r.sourceID sourceID = r.sourceID
targetIDs = r.targetIDs targetIDs = r.targetIDs
}
await runCleanup() await runCleanup()
} }
} }
@@ -529,22 +694,42 @@ struct ContentView: View {
} }
.onAppear { .onAppear {
requestAccess() requestAccess()
mergeGapHours = mergeGapMin / 60 loadSettingsFromDefaults()
mergeGapMin = max(0, mergeGapHours * 60)
tryRunCLIIfPresent() tryRunCLIIfPresent()
enforceNoSourceInTargets() enforceNoSourceInTargets()
} }
.onChange(of: sourceIndex) { oldValue, newValue in // Persist key settings whenever they change, to ensure restore between runs
.onChange(of: daysBack) { _ in saveSettingsToDefaults() }
.onChange(of: daysForward) { _ in saveSettingsToDefaults() }
.onChange(of: mergeGapHours) { _ in saveSettingsToDefaults() }
.onChange(of: hideDetails) { _ in saveSettingsToDefaults() }
.onChange(of: copyDescription) { _ in saveSettingsToDefaults() }
.onChange(of: mirrorAllDay) { _ in saveSettingsToDefaults() }
.onChange(of: mirrorAcceptedOnly) { _ in saveSettingsToDefaults() }
.onChange(of: overlapModeRaw) { _ in saveSettingsToDefaults() }
.onChange(of: titlePrefix) { _ in saveSettingsToDefaults() }
.onChange(of: placeholderTitle) { _ in saveSettingsToDefaults() }
.onChange(of: autoDeleteMissing) { _ in saveSettingsToDefaults() }
.onChange(of: markPrivate) { _ in saveSettingsToDefaults() }
.onChange(of: sourceIndex) { newValue in
// Track selected source by persistent ID and ensure it is not a target // Track selected source by persistent ID and ensure it is not a target
if newValue < calendars.count { sourceID = calendars[newValue].calendarIdentifier } if newValue < calendars.count { sourceID = calendars[newValue].calendarIdentifier }
enforceNoSourceInTargets() enforceNoSourceInTargets()
saveSettingsToDefaults()
} }
.onChange(of: targetSelections) { _, _ in .onChange(of: targetSelections) { _ in
// If the new source is accidentally included, drop it // If the new source is accidentally included, drop it
enforceNoSourceInTargets() enforceNoSourceInTargets()
saveSettingsToDefaults()
} }
.onChange(of: targetIDs) { _, _ in .onChange(of: targetIDs) { _ in
// If IDs contain the sources ID, drop it // If IDs contain the sources ID, drop it
enforceNoSourceInTargets() enforceNoSourceInTargets()
saveSettingsToDefaults()
}
.onChange(of: routes) { _ in
saveSettingsToDefaults()
} }
} }
@@ -581,9 +766,9 @@ struct ContentView: View {
mergeGapMin = max(0, mergeGapHours * 60) mergeGapMin = max(0, mergeGapHours * 60)
if let modeStr = strArg("--mode")?.lowercased() { if let modeStr = strArg("--mode")?.lowercased() {
switch modeStr { switch modeStr {
case "allow": overlapMode = .allow case "allow": overlapModeRaw = OverlapMode.allow.rawValue
case "skipcovered", "skip": overlapMode = .skipCovered case "skipcovered", "skip": overlapModeRaw = OverlapMode.skipCovered.rawValue
case "fillgaps", "gaps": overlapMode = .fillGaps case "fillgaps", "gaps": overlapModeRaw = OverlapMode.fillGaps.rawValue
default: break default: break
} }
} }
@@ -610,10 +795,12 @@ struct ContentView: View {
let srcIdx0 = max(0, s1 - 1) let srcIdx0 = max(0, s1 - 1)
let tgtIdxs0: [Int] = lr[1].split(separator: ",").compactMap { Int($0.trimmingCharacters(in: .whitespaces))?.advanced(by: -1) }.filter { $0 >= 0 } let tgtIdxs0: [Int] = lr[1].split(separator: ",").compactMap { Int($0.trimmingCharacters(in: .whitespaces))?.advanced(by: -1) }.filter { $0 >= 0 }
if srcIdx0 >= calendars.count { continue } if srcIdx0 >= calendars.count { continue }
await MainActor.run {
sourceIndex = srcIdx0 sourceIndex = srcIdx0
sourceID = calendars[srcIdx0].calendarIdentifier sourceID = calendars[srcIdx0].calendarIdentifier
targetSelections = Set(tgtIdxs0) targetSelections = Set(tgtIdxs0)
targetIDs = Set(tgtIdxs0.compactMap { i in calendars.indices.contains(i) ? calendars[i].calendarIdentifier : nil }) targetIDs = Set(tgtIdxs0.compactMap { i in calendars.indices.contains(i) ? calendars[i].calendarIdentifier : nil })
}
if boolArg("--cleanup-only", default: false) { if boolArg("--cleanup-only", default: false) {
log("CLI: cleanup route \(part)") log("CLI: cleanup route \(part)")
@@ -630,13 +817,18 @@ struct ContentView: View {
} }
// MARK: - Permissions & Calendars // MARK: - Permissions & Calendars
@MainActor
func requestAccess() { func requestAccess() {
log("Requesting calendar access…") log("Requesting calendar access…")
if #available(macOS 14.0, *) { if #available(macOS 14.0, *) {
store.requestFullAccessToEvents { granted, _ in store.requestFullAccessToEvents { granted, _ in
DispatchQueue.main.async { DispatchQueue.main.async {
hasAccess = granted hasAccess = granted
if granted { reloadCalendars() } if granted {
// Reinitialize the store after permission changes to ensure sources load
store = EKEventStore()
reloadCalendars()
}
log(granted ? "Access granted." : "Access denied.") log(granted ? "Access granted." : "Access denied.")
} }
} }
@@ -644,13 +836,18 @@ struct ContentView: View {
store.requestAccess(to: .event) { granted, _ in store.requestAccess(to: .event) { granted, _ in
DispatchQueue.main.async { DispatchQueue.main.async {
hasAccess = granted hasAccess = granted
if granted { reloadCalendars() } if granted {
// Reinitialize the store after permission changes to ensure sources load
store = EKEventStore()
reloadCalendars()
}
log(granted ? "Access granted." : "Access denied.") log(granted ? "Access granted." : "Access denied.")
} }
} }
} }
} }
@MainActor
func reloadCalendars() { func reloadCalendars() {
let fetched = store.calendars(for: .event) let fetched = store.calendars(for: .event)
calendars = sortedCalendars(fetched) calendars = sortedCalendars(fetched)
@@ -704,7 +901,37 @@ struct ContentView: View {
var srcBlocks: [Block] = [] var srcBlocks: [Block] = []
var skippedMirrors = 0 var skippedMirrors = 0
let titleFilters = excludedTitleFilterTerms
let enforceWorkHours = filterByWorkHours && workHoursEnd > workHoursStart
let allowedStartMinutes = workHoursStart * 60
let allowedEndMinutes = workHoursEnd * 60
var skippedWorkHours = 0
var skippedTitles = 0
var skippedStatus = 0
for ev in srcEvents { for ev in srcEvents {
if mirrorAcceptedOnly, ev.hasAttendees {
// Only include events where the current user's attendee status is Accepted
let attendees = ev.attendees ?? []
if let me = attendees.first(where: { $0.isCurrentUser }) {
if me.participantStatus != .accepted {
skippedStatus += 1
continue
}
} else {
// If we cannot determine a self attendee, treat as not accepted
skippedStatus += 1
continue
}
}
if enforceWorkHours, !ev.isAllDay, let start = ev.startDate,
isOutsideWorkHours(start, calendar: cal, startMinutes: allowedStartMinutes, endMinutes: allowedEndMinutes) {
skippedWorkHours += 1
continue
}
if shouldSkip(event: ev, filters: titleFilters) {
skippedTitles += 1
continue
}
if SKIP_ALL_DAY_DEFAULT == true && mirrorAllDay == false && ev.isAllDay { continue } if SKIP_ALL_DAY_DEFAULT == true && mirrorAllDay == false && ev.isAllDay { continue }
if isMirrorEvent(ev, prefix: titlePrefix, placeholder: placeholderTitle) { if isMirrorEvent(ev, prefix: titlePrefix, placeholder: placeholderTitle) {
// Aggregate skip count for mirrored-on-source // Aggregate skip count for mirrored-on-source
@@ -720,6 +947,15 @@ struct ContentView: View {
if skippedMirrors > 0 { if skippedMirrors > 0 {
log("- SKIP mirrored-on-source: \(skippedMirrors) instance(s)") log("- SKIP mirrored-on-source: \(skippedMirrors) instance(s)")
} }
if skippedWorkHours > 0 {
log("- SKIP outside work hours: \(skippedWorkHours) event(s)")
}
if skippedTitles > 0 {
log("- SKIP title filter: \(skippedTitles) event(s)")
}
if skippedStatus > 0 {
log("- SKIP non-accepted status: \(skippedStatus) event(s)")
}
// Deduplicate source blocks to avoid duplicates from EventKit (recurrences / sync races) // Deduplicate source blocks to avoid duplicates from EventKit (recurrences / sync races)
srcBlocks = uniqueBlocks(srcBlocks, trackByID: mergeGapMin == 0) srcBlocks = uniqueBlocks(srcBlocks, trackByID: mergeGapMin == 0)
@@ -770,6 +1006,7 @@ struct ContentView: View {
var created = 0 var created = 0
var skipped = 0 var skipped = 0
var updated = 0 var updated = 0
var warnedPrivateUnsupported = false
// Cross-route loop guard: unique key generator for (source, occurrence/time, target) // Cross-route loop guard: unique key generator for (source, occurrence/time, target)
func guardKey(for blk: Block, targetID: String) -> String { func guardKey(for blk: Block, targetID: String) -> String {
@@ -816,6 +1053,11 @@ struct ContentView: View {
let sid0 = blk.srcEventID ?? "" let sid0 = blk.srcEventID ?? ""
let occ0 = blk.occurrence?.timeIntervalSince1970 ?? blk.start.timeIntervalSince1970 let occ0 = blk.occurrence?.timeIntervalSince1970 ?? blk.start.timeIntervalSince1970
existingByTime.url = URL(string: "mirror://\(tgt.calendarIdentifier)|\(srcCal.calendarIdentifier)|\(sid0)|\(occ0)|\(blk.start.timeIntervalSince1970)|\(blk.end.timeIntervalSince1970)") existingByTime.url = URL(string: "mirror://\(tgt.calendarIdentifier)|\(srcCal.calendarIdentifier)|\(sid0)|\(occ0)|\(blk.start.timeIntervalSince1970)|\(blk.end.timeIntervalSince1970)")
let okTime = setEventPrivateIfSupported(existingByTime, markPrivate)
if markPrivate && !okTime && !warnedPrivateUnsupported {
log("- INFO: Mark Private not supported for \(tgtName) [source: \(tgt.source.title)]")
warnedPrivateUnsupported = true
}
do { do {
try store.save(existingByTime, span: .thisEvent, commit: true) try store.save(existingByTime, span: .thisEvent, commit: true)
log("✓ UPDATED [\(srcName) -> \(tgtName)] (by time) \(blk.start) -> \(blk.end)") log("✓ UPDATED [\(srcName) -> \(tgtName)] (by time) \(blk.start) -> \(blk.end)")
@@ -858,6 +1100,11 @@ struct ContentView: View {
existing.notes = nil existing.notes = nil
} }
existing.url = URL(string: "mirror://\(tgt.calendarIdentifier)|\(srcCal.calendarIdentifier)|\(sid)|\(occTS)|\(blk.start.timeIntervalSince1970)|\(blk.end.timeIntervalSince1970)") existing.url = URL(string: "mirror://\(tgt.calendarIdentifier)|\(srcCal.calendarIdentifier)|\(sid)|\(occTS)|\(blk.start.timeIntervalSince1970)|\(blk.end.timeIntervalSince1970)")
let okOcc = setEventPrivateIfSupported(existing, markPrivate)
if markPrivate && !okOcc && !warnedPrivateUnsupported {
log("- INFO: Mark Private not supported for \(tgtName) [source: \(tgt.source.title)]")
warnedPrivateUnsupported = true
}
do { do {
try store.save(existing, span: .thisEvent, commit: true) try store.save(existing, span: .thisEvent, commit: true)
log("✓ UPDATED [\(srcName) -> \(tgtName)] \(blk.start) -> \(blk.end)") log("✓ UPDATED [\(srcName) -> \(tgtName)] \(blk.start) -> \(blk.end)")
@@ -898,6 +1145,11 @@ struct ContentView: View {
let occTS = blk.occurrence?.timeIntervalSince1970 ?? blk.start.timeIntervalSince1970 let occTS = blk.occurrence?.timeIntervalSince1970 ?? blk.start.timeIntervalSince1970
newEv.url = URL(string: "mirror://\(tgt.calendarIdentifier)|\(srcCal.calendarIdentifier)|\(sid)|\(occTS)|\(blk.start.timeIntervalSince1970)|\(blk.end.timeIntervalSince1970)") newEv.url = URL(string: "mirror://\(tgt.calendarIdentifier)|\(srcCal.calendarIdentifier)|\(sid)|\(occTS)|\(blk.start.timeIntervalSince1970)|\(blk.end.timeIntervalSince1970)")
newEv.availability = .busy newEv.availability = .busy
let okNew = setEventPrivateIfSupported(newEv, markPrivate)
if markPrivate && !okNew && !warnedPrivateUnsupported {
log("- INFO: Mark Private not supported for \(tgtName) [source: \(tgt.source.title)]")
warnedPrivateUnsupported = true
}
do { do {
try store.save(newEv, span: .thisEvent, commit: true) try store.save(newEv, span: .thisEvent, commit: true)
created += 1 created += 1
@@ -938,23 +1190,46 @@ struct ContentView: View {
} }
} }
log("[Summary → \(tgtName)] created=\(created), updated=\(updated), skipped=\(skipped)") log("[Summary → \(tgtName)] created=\(created), updated=\(updated), skipped=\(skipped)")
// Auto-delete placeholders whose source instance no longer exists // Auto-delete placeholders whose source instance no longer exists.
// Works even when no source events remain in the window, and
// also cleans up legacy mirrors that lack a mirror URL (by time).
if autoDeleteMissing { if autoDeleteMissing {
let validKeys: Set<String> = Set(baseBlocks.compactMap { blk in let trackByID = (mergeGapMin == 0)
if (mergeGapMin == 0), let sid = blk.srcEventID { // Build valid occurrence keys from current source blocks (when trackByID)
let validOccKeys: Set<String> = Set(baseBlocks.compactMap { blk in
guard trackByID, let sid = blk.srcEventID else { return nil }
let occTS = blk.occurrence?.timeIntervalSince1970 ?? blk.start.timeIntervalSince1970 let occTS = blk.occurrence?.timeIntervalSince1970 ?? blk.start.timeIntervalSince1970
return "\(sid)|\(occTS)" return "\(sid)|\(occTS)"
}
return nil
}) })
if !validKeys.isEmpty { // Also build valid time keys for legacy/fallback cleanup
let validTimeKeys: Set<String> = Set(baseBlocks.map { blk in
"\(blk.start.timeIntervalSince1970)|\(blk.end.timeIntervalSince1970)"
})
// Consider all known placeholders on target (URL or title-identified)
// Deduplicate by eventIdentifier to avoid double-processing updated items
var byID: [String: EKEvent] = [:]
for tv in placeholdersByTime.values {
guard tv.calendar.calendarIdentifier == tgt.calendarIdentifier else { continue }
if let eid = tv.eventIdentifier { byID[eid] = tv }
}
var removed = 0 var removed = 0
for (_, ev) in placeholdersByOccurrenceID { for ev in byID.values {
if ev.calendar.calendarIdentifier != tgt.calendarIdentifier { continue }
let parsed = parseMirrorURL(ev.url) let parsed = parseMirrorURL(ev.url)
var shouldDelete = false
if let sid = parsed.srcEventID, let occ = parsed.occ { if let sid = parsed.srcEventID, let occ = parsed.occ {
let k = "\(sid)|\(occ.timeIntervalSince1970)" let k = "\(sid)|\(occ.timeIntervalSince1970)"
if !validKeys.contains(k) { // If key not present among current source instances, delete
if !validOccKeys.contains(k) { shouldDelete = true }
} else if trackByID {
// Legacy fallback: no URL -> compare exact time window membership
if let s = ev.startDate, let e = ev.endDate {
let tk = "\(s.timeIntervalSince1970)|\(e.timeIntervalSince1970)"
if !validTimeKeys.contains(tk) { shouldDelete = true }
}
}
if shouldDelete {
if !writeEnabled { if !writeEnabled {
log("~ WOULD DELETE (missing source) [\(srcName) -> \(tgtName)] \(ev.startDate ?? windowStart) -> \(ev.endDate ?? windowEnd)") log("~ WOULD DELETE (missing source) [\(srcName) -> \(tgtName)] \(ev.startDate ?? windowStart) -> \(ev.endDate ?? windowEnd)")
} else { } else {
@@ -963,11 +1238,230 @@ struct ContentView: View {
} }
} }
} }
}
if removed > 0 { log("[Cleanup missing for \(tgtName)] deleted=\(removed)") } if removed > 0 { log("[Cleanup missing for \(tgtName)] deleted=\(removed)") }
} }
} }
} }
// MARK: - Export / Import Settings
private struct SettingsPayload: Codable {
var daysBack: Int
var daysForward: Int
var mergeGapHours: Int
var hideDetails: Bool
var copyDescription: Bool
var markPrivate: Bool
var mirrorAllDay: Bool
var filterByWorkHours: Bool = false
var workHoursStart: Int = 9
var workHoursEnd: Int = 17
var excludedTitleFilters: [String] = []
var mirrorAcceptedOnly: Bool = false
var overlapMode: String
var titlePrefix: String
var placeholderTitle: String
var autoDeleteMissing: Bool
var routes: [Route]
// UI selections (optional for backward compatibility)
var selectedSourceID: String? = nil
var selectedTargetIDs: [String]? = nil
// optional metadata
var appVersion: String?
var exportedAt: Date = Date()
}
private func makeSnapshot() -> SettingsPayload {
SettingsPayload(
daysBack: daysBack,
daysForward: daysForward,
mergeGapHours: mergeGapHours,
hideDetails: hideDetails,
copyDescription: copyDescription,
markPrivate: markPrivate,
mirrorAllDay: mirrorAllDay,
filterByWorkHours: filterByWorkHours,
workHoursStart: workHoursStart,
workHoursEnd: workHoursEnd,
excludedTitleFilters: excludedTitleFilterList,
mirrorAcceptedOnly: mirrorAcceptedOnly,
overlapMode: overlapMode.rawValue,
titlePrefix: titlePrefix,
placeholderTitle: placeholderTitle,
autoDeleteMissing: autoDeleteMissing,
routes: routes,
selectedSourceID: sourceID,
selectedTargetIDs: Array(targetIDs).sorted(),
appVersion: Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String,
exportedAt: Date()
)
}
private func applySnapshot(_ s: SettingsPayload) {
daysBack = s.daysBack
daysForward = s.daysForward
mergeGapHours = s.mergeGapHours
mergeGapMin = max(0, s.mergeGapHours * 60)
hideDetails = s.hideDetails
copyDescription = s.copyDescription
mirrorAllDay = s.mirrorAllDay
markPrivate = s.markPrivate
filterByWorkHours = s.filterByWorkHours
workHoursStart = s.workHoursStart
workHoursEnd = s.workHoursEnd
excludedTitleFiltersRaw = s.excludedTitleFilters.joined(separator: "\n")
mirrorAcceptedOnly = s.mirrorAcceptedOnly
overlapMode = OverlapMode(rawValue: s.overlapMode) ?? .allow
titlePrefix = s.titlePrefix
placeholderTitle = s.placeholderTitle
autoDeleteMissing = s.autoDeleteMissing
routes = s.routes
// Restore UI selections if provided
if let selSrc = s.selectedSourceID { sourceID = selSrc }
if let selTgts = s.selectedTargetIDs { targetIDs = Set(selTgts) }
clampWorkHours()
// Rebuild indices from IDs after restoring selections
rebuildSelectionsFromIDs()
}
private func exportSettings() {
let panel = NSSavePanel()
panel.allowedFileTypes = ["json"]
panel.nameFieldStringValue = "BusyMirror-Settings.json"
panel.canCreateDirectories = true
panel.isExtensionHidden = false
if panel.runModal() == .OK, let url = panel.url {
do {
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
let data = try encoder.encode(makeSnapshot())
try data.write(to: url, options: Data.WritingOptions.atomic)
log("✓ Exported settings to \(url.path)")
} catch {
log("✗ Export failed: \(error.localizedDescription)")
}
}
}
private func importSettings() {
let panel = NSOpenPanel()
panel.allowedFileTypes = ["json"]
panel.allowsMultipleSelection = false
panel.canChooseDirectories = false
if panel.runModal() == .OK, let url = panel.url {
do {
let data = try Data(contentsOf: url)
let snap = try JSONDecoder().decode(SettingsPayload.self, from: data)
applySnapshot(snap)
saveSettingsToDefaults()
log("✓ Imported settings from \(url.lastPathComponent)")
} catch {
log("✗ Import failed: \(error.localizedDescription)")
}
}
}
// MARK: - Settings persistence (UserDefaults)
private let settingsDefaultsKey = "settings.v2"
private let legacyRoutesDefaultsKey = "routes.v1"
private func saveSettingsToDefaults() {
do {
let data = try JSONEncoder().encode(makeSnapshot())
UserDefaults.standard.set(data, forKey: settingsDefaultsKey)
} catch {
log("✗ Failed to save settings: \(error.localizedDescription)")
}
}
private func loadSettingsFromDefaults() {
let defaults = UserDefaults.standard
if let data = defaults.data(forKey: settingsDefaultsKey) {
do {
let snap = try JSONDecoder().decode(SettingsPayload.self, from: data)
applySnapshot(snap)
} catch {
log("✗ Failed to load settings: \(error.localizedDescription)")
}
return
}
// Legacy fallback: routes-only payload
guard let legacyData = defaults.data(forKey: legacyRoutesDefaultsKey) else { return }
do {
let decodedRoutes = try JSONDecoder().decode([Route].self, from: legacyData)
routes = decodedRoutes
clampWorkHours()
saveSettingsToDefaults() // upgrade stored format
} catch {
log("✗ Failed to load routes: \(error.localizedDescription)")
}
}
// MARK: - Filters
private func isOutsideWorkHours(_ startDate: Date, calendar: Calendar, startMinutes: Int, endMinutes: Int) -> Bool {
guard endMinutes > startMinutes else { return false }
let comps = calendar.dateComponents([.hour, .minute], from: startDate)
guard let hour = comps.hour else { return false }
let minute = comps.minute ?? 0
let start = hour * 60 + minute
return start < startMinutes || start >= endMinutes
}
// Best-effort: mark an event as Private if the account/server supports it.
// Uses ObjC selector lookup to avoid crashes on unsupported keys.
private func setEventPrivateIfSupported(_ ev: EKEvent, _ flag: Bool) -> Bool {
guard flag else { return false }
let sel = Selector(("setPrivate:"))
if ev.responds(to: sel) {
_ = ev.perform(sel, with: NSNumber(value: true))
return true
}
// Some backends may expose privacy level via a numeric setter
let sel2 = Selector(("setPrivacy:"))
if ev.responds(to: sel2) {
// 1 may represent private on some providers; this is best-effort.
_ = ev.perform(sel2, with: NSNumber(value: 1))
return true
}
// Try common KVC keys seen in some providers (best-effort, may be no-ops)
let kvPairs: [(String, Any)] = [
("private", true),
("isPrivate", true),
("privacy", 1),
("sensitivity", 1), // Exchange often: 1=personal, 2=private; varies
("classification", 1) // iCalendar CLASS: 1 might map to PRIVATE
]
for (key, val) in kvPairs {
do {
ev.setValue(val, forKey: key)
return true
} catch {
// ignore and try next
}
}
// Not supported; no-op
return false
}
private func shouldSkip(event: EKEvent, filters: [String]) -> Bool {
guard !filters.isEmpty else { return false }
let rawTitle = (event.title ?? "").lowercased()
let strippedTitle = stripPrefix(event.title, prefix: titlePrefix).lowercased()
return filters.contains { token in
rawTitle.contains(token) || strippedTitle.contains(token)
}
}
private func clampWorkHours() {
let clampedStart = min(max(workHoursStart, 0), 23)
if clampedStart != workHoursStart { workHoursStart = clampedStart }
let clampedEnd = min(max(workHoursEnd, 1), 24)
if clampedEnd != workHoursEnd { workHoursEnd = clampedEnd }
if workHoursEnd <= workHoursStart {
let adjustedEnd = min(workHoursStart + 1, 24)
if workHoursEnd != adjustedEnd { workHoursEnd = adjustedEnd }
}
} }
// MARK: - Logging // MARK: - Logging

28
CHANGELOG.md Normal file
View File

@@ -0,0 +1,28 @@
# Changelog
# Changelog
All notable changes to BusyMirror will be documented in this file.
## [1.3.1] - 2025-10-13
- Fix: auto-delete of mirrored placeholders when the source is removed now works even if no source instances remain in the window. Also cleans legacy mirrors without URLs by matching exact times.
## [1.2.4] - 2025-10-10
- Fix: enable “Mirror Now” when Routes are defined even if no Source/Targets are checked in the main window. Button now enables if either routes exist or a manual selection is present.
## [1.3.0] - 2025-10-10
- New: Mark Private option to mirror with prefix + real title and set event privacy on supported servers; available globally and per-route; persisted.
- Misc: calendar access fixes, concurrency annotations, acceptedonly filter, settings autosave/restore, Mirror Now enablement.
## [1.2.3] - 2025-10-10
- Fix: reliably save and restore settings between runs via autosave of key options and restoration of source/target selections by persistent IDs.
- UX: persist Source and Target selections; rebuild indices on launch so UI matches saved IDs.
- Build: bump version to 1.2.3 (build 5).
## [1.2.1] - 2025-10-10
- Fix: reinitialize EKEventStore after permission grant to avoid “Loaded 0 calendars” right after approval.
- Fix: attendee status filter uses current users attendee `participantStatus == .accepted` instead of unavailable APIs.
- Concurrency: mark `requestAccess()` and `reloadCalendars()` as `@MainActor` to satisfy strict concurrency checks.
- Dev: add Makefile with `build-debug`, `build-release`, and `package` targets; produce versioned ZIP + SHA-256.
## [1.2.0] - 2024-09-29
- Feature: multi-route mirroring, overlap modes, merge gaps, work hours filter, CLI support, export/import settings.

46
Makefile Normal file
View File

@@ -0,0 +1,46 @@
# Simple build and package helpers for BusyMirror
SCHEME ?= BusyMirror
PROJECT ?= BusyMirror.xcodeproj
DERIVED ?= build/DerivedData
DEST := platform=macOS
# Extract marketing version from project settings
VERSION := $(shell sed -n 's/.*MARKETING_VERSION = \([0-9.]*\);.*/\1/p' $(PROJECT)/project.pbxproj | head -n1)
.PHONY: all clean build-debug build-release open app package
all: build-release
clean:
@echo "Cleaning derived data…"
xcodebuild -scheme $(SCHEME) -project $(PROJECT) -derivedDataPath $(DERIVED) -destination '$(DEST)' CODE_SIGNING_ALLOWED=NO clean >/dev/null
@echo "Done."
build-debug:
@echo "Building Debug…"
xcodebuild -scheme $(SCHEME) -project $(PROJECT) -configuration Debug -destination '$(DEST)' -derivedDataPath $(DERIVED) CODE_SIGNING_ALLOWED=NO build
build-release:
@echo "Building Release…"
xcodebuild -scheme $(SCHEME) -project $(PROJECT) -configuration Release -destination '$(DEST)' -derivedDataPath $(DERIVED) CODE_SIGNING_ALLOWED=NO build
# Convenience to open the built app in Finder
open: app
@open "$<"
# Path to built app (Release)
APP_PATH := $(DERIVED)/Build/Products/Release/BusyMirror.app
app: build-release
@# Ensure the app exists
@test -d "$(APP_PATH)" && echo "Built: $(APP_PATH)" || (echo "App not found at $(APP_PATH)" && exit 1)
@echo "Version: $(VERSION)"
@echo "OK"
package: app
@echo "Packaging BusyMirror $(VERSION)"
@zip -qry "BusyMirror-$(VERSION)-macOS.zip" "$(APP_PATH)"
@shasum -a 256 "BusyMirror-$(VERSION)-macOS.zip" | awk '{print $$1}' > "BusyMirror-$(VERSION)-macOS.zip.sha256"
@echo "Created BusyMirror-$(VERSION)-macOS.zip and .sha256"

View File

@@ -2,23 +2,43 @@
BusyMirror mirrors meetings between your calendars so your availability stays consistent across accounts/devices. BusyMirror mirrors meetings between your calendars so your availability stays consistent across accounts/devices.
## What it does (current checkpoint) ## What it does (current)
- Manual “Run” to mirror events across selected routes (Source → Targets). - Route-driven mirroring (multi-source): define Source → Targets routes and run them in one go.
- DRY-RUN mode shows what would happen. - Manual selection mirroring: pick a source and targets in the UI and run.
- Prefix-based tagging of mirrored events. - Two privacy modes:
- Cleanup of placeholders (with confirmation). - Private (hide details): mirrors placeholders with prefix + placeholder title (e.g., "🪞 Busy").
- Loop/duplicate guards so mirrors dont replicate themselves. - Mark Private: mirrors prefix + real title, but marks events Private on supported servers (best-effort).
- Time window and merge-gap settings. - DRY-RUN mode: see what would be created/updated/deleted without writing.
- Overlap modes: `allow`, `skipCovered`, `fillGaps`.
- Merge adjacent events with a configurable gap.
- Time window controls (days back/forward) and Work Hours filter.
- Accepted-only filter (mirror your accepted meetings only).
- Cleanup of placeholders, including auto-delete of mirrors whose source disappeared.
- Prefix-based tagging and loop guards to prevent re-mirroring mirrors.
- Settings: autosave/restore, Import/Export JSON.
## Why ## Why
Use one calendars confirmed meetings to block time in other calendars (e.g., corporate iPad vs. personal devices). Use one calendars confirmed meetings to block time in other calendars (e.g., corporate iPad vs. personal devices).
## Build (macOS) ## Build (macOS)
Option A — Xcode
1. Open `BusyMirror.xcodeproj` in Xcode. 1. Open `BusyMirror.xcodeproj` in Xcode.
2. Select the BusyMirror scheme → My Mac. 2. Select the BusyMirror scheme → My Mac.
3. Product → Build. 3. Product → Build.
4. Product → Archive → Distribute App → Copy App (no notarization) to export a `.app` (or ZIP it for sharing). 4. Product → Archive → Distribute App → Copy App (no notarization) to export a `.app` (or ZIP it for sharing).
Option B — Makefile (reproducible)
- Build Release: `make build-release`
- Package ZIP: `make package` (creates `BusyMirror-<version>-macOS.zip` + `.sha256`)
- Built app: `build/DerivedData/Build/Products/Release/BusyMirror.app`
See `CHANGELOG.md` for notable changes.
## CLI (optional)
- Run from Terminal with `--routes` to mirror without the UI. Example:
- `BusyMirror.app/Contents/MacOS/BusyMirror --routes "1->2,3; 4->5" --write 1 --days-forward 7 --mode allow --exit`
- Flags exist for privacy, all-day, merge gap, days window, overlap mode, and cleanup.
## Roadmap ## Roadmap
See [ROADMAP.md](ROADMAP.md) See [ROADMAP.md](ROADMAP.md)

View File

@@ -1,17 +1,26 @@
# BusyMirror Roadmap # BusyMirror Roadmap
## Shipped (highlights)
- Route-driven mirroring (multi-source)
- Accepted-only filter (mirror your accepted meetings)
- Persistent settings with autosave/restore; Import/Export JSON
- Overlap modes (allow, skipCovered, fillGaps) and merge-gap
- Work Hours filter and title-based skip filters
- Privacy: placeholders with prefix + customizable title
- 1.3.0: Mark Private option (global + per-route)
## Next ## Next
- Source filters (name patterns like `[HOLD]`, `#nomirror`) - Auto-refresh calendars on `EKEventStoreChanged` (live refresh button-less)
- Mirror only **Accepted** meetings (exclude tentative/declined) - Hint near "Mirror Now" indicating run mode (Routes vs Manual)
- Persistent settings (routes, window, prefix) - Better server-side privacy mapping (per-provider heuristics)
- Import/Export settings (.busymirror.json)
## Then ## Then
- iOS/iPadOS app (Run Now, Shortcuts, iCloud sync) - Signed/notarized binaries and release pipeline
- UI: route editor & clearer toggles - CLI quality: friendlier `--routes` parsing and help flag
- “Dry-run by default” preference - “Dry-run by default” preference
## Later ## Later
- Background monitoring (macOS) - Background monitoring (macOS)
- Smarter cleanup & conflict resolution - Smarter cleanup & conflict resolution
- iOS/iPadOS helper (Shortcuts integration)
- Profiles & MDM/Managed Config support - Profiles & MDM/Managed Config support

24
ReleaseNotes-1.2.3.md Normal file
View File

@@ -0,0 +1,24 @@
# BusyMirror 1.2.3 — 2025-10-10
This release focuses on reliable settings persistence and quality-of-life fixes from the 1.2.1 hotfix.
Highlights
- Settings persist between runs: autosave key options on change; restore on launch.
- Source/Target selection is remembered using calendar IDs and rehydrated into UI indices.
Fixes and improvements
- Save on change for: days back/forward, default merge gap, privacy/copy notes, all-day, accepted-only, overlap mode, title/placeholder prefixes, auto-delete.
- Restore saved `selectedSourceID` and `selectedTargetIDs` and rebuild index selections.
- Keep backward compatibility with older saved payloads.
- Version bump to 1.2.3 (build 5).
Included from 1.2.1
- Reinitialize `EKEventStore` after permission grant to avoid “Loaded 0 calendars”.
- Use attendee `participantStatus == .accepted` for accepted-only filter.
- Mark `requestAccess()` and `reloadCalendars()` as `@MainActor`.
- Makefile for reproducible builds and packaging.
Build
- `make build-release`
- `make package` → BusyMirror-1.2.3-macOS.zip and .sha256

11
ReleaseNotes-1.2.4.md Normal file
View File

@@ -0,0 +1,11 @@
# BusyMirror 1.2.4 — 2025-10-10
Bugfix release improving route-driven mirroring.
Fixes
- Mirror Now is enabled when routes are defined, even if nothing is checked in the main window. This allows fully route-driven runs without requiring a temporary manual selection.
Build
- `make build-release`
- `make package` → BusyMirror-1.2.4-macOS.zip and .sha256

17
ReleaseNotes-1.3.0.md Normal file
View File

@@ -0,0 +1,17 @@
# BusyMirror 1.3.0 — 2025-10-10
New
- Mark Private option: mirror events with your prefix + real title while marking them Private on supported servers (e.g., Exchange). Coworkers see the time block but not the details.
- Per-route and global toggles for Mark Private; persists in settings and export/import.
Fixes & improvements
- More reliable calendar loading after permission grant (reinit EKEventStore).
- Concurrency: `@MainActor` on permission/refresh methods.
- Acceptedonly filter via current user attendee `participantStatus`.
- Settings autosave and restore (including source/target selections by IDs).
- Mirror Now enabled when calendars available; routes or manual selection used as appropriate.
Build
- `make build-release`
- `make package` → BusyMirror-1.3.0-macOS.zip and .sha256

6
ReleaseNotes-1.3.1.md Normal file
View File

@@ -0,0 +1,6 @@
BusyMirror 1.3.1 — Bugfix Release
- Fix: Auto-delete mirrored placeholders when the source event is removed.
- Triggers even if no source instances remain in the selected window.
- Also cleans legacy mirrors without mirror URLs by matching exact times.