mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Update Notion Calendar
This commit is contained in:
parent
ab7d2619d7
commit
563afde92f
4 changed files with 110 additions and 20 deletions
|
|
@ -268,6 +268,34 @@ enum FantasticalViewStyle: String, CaseIterable, Codable, Defaults.Serializable
|
|||
}
|
||||
}
|
||||
|
||||
enum ThirdPartyCalendarApp: String, CaseIterable, Codable, Defaults.Serializable, Identifiable {
|
||||
case fantastical = "fantastical"
|
||||
case notionCalendar = "notionCalendar"
|
||||
|
||||
var id: String { rawValue }
|
||||
|
||||
var displayName: String {
|
||||
switch self {
|
||||
case .fantastical: return "Fantastical"
|
||||
case .notionCalendar: return "Notion Calendar"
|
||||
}
|
||||
}
|
||||
|
||||
var iconName: String {
|
||||
switch self {
|
||||
case .fantastical: return "calendar.badge.clock"
|
||||
case .notionCalendar: return "calendar.badge.plus"
|
||||
}
|
||||
}
|
||||
|
||||
var iconColor: Color {
|
||||
switch self {
|
||||
case .fantastical: return .red
|
||||
case .notionCalendar: return .blue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum ClipboardDisplayMode: String, CaseIterable, Codable, Defaults.Serializable {
|
||||
case popover = "popover" // Traditional popover attached to button
|
||||
case panel = "panel" // Floating panel near notch
|
||||
|
|
@ -867,7 +895,8 @@ extension Defaults.Keys {
|
|||
static let lockScreenWeatherWidgetRowOrder = Key<String>("lockScreenWeatherWidgetRowOrder", default: "weather_calendar_focus")
|
||||
|
||||
// MARK: Third-party Calendar Integration
|
||||
static let useFantasticalCalendar = Key<Bool>("useFantasticalCalendar", default: false)
|
||||
static let enableThirdPartyCalendarApp = Key<Bool>("enableThirdPartyCalendarApp", default: false)
|
||||
static let selectedCalendarApp = Key<ThirdPartyCalendarApp>("selectedCalendarApp", default: .fantastical)
|
||||
static let fantasticalDefaultView = Key<FantasticalViewStyle>("fantasticalDefaultView", default: .mini)
|
||||
|
||||
// MARK: Battery
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
import Foundation
|
||||
import Defaults
|
||||
import AppKit
|
||||
|
||||
struct EventModel: Equatable, Identifiable {
|
||||
let id: String
|
||||
|
|
@ -98,9 +99,14 @@ extension EventModel {
|
|||
var isMeeting: Bool { !participants.isEmpty }
|
||||
|
||||
func calendarAppURL() -> URL? {
|
||||
// Check if Fantastical is enabled
|
||||
if Defaults[.useFantasticalCalendar] {
|
||||
return fantasticalURL()
|
||||
// Check if a third-party calendar app is enabled
|
||||
if Defaults[.enableThirdPartyCalendarApp] {
|
||||
switch Defaults[.selectedCalendarApp] {
|
||||
case .fantastical:
|
||||
return fantasticalURL()
|
||||
case .notionCalendar:
|
||||
return notionCalendarURL()
|
||||
}
|
||||
}
|
||||
return appleCalendarURL()
|
||||
}
|
||||
|
|
@ -160,6 +166,48 @@ extension EventModel {
|
|||
}
|
||||
return URL(string: "x-fantastical3://show/\(viewStyle.rawValue)")
|
||||
}
|
||||
|
||||
/// Returns URL to open event in Notion Calendar (formerly Cron)
|
||||
private func notionCalendarURL() -> URL? {
|
||||
// Reminders still use Apple's Reminders app
|
||||
guard !type.isReminder else {
|
||||
return URL(string: "x-apple-reminderkit://remcdreminder/\(id)")
|
||||
}
|
||||
|
||||
let formatter = ISO8601DateFormatter()
|
||||
|
||||
var components = URLComponents()
|
||||
components.scheme = "cron"
|
||||
components.host = "showEvent"
|
||||
components.queryItems = [
|
||||
URLQueryItem(name: "accountEmail", value: calendar.accountName),
|
||||
URLQueryItem(name: "iCalUID", value: id),
|
||||
URLQueryItem(name: "startDate", value: formatter.string(from: start)),
|
||||
URLQueryItem(name: "endDate", value: formatter.string(from: end)),
|
||||
URLQueryItem(name: "title", value: title)
|
||||
]
|
||||
|
||||
if let url = components.url {
|
||||
return url
|
||||
}
|
||||
|
||||
// Fallback: just launch Notion Calendar app
|
||||
Self.launchNotionCalendar()
|
||||
return nil
|
||||
}
|
||||
|
||||
/// Launches Notion Calendar app directly (fallback or general access)
|
||||
static func launchNotionCalendar() {
|
||||
// Launch via bundle identifier (Notion Calendar's bundle ID is "com.cron.electron")
|
||||
if let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.cron.electron") {
|
||||
let config = NSWorkspace.OpenConfiguration()
|
||||
NSWorkspace.shared.openApplication(at: url, configuration: config) { _, error in
|
||||
if let error = error {
|
||||
print("Error launching Notion Calendar: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Participant: Hashable {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue