channel.rs

 1use lazy_static::lazy_static;
 2use std::env;
 3
 4lazy_static! {
 5    pub static ref RELEASE_CHANNEL_NAME: String = if cfg!(debug_assertions) {
 6        env::var("ZED_RELEASE_CHANNEL")
 7            .unwrap_or_else(|_| include_str!("../../zed/RELEASE_CHANNEL").to_string())
 8    } else {
 9        include_str!("../../zed/RELEASE_CHANNEL").to_string()
10    };
11    pub static ref RELEASE_CHANNEL: ReleaseChannel = match RELEASE_CHANNEL_NAME.as_str().trim() {
12        "dev" => ReleaseChannel::Dev,
13        "nightly" => ReleaseChannel::Nightly,
14        "preview" => ReleaseChannel::Preview,
15        "stable" => ReleaseChannel::Stable,
16        _ => panic!("invalid release channel {}", *RELEASE_CHANNEL_NAME),
17    };
18}
19
20pub struct AppCommitSha(pub String);
21
22#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
23pub enum ReleaseChannel {
24    #[default]
25    Dev,
26    Nightly,
27    Preview,
28    Stable,
29}
30
31impl ReleaseChannel {
32    pub fn display_name(&self) -> &'static str {
33        match self {
34            ReleaseChannel::Dev => "Zed Dev",
35            ReleaseChannel::Nightly => "Zed Nightly",
36            ReleaseChannel::Preview => "Zed Preview",
37            ReleaseChannel::Stable => "Zed",
38        }
39    }
40
41    pub fn dev_name(&self) -> &'static str {
42        match self {
43            ReleaseChannel::Dev => "dev",
44            ReleaseChannel::Nightly => "nightly",
45            ReleaseChannel::Preview => "preview",
46            ReleaseChannel::Stable => "stable",
47        }
48    }
49
50    pub fn url_scheme(&self) -> &'static str {
51        match self {
52            ReleaseChannel::Dev => "zed-dev://",
53            ReleaseChannel::Nightly => "zed-nightly://",
54            ReleaseChannel::Preview => "zed-preview://",
55            ReleaseChannel::Stable => "zed://",
56        }
57    }
58
59    pub fn link_prefix(&self) -> &'static str {
60        match self {
61            ReleaseChannel::Dev => "https://zed.dev/dev/",
62            ReleaseChannel::Nightly => "https://zed.dev/nightly/",
63            ReleaseChannel::Preview => "https://zed.dev/preview/",
64            ReleaseChannel::Stable => "https://zed.dev/",
65        }
66    }
67
68    pub fn release_query_param(&self) -> Option<&'static str> {
69        match self {
70            Self::Dev => None,
71            Self::Nightly => Some("nightly=1"),
72            Self::Preview => Some("preview=1"),
73            Self::Stable => None,
74        }
75    }
76}
77
78pub fn parse_zed_link(link: &str) -> Option<&str> {
79    for release in [
80        ReleaseChannel::Dev,
81        ReleaseChannel::Nightly,
82        ReleaseChannel::Preview,
83        ReleaseChannel::Stable,
84    ] {
85        if let Some(stripped) = link.strip_prefix(release.link_prefix()) {
86            return Some(stripped);
87        }
88        if let Some(stripped) = link.strip_prefix(release.url_scheme()) {
89            return Some(stripped);
90        }
91    }
92    None
93}