mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
fix: Add macOS support for time sync command
Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
parent
ac08ffb54f
commit
0a9f9c6612
1 changed files with 32 additions and 8 deletions
26
src/ui.rs
26
src/ui.rs
|
|
@ -71,8 +71,9 @@ pub fn trigger_sync(frame: &LtcFrame) -> Result<String, ()> {
|
||||||
.from_local_datetime(&naive_dt)
|
.from_local_datetime(&naive_dt)
|
||||||
.single()
|
.single()
|
||||||
.expect("Ambiguous or invalid local time");
|
.expect("Ambiguous or invalid local time");
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
let (ts, success) = {
|
||||||
let ts = dt_local.format("%H:%M:%S.%3f").to_string();
|
let ts = dt_local.format("%H:%M:%S.%3f").to_string();
|
||||||
|
|
||||||
let success = Command::new("sudo")
|
let success = Command::new("sudo")
|
||||||
.arg("date")
|
.arg("date")
|
||||||
.arg("-s")
|
.arg("-s")
|
||||||
|
|
@ -80,6 +81,29 @@ pub fn trigger_sync(frame: &LtcFrame) -> Result<String, ()> {
|
||||||
.status()
|
.status()
|
||||||
.map(|s| s.success())
|
.map(|s| s.success())
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
(ts, success)
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
let (ts, success) = {
|
||||||
|
// macOS `date` command format is `mmddHHMMccyy.SS`
|
||||||
|
let ts = dt_local.format("%m%d%H%M%y.%S").to_string();
|
||||||
|
let success = Command::new("sudo")
|
||||||
|
.arg("date")
|
||||||
|
.arg(&ts)
|
||||||
|
.status()
|
||||||
|
.map(|s| s.success())
|
||||||
|
.unwrap_or(false);
|
||||||
|
(ts, success)
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||||
|
let (ts, success) = {
|
||||||
|
// Unsupported OS, always fail
|
||||||
|
let ts = dt_local.format("%H:%M:%S.%3f").to_string();
|
||||||
|
eprintln!("Unsupported OS for time synchronization");
|
||||||
|
(ts, false)
|
||||||
|
};
|
||||||
|
|
||||||
if success {
|
if success {
|
||||||
Ok(ts)
|
Ok(ts)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue