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(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            // TODO kb need to add server handling
63            ReleaseChannel::Nightly => "https://zed.dev/nightly/",
64            ReleaseChannel::Preview => "https://zed.dev/preview/",
65            ReleaseChannel::Stable => "https://zed.dev/",
66        }
67    }
68
69    pub fn release_query_param(&self) -> Option<&'static str> {
70        match self {
71            Self::Dev => None,
72            Self::Nightly => Some("nightly=1"),
73            Self::Preview => Some("preview=1"),
74            Self::Stable => None,
75        }
76    }
77}
78
79pub fn parse_zed_link(link: &str) -> Option<&str> {
80    for release in [
81        ReleaseChannel::Dev,
82        ReleaseChannel::Nightly,
83        ReleaseChannel::Preview,
84        ReleaseChannel::Stable,
85    ] {
86        if let Some(stripped) = link.strip_prefix(release.link_prefix()) {
87            return Some(stripped);
88        }
89        if let Some(stripped) = link.strip_prefix(release.url_scheme()) {
90            return Some(stripped);
91        }
92    }
93    None
94}