worktree_io/scheme/
mod.rs1use anyhow::Result;
2
3#[cfg(target_os = "macos")]
4mod macos;
5
6#[cfg(target_os = "linux")]
7mod linux;
8
9#[cfg(target_os = "windows")]
10mod windows;
11
12#[derive(Debug, Clone, PartialEq)]
13pub enum SchemeStatus {
14 Installed { path: String },
15 NotInstalled,
16}
17
18impl std::fmt::Display for SchemeStatus {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 match self {
21 Self::Installed { path } => write!(f, "Installed at {path}"),
22 Self::NotInstalled => write!(f, "Not installed"),
23 }
24 }
25}
26
27pub fn install() -> Result<()> {
28 platform_install()
29}
30
31pub fn uninstall() -> Result<()> {
32 platform_uninstall()
33}
34
35pub fn status() -> Result<SchemeStatus> {
36 platform_status()
37}
38
39#[cfg(target_os = "macos")]
42fn platform_install() -> Result<()> { macos::install() }
43
44#[cfg(target_os = "macos")]
45fn platform_uninstall() -> Result<()> { macos::uninstall() }
46
47#[cfg(target_os = "macos")]
48fn platform_status() -> Result<SchemeStatus> { macos::status() }
49
50#[cfg(target_os = "linux")]
53fn platform_install() -> Result<()> { linux::install() }
54
55#[cfg(target_os = "linux")]
56fn platform_uninstall() -> Result<()> { linux::uninstall() }
57
58#[cfg(target_os = "linux")]
59fn platform_status() -> Result<SchemeStatus> { linux::status() }
60
61#[cfg(target_os = "windows")]
64fn platform_install() -> Result<()> { windows::install() }
65
66#[cfg(target_os = "windows")]
67fn platform_uninstall() -> Result<()> { windows::uninstall() }
68
69#[cfg(target_os = "windows")]
70fn platform_status() -> Result<SchemeStatus> { windows::status() }
71
72#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
75fn platform_install() -> Result<()> {
76 anyhow::bail!("URL scheme registration is not supported on this platform")
77}
78
79#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
80fn platform_uninstall() -> Result<()> {
81 anyhow::bail!("URL scheme registration is not supported on this platform")
82}
83
84#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
85fn platform_status() -> Result<SchemeStatus> {
86 Ok(SchemeStatus::NotInstalled)
87}