Skip to main content

worktree_io/scheme/
mod.rs

1use anyhow::Result;
2
3mod dispatch;
4
5#[cfg(target_os = "macos")]
6mod macos;
7
8#[cfg(target_os = "linux")]
9mod linux;
10
11#[cfg(target_os = "windows")]
12mod windows;
13
14/// Whether the `worktree://` URL scheme handler is registered on this system.
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub enum SchemeStatus {
17    /// The handler is installed at the given path.
18    Installed {
19        /// File-system path to the installed application bundle or binary.
20        path: String,
21    },
22    /// The handler is not installed.
23    NotInstalled,
24}
25
26impl std::fmt::Display for SchemeStatus {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            Self::Installed { path } => write!(f, "Installed at {path}"),
30            Self::NotInstalled => write!(f, "Not installed"),
31        }
32    }
33}
34
35/// Register the `worktree://` URL scheme handler on the current platform.
36///
37/// # Errors
38///
39/// Returns an error if the platform is unsupported or registration fails.
40pub fn install() -> Result<()> {
41    dispatch::platform_install()
42}
43
44/// Remove the `worktree://` URL scheme handler from the current platform.
45///
46/// # Errors
47///
48/// Returns an error if the platform is unsupported or removal fails.
49pub fn uninstall() -> Result<()> {
50    dispatch::platform_uninstall()
51}
52
53/// Query whether the `worktree://` URL scheme handler is currently installed.
54///
55/// # Errors
56///
57/// Returns an error if the platform is unsupported or the query fails.
58pub fn status() -> Result<SchemeStatus> {
59    dispatch::platform_status()
60}
61
62#[cfg(test)]
63#[path = "scheme_tests.rs"]
64mod tests;