Store current release channel name in a file in the zed crate

This commit is contained in:
Max Brunsfeld 2022-10-26 10:32:30 -07:00
parent 1cdd3c0e28
commit a4a8596a29
10 changed files with 80 additions and 36 deletions

View file

@ -39,7 +39,7 @@ use settings::watched_json::{watch_keymap_file, watch_settings_file, WatchedJson
use theme::ThemeRegistry;
use util::{ResultExt, TryFutureExt};
use workspace::{self, AppState, ItemHandle, NewFile, OpenPaths, Workspace};
use zed::{self, build_window_options, initialize_workspace, languages, menus};
use zed::{self, build_window_options, initialize_workspace, languages, menus, RELEASE_CHANNEL};
fn main() {
let http = http::client();
@ -97,6 +97,7 @@ fn main() {
let (settings_file_content, keymap_file) = cx.background().block(config_files).unwrap();
cx.set_global(*RELEASE_CHANNEL);
cx.set_global(HomeDir(zed::paths::HOME.to_path_buf()));
//Setup settings global before binding actions

View file

@ -9,11 +9,11 @@ use anyhow::{anyhow, Context, Result};
use assets::Assets;
use breadcrumbs::Breadcrumbs;
pub use client;
use client::PREVIEW_CHANNEL;
use collab_ui::{CollabTitlebarItem, ToggleCollaborationMenu};
use collections::VecDeque;
pub use editor;
use editor::{Editor, MultiBuffer};
use lazy_static::lazy_static;
use gpui::{
actions,
@ -29,7 +29,7 @@ use project_panel::ProjectPanel;
use search::{BufferSearchBar, ProjectSearchBar};
use serde::Deserialize;
use serde_json::to_string_pretty;
use settings::{keymap_file_json_schema, settings_file_json_schema, Settings};
use settings::{keymap_file_json_schema, settings_file_json_schema, ReleaseChannel, Settings};
use std::{env, path::Path, str, sync::Arc};
use util::ResultExt;
pub use workspace;
@ -69,6 +69,16 @@ actions!(
);
const MIN_FONT_SIZE: f32 = 6.0;
const RELEASE_CHANNEL_NAME: &str = include_str!("../RELEASE_CHANNEL");
lazy_static! {
pub static ref RELEASE_CHANNEL: ReleaseChannel = match RELEASE_CHANNEL_NAME {
"dev" => ReleaseChannel::Dev,
"preview" => ReleaseChannel::Preview,
"stable" => ReleaseChannel::Preview,
_ => panic!("invalid release channel {RELEASE_CHANNEL_NAME}"),
};
}
pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
cx.add_action(about);
@ -378,11 +388,15 @@ fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) {
}
fn about(_: &mut Workspace, _: &About, cx: &mut gpui::ViewContext<Workspace>) {
let channel = if *PREVIEW_CHANNEL { "Preview " } else { "" };
let app_name = match *cx.global::<ReleaseChannel>() {
ReleaseChannel::Dev => "Zed Dev",
ReleaseChannel::Preview => "Zed Preview",
ReleaseChannel::Stable => "Zed",
};
let version = env!("CARGO_PKG_VERSION");
cx.prompt(
gpui::PromptLevel::Info,
&format!("Zed {channel}{version}"),
&format!("{app_name} {version}"),
&["OK"],
);
}