Skip to content

Commit fd06dd2

Browse files
Remove calendar-outlook, calendar-google, and calendar-interface crates (#2202)
1 parent 1d09939 commit fd06dd2

File tree

14 files changed

+156
-974
lines changed

14 files changed

+156
-974
lines changed

Cargo.lock

Lines changed: 32 additions & 687 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ hypr-audio-utils = { path = "crates/audio-utils", package = "audio-utils" }
3131
hypr-auth-interface = { path = "plugins/auth-interface", package = "auth-interface" }
3232
hypr-buffer = { path = "crates/buffer", package = "buffer" }
3333
hypr-calendar-apple = { path = "crates/calendar-apple", package = "calendar-apple" }
34-
hypr-calendar-google = { path = "crates/calendar-google", package = "calendar-google" }
35-
hypr-calendar-interface = { path = "crates/calendar-interface", package = "calendar-interface" }
36-
hypr-calendar-outlook = { path = "crates/calendar-outlook", package = "calendar-outlook" }
3734
hypr-data = { path = "crates/data", package = "data" }
3835
hypr-db-admin = { path = "crates/db-admin", package = "db-admin" }
3936
hypr-db-core = { path = "crates/db-core", package = "db-core" }

crates/calendar-apple/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ edition = "2021"
55

66
[dependencies]
77
anyhow = { workspace = true }
8-
chrono = { workspace = true }
9-
hypr-calendar-interface = { path = "../calendar-interface", package = "calendar-interface" }
10-
itertools = { workspace = true }
8+
chrono = { workspace = true, features = ["serde"] }
9+
serde = { workspace = true, features = ["derive"] }
1110

1211
[target.'cfg(target_os = "macos")'.dependencies]
12+
itertools = { workspace = true }
1313
block2 = "0.5.1"
1414
objc2 = "0.5.2"
1515
objc2-contacts = { version = "0.2.2", features = ["CNContactStore", "CNLabeledValue", "CNContact", "block2"] }

crates/calendar-apple/src/lib.rs

Lines changed: 109 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,130 @@
1+
use chrono::{DateTime, Utc};
2+
use serde::{Deserialize, Serialize};
3+
use std::future::Future;
4+
5+
pub use anyhow::Error;
6+
7+
pub trait CalendarSource {
8+
fn list_calendars(&self) -> impl Future<Output = Result<Vec<Calendar>, Error>>;
9+
fn list_events(&self, filter: EventFilter) -> impl Future<Output = Result<Vec<Event>, Error>>;
10+
}
11+
12+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13+
pub enum Platform {
14+
Apple,
15+
Google,
16+
Outlook,
17+
}
18+
19+
impl std::fmt::Display for Platform {
20+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21+
match self {
22+
Platform::Apple => write!(f, "Apple"),
23+
Platform::Google => write!(f, "Google"),
24+
Platform::Outlook => write!(f, "Outlook"),
25+
}
26+
}
27+
}
28+
29+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
30+
pub struct Calendar {
31+
pub id: String,
32+
pub platform: Platform,
33+
pub name: String,
34+
pub source: Option<String>,
35+
}
36+
37+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
38+
pub struct Event {
39+
pub id: String,
40+
pub calendar_id: String,
41+
pub platform: Platform,
42+
pub name: String,
43+
pub note: String,
44+
pub participants: Vec<Participant>,
45+
pub start_date: DateTime<Utc>,
46+
pub end_date: DateTime<Utc>,
47+
pub google_event_url: Option<String>,
48+
#[serde(default)]
49+
pub is_recurring: bool,
50+
}
51+
52+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
53+
pub struct Participant {
54+
pub name: String,
55+
pub email: Option<String>,
56+
}
57+
58+
#[derive(Debug, Serialize, Deserialize)]
59+
pub struct EventFilter {
60+
pub from: DateTime<Utc>,
61+
pub to: DateTime<Utc>,
62+
pub calendar_tracking_id: String,
63+
}
64+
65+
#[derive(Debug, Serialize, Deserialize)]
66+
pub enum Opener {
67+
AppleScript(String),
68+
Url(String),
69+
}
70+
71+
impl Event {
72+
pub fn opener(&self) -> anyhow::Result<Opener> {
73+
match self.platform {
74+
Platform::Apple => {
75+
let script = String::from(
76+
"
77+
tell application \"Calendar\"
78+
activate
79+
switch view to month view
80+
view calendar at current date
81+
end tell
82+
",
83+
);
84+
85+
Ok(Opener::AppleScript(script))
86+
}
87+
Platform::Google => {
88+
let url = self.google_event_url.as_ref().unwrap().clone();
89+
Ok(Opener::Url(url))
90+
}
91+
Platform::Outlook => {
92+
anyhow::bail!("Outlook is not supported yet");
93+
}
94+
}
95+
}
96+
}
97+
98+
#[cfg(target_os = "macos")]
199
use itertools::Itertools;
100+
#[cfg(target_os = "macos")]
2101
use std::time::Duration;
3102

103+
#[cfg(target_os = "macos")]
4104
use objc2::msg_send;
5105

106+
#[cfg(target_os = "macos")]
6107
use block2::RcBlock;
108+
#[cfg(target_os = "macos")]
7109
use objc2::{rc::Retained, runtime::Bool, ClassType};
110+
#[cfg(target_os = "macos")]
8111
use objc2_contacts::{CNAuthorizationStatus, CNContactStore, CNEntityType};
112+
#[cfg(target_os = "macos")]
9113
use objc2_event_kit::{
10114
EKAuthorizationStatus, EKCalendar, EKEntityType, EKEvent, EKEventStore, EKParticipant,
11115
};
116+
#[cfg(target_os = "macos")]
12117
use objc2_foundation::{NSArray, NSDate, NSError, NSString};
13118

14-
use hypr_calendar_interface::{
15-
Calendar, CalendarSource, Error, Event, EventFilter, Participant, Platform,
16-
};
17-
119+
#[cfg(target_os = "macos")]
18120
pub struct Handle {
19121
event_store: Retained<EKEventStore>,
20122
contacts_store: Retained<CNContactStore>,
21123
calendar_access_granted: bool,
22124
contacts_access_granted: bool,
23125
}
24126

127+
#[cfg(target_os = "macos")]
25128
#[allow(clippy::new_without_default)]
26129
impl Handle {
27130
pub fn new() -> Self {
@@ -166,6 +269,7 @@ impl Handle {
166269
}
167270
}
168271

272+
#[cfg(target_os = "macos")]
169273
impl CalendarSource for Handle {
170274
async fn list_calendars(&self) -> Result<Vec<Calendar>, Error> {
171275
if !self.calendar_access_granted {
@@ -263,6 +367,7 @@ impl CalendarSource for Handle {
263367
}
264368
}
265369

370+
#[cfg(target_os = "macos")]
266371
fn offset_date_time_from(date: Retained<NSDate>) -> chrono::DateTime<chrono::Utc> {
267372
let seconds = unsafe { date.timeIntervalSinceReferenceDate() };
268373

crates/calendar-google/Cargo.toml

Lines changed: 0 additions & 10 deletions
This file was deleted.

crates/calendar-google/src/lib.rs

Lines changed: 0 additions & 114 deletions
This file was deleted.

crates/calendar-interface/Cargo.toml

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)