Skip to main content

worktree_io/scheme/
mod.rs

1use 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}
30pub fn uninstall() -> Result<()> {
31    platform_uninstall()
32}
33pub fn status() -> Result<SchemeStatus> {
34    platform_status()
35}
36
37#[cfg(target_os = "macos")]
38fn platform_install() -> Result<()> {
39    macos::install()
40}
41#[cfg(target_os = "macos")]
42fn platform_uninstall() -> Result<()> {
43    macos::uninstall()
44}
45#[cfg(target_os = "macos")]
46fn platform_status() -> Result<SchemeStatus> {
47    macos::status()
48}
49
50#[cfg(target_os = "linux")]
51fn platform_install() -> Result<()> {
52    linux::install()
53}
54#[cfg(target_os = "linux")]
55fn platform_uninstall() -> Result<()> {
56    linux::uninstall()
57}
58#[cfg(target_os = "linux")]
59fn platform_status() -> Result<SchemeStatus> {
60    linux::status()
61}
62
63#[cfg(target_os = "windows")]
64fn platform_install() -> Result<()> {
65    windows::install()
66}
67#[cfg(target_os = "windows")]
68fn platform_uninstall() -> Result<()> {
69    windows::uninstall()
70}
71#[cfg(target_os = "windows")]
72fn platform_status() -> Result<SchemeStatus> {
73    windows::status()
74}
75
76#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
77fn platform_install() -> Result<()> {
78    anyhow::bail!("URL scheme registration is not supported on this platform")
79}
80#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
81fn platform_uninstall() -> Result<()> {
82    anyhow::bail!("URL scheme registration is not supported on this platform")
83}
84#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
85fn platform_status() -> Result<SchemeStatus> {
86    Ok(SchemeStatus::NotInstalled)
87}
88
89#[cfg(test)]
90#[path = "scheme_tests.rs"]
91mod tests;