Skip to content

Commit e1231e4

Browse files
committed
MacOS support
1 parent 9513e08 commit e1231e4

2 files changed

Lines changed: 25 additions & 21 deletions

File tree

src/main.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use crossterm::{
2525
use google::{CalendarClient, GoogleAuth, TokenInfo};
2626
use icloud::{CalDavClient, ICalEvent, ICloudAuth};
2727
use std::io::stdout;
28-
use std::os::unix::process::CommandExt;
2928
use std::time::Duration as StdDuration;
29+
use utils::open_url;
3030
use tokio::sync::mpsc;
3131

3232
/// Messages from async tasks to main loop
@@ -516,10 +516,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
516516
// Join meeting
517517
if let Some(event) = app.get_selected_event()
518518
&& let Some(ref url) = event.meeting_url {
519-
let _ = std::process::Command::new("xdg-open")
520-
.arg(url)
521-
.process_group(0)
522-
.spawn();
519+
open_url(url);
523520
}
524521
}
525522
(KeyCode::Char('a') | KeyCode::Char('а'), _) => {
@@ -589,16 +586,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
589586
execute!(stdout(), Clear(ClearType::All)).ok();
590587
}
591588
(KeyCode::Char('1'), _) => {
592-
let _ = std::process::Command::new("xdg-open")
593-
.arg("https://calendar.google.com")
594-
.process_group(0)
595-
.spawn();
589+
open_url("https://calendar.google.com");
596590
}
597591
(KeyCode::Char('2'), _) => {
598-
let _ = std::process::Command::new("xdg-open")
599-
.arg("https://www.icloud.com/calendar")
600-
.process_group(0)
601-
.spawn();
592+
open_url("https://www.icloud.com/calendar");
602593
}
603594
(KeyCode::Char('q') | KeyCode::Char('я'), _) => {
604595
break;
@@ -652,16 +643,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
652643
execute!(stdout(), Clear(ClearType::All)).ok();
653644
}
654645
(KeyCode::Char('1'), _) => {
655-
let _ = std::process::Command::new("xdg-open")
656-
.arg("https://calendar.google.com")
657-
.process_group(0)
658-
.spawn();
646+
open_url("https://calendar.google.com");
659647
}
660648
(KeyCode::Char('2'), _) => {
661-
let _ = std::process::Command::new("xdg-open")
662-
.arg("https://www.icloud.com/calendar")
663-
.process_group(0)
664-
.spawn();
649+
open_url("https://www.icloud.com/calendar");
665650
}
666651
(KeyCode::Char('g') | KeyCode::Char('г'), _) => {
667652
// Start Google auth flow (only if not already authenticated)

src/utils.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
33
use crate::cache::{AttendeeStatus, DisplayAttendee};
44

5+
/// Open a URL in the default browser (platform-specific)
6+
#[cfg(target_os = "macos")]
7+
pub fn open_url(url: &str) {
8+
use std::os::unix::process::CommandExt;
9+
let _ = std::process::Command::new("open")
10+
.arg(url)
11+
.process_group(0)
12+
.spawn();
13+
}
14+
15+
#[cfg(target_os = "linux")]
16+
pub fn open_url(url: &str) {
17+
use std::os::unix::process::CommandExt;
18+
let _ = std::process::Command::new("xdg-open")
19+
.arg(url)
20+
.process_group(0)
21+
.spawn();
22+
}
23+
524
/// Sort order for attendee status (lower = first)
625
pub fn status_sort_order(status: &AttendeeStatus) -> u8 {
726
match status {

0 commit comments

Comments
 (0)