Compare commits

...

2 Commits

Author SHA1 Message Date
Bennet Bo Fenner
f448d7e2e8 remove app_version from gpui platform 2024-05-07 16:28:03 +02:00
Bennet Bo Fenner
4624a0a9f4 allow specifying version for gpui app 2024-05-07 16:27:35 +02:00
11 changed files with 57 additions and 153 deletions

View File

@@ -445,15 +445,12 @@ impl Telemetry {
installation_id: state.installation_id.as_deref().map(Into::into),
session_id: state.session_id.clone(),
is_staff: state.is_staff,
app_version: state
.app_metadata
.app_version
.unwrap_or_default()
.to_string(),
os_name: state.app_metadata.os_name.to_string(),
app_version: state.app_metadata.version.unwrap_or_default().to_string(),
os_name: state.app_metadata.os.name.to_string(),
os_version: state
.app_metadata
.os_version
.os
.version
.map(|version| version.to_string()),
architecture: state.architecture.to_string(),

View File

@@ -20,7 +20,7 @@ impl SystemSpecs {
pub fn new(cx: &AppContext) -> Self {
let app_version = AppVersion::global(cx).to_string();
let release_channel = ReleaseChannel::global(cx);
let os_name = cx.app_metadata().os_name;
let os_name = cx.app_metadata().os.name;
let system = System::new_with_specifics(
RefreshKind::new().with_memory(MemoryRefreshKind::everything()),
);
@@ -28,7 +28,8 @@ impl SystemSpecs {
let architecture = env::consts::ARCH;
let os_version = cx
.app_metadata()
.os_version
.os
.version
.map(|os_version| os_version.to_string());
let commit_sha = match release_channel {
ReleaseChannel::Dev | ReleaseChannel::Nightly => {

View File

@@ -12,6 +12,7 @@ use std::{
use anyhow::{anyhow, Result};
use derive_more::{Deref, DerefMut};
use futures::{channel::oneshot, future::LocalBoxFuture, Future};
use semantic_version::SemanticVersion;
use slotmap::SlotMap;
use smol::future::FutureExt;
use time::UtcOffset;
@@ -31,8 +32,8 @@ use crate::{
current_platform, init_app_menus, Action, ActionRegistry, Any, AnyView, AnyWindowHandle,
AppMetadata, AssetCache, AssetSource, BackgroundExecutor, ClipboardItem, Context,
DispatchPhase, DisplayId, Entity, EventEmitter, ForegroundExecutor, Global, KeyBinding, Keymap,
Keystroke, LayoutId, Menu, PathPromptOptions, Pixels, Platform, PlatformDisplay, Point,
PromptBuilder, PromptHandle, PromptLevel, Render, RenderablePromptHandle, Reservation,
Keystroke, LayoutId, Menu, OsMetadata, PathPromptOptions, Pixels, Platform, PlatformDisplay,
Point, PromptBuilder, PromptHandle, PromptLevel, Render, RenderablePromptHandle, Reservation,
SharedString, SubscriberSet, Subscription, SvgRenderer, Task, TextSystem, View, ViewContext,
Window, WindowAppearance, WindowContext, WindowHandle, WindowId,
};
@@ -131,6 +132,12 @@ impl App {
self
}
/// Assign the version of the application.
pub fn with_version(mut self, version: Option<SemanticVersion>) -> Self {
self.0.borrow_mut().app_metadata.version = version;
self
}
/// Start the application. The provided callback will be called once the
/// app is fully launched.
pub fn run<F>(self, on_finish_launching: F)
@@ -263,9 +270,11 @@ impl AppContext {
let entities = EntityMap::new();
let app_metadata = AppMetadata {
os_name: platform.os_name(),
os_version: platform.os_version().ok(),
app_version: platform.app_version().ok(),
version: None,
os: OsMetadata {
name: platform.os_name(),
version: platform.os_version().ok(),
},
};
let app = Rc::new_cyclic(|this| AppCell {
@@ -352,6 +361,11 @@ impl AppContext {
self.app_metadata.clone()
}
/// Set the version of the application.
pub fn set_app_version(&mut self, version: SemanticVersion) {
self.app_metadata.version = Some(version);
}
/// Schedules all windows in the application to be redrawn. This can be called
/// multiple times in an update cycle and still result in a single redraw.
pub fn refresh(&mut self) {

View File

@@ -138,7 +138,6 @@ pub(crate) trait Platform: 'static {
fn os_name(&self) -> &'static str;
fn os_version(&self) -> Result<SemanticVersion>;
fn app_version(&self) -> Result<SemanticVersion>;
fn app_path(&self) -> Result<PathBuf>;
fn local_timezone(&self) -> UtcOffset;
fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf>;
@@ -271,14 +270,20 @@ pub(crate) trait PlatformTextSystem: Send + Sync {
/// Basic metadata about the current application and operating system.
#[derive(Clone, Debug)]
pub struct AppMetadata {
/// The current version of the application
pub version: Option<SemanticVersion>,
/// Basic metadata about the operating system
pub os: OsMetadata,
}
/// Basic metadata about the operating system.
#[derive(Clone, Debug)]
pub struct OsMetadata {
/// The name of the current operating system
pub os_name: &'static str,
pub name: &'static str,
/// The operating system's version
pub os_version: Option<SemanticVersion>,
/// The current version of the application
pub app_version: Option<SemanticVersion>,
pub version: Option<SemanticVersion>,
}
#[derive(PartialEq, Eq, Hash, Clone)]

View File

@@ -347,10 +347,6 @@ impl<P: LinuxClient + 'static> Platform for P {
Ok(SemanticVersion::new(1, 0, 0))
}
fn app_version(&self) -> Result<SemanticVersion> {
Ok(SemanticVersion::new(1, 0, 0))
}
fn app_path(&self) -> Result<PathBuf> {
// get the path of the executable of the current process
let exe_path = std::env::current_exe()?;

View File

@@ -5,7 +5,7 @@ use crate::{
Platform, PlatformDisplay, PlatformTextSystem, PlatformWindow, Result, SemanticVersion, Task,
WindowAppearance, WindowParams,
};
use anyhow::{anyhow, bail};
use anyhow::anyhow;
use block::ConcreteBlock;
use cocoa::{
appkit::{
@@ -693,24 +693,6 @@ impl Platform for MacPlatform {
}
}
fn app_version(&self) -> Result<SemanticVersion> {
unsafe {
let bundle: id = NSBundle::mainBundle();
if bundle.is_null() {
Err(anyhow!("app is not running inside a bundle"))
} else {
let version: id = msg_send![bundle, objectForInfoDictionaryKey: ns_string("CFBundleShortVersionString")];
if version.is_null() {
bail!("bundle does not have version");
}
let len = msg_send![version, lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
let bytes = version.UTF8String() as *const u8;
let version = str::from_utf8(slice::from_raw_parts(bytes, len)).unwrap();
version.parse()
}
}
}
fn app_path(&self) -> Result<PathBuf> {
unsafe {
let bundle: id = NSBundle::mainBundle();

View File

@@ -248,10 +248,6 @@ impl Platform for TestPlatform {
Err(anyhow!("os_version called on TestPlatform"))
}
fn app_version(&self) -> Result<crate::SemanticVersion> {
Err(anyhow!("app_version called on TestPlatform"))
}
fn app_path(&self) -> Result<std::path::PathBuf> {
unimplemented!()
}

View File

@@ -544,100 +544,6 @@ impl Platform for WindowsPlatform {
}
}
fn app_version(&self) -> Result<SemanticVersion> {
let mut file_name_buffer = vec![0u16; MAX_PATH as usize];
let file_name = {
let mut file_name_buffer_capacity = MAX_PATH as usize;
let mut file_name_length;
loop {
file_name_length =
unsafe { GetModuleFileNameW(None, &mut file_name_buffer) } as usize;
if file_name_length < file_name_buffer_capacity {
break;
}
// buffer too small
file_name_buffer_capacity *= 2;
file_name_buffer = vec![0u16; file_name_buffer_capacity];
}
PCWSTR::from_raw(file_name_buffer[0..(file_name_length + 1)].as_ptr())
};
let version_info_block = {
let mut version_handle = 0;
let version_info_size =
unsafe { GetFileVersionInfoSizeW(file_name, Some(&mut version_handle)) } as usize;
if version_info_size == 0 {
log::error!(
"unable to get version info size: {}",
std::io::Error::last_os_error()
);
return Err(anyhow!("unable to get version info size"));
}
let mut version_data = vec![0u8; version_info_size + 2];
unsafe {
GetFileVersionInfoW(
file_name,
version_handle,
version_info_size as u32,
version_data.as_mut_ptr() as _,
)
}
.inspect_err(|_| {
log::error!(
"unable to retrieve version info: {}",
std::io::Error::last_os_error()
)
})?;
version_data
};
let version_info_raw = {
let mut buffer = unsafe { std::mem::zeroed() };
let mut size = 0;
let entry = "\\".encode_utf16().chain(Some(0)).collect_vec();
if !unsafe {
VerQueryValueW(
version_info_block.as_ptr() as _,
PCWSTR::from_raw(entry.as_ptr()),
&mut buffer,
&mut size,
)
}
.as_bool()
{
log::error!(
"unable to query version info data: {}",
std::io::Error::last_os_error()
);
return Err(anyhow!("the specified resource is not valid"));
}
if size == 0 {
log::error!(
"unable to query version info data: {}",
std::io::Error::last_os_error()
);
return Err(anyhow!("no value is available for the specified name"));
}
buffer
};
let version_info = unsafe { &*(version_info_raw as *mut VS_FIXEDFILEINFO) };
// https://learn.microsoft.com/en-us/windows/win32/api/verrsrc/ns-verrsrc-vs_fixedfileinfo
if version_info.dwSignature == 0xFEEF04BD {
return Ok(SemanticVersion::new(
((version_info.dwProductVersionMS >> 16) & 0xFFFF) as usize,
(version_info.dwProductVersionMS & 0xFFFF) as usize,
((version_info.dwProductVersionLS >> 16) & 0xFFFF) as usize,
));
} else {
log::error!(
"no version info present: {}",
std::io::Error::last_os_error()
);
return Err(anyhow!("no version info present"));
}
}
fn app_path(&self) -> Result<PathBuf> {
Ok(std::env::current_exe()?)
}

View File

@@ -63,7 +63,7 @@ impl AppVersion {
from_env.parse().expect("invalid ZED_APP_VERSION")
} else {
cx.app_metadata()
.app_version
.version
.unwrap_or_else(|| pkg_version.parse().expect("invalid version in Cargo.toml"))
};
cx.set_global(GlobalAppVersion(version))

View File

@@ -60,8 +60,12 @@ use crate::zed::inline_completion_registry;
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
fn fail_to_launch(e: anyhow::Error) {
App::new().run(move |cx| {
App::new()
.with_version(APP_VERSION.parse().ok())
.run(move |cx| {
let window = cx.open_window(gpui::WindowOptions::default(), |cx| cx.new_view(|_| gpui::Empty));
window.update(cx, |_, cx| {
let response = cx.prompt(gpui::PromptLevel::Critical, "Zed failed to launch", Some(&format!("{}\n\nFor help resolving this, please open an issue on https://github.com/zed-industries/zed", e)), &["Exit"]);
@@ -83,7 +87,7 @@ fn init_headless(dev_server_token: DevServerToken) {
}
init_logger();
let app = App::new();
let app = App::new().with_version(APP_VERSION.parse().ok());
let session_id = Uuid::new_v4().to_string();
let (installation_id, _) = app
@@ -95,7 +99,7 @@ fn init_headless(dev_server_token: DevServerToken) {
reliability::init_panic_hook(&app, installation_id.clone(), session_id.clone());
app.run(|cx| {
release_channel::init(env!("CARGO_PKG_VERSION"), cx);
release_channel::init(APP_VERSION, cx);
if let Some(build_sha) = option_env!("ZED_COMMIT_SHA") {
AppCommitSha::set_global(AppCommitSha(build_sha.into()), cx);
}
@@ -180,7 +184,9 @@ fn init_ui(args: Args) {
}
log::info!("========== starting zed ==========");
let app = App::new().with_assets(Assets);
let app = App::new()
.with_version(APP_VERSION.parse().ok())
.with_assets(Assets);
let (installation_id, existing_installation_id_found) = app
.background_executor()
@@ -239,7 +245,7 @@ fn init_ui(args: Args) {
});
app.run(move |cx| {
release_channel::init(env!("CARGO_PKG_VERSION"), cx);
release_channel::init(APP_VERSION, cx);
if let Some(build_sha) = option_env!("ZED_COMMIT_SHA") {
AppCommitSha::set_global(AppCommitSha(build_sha.into()), cx);
}

View File

@@ -93,7 +93,7 @@ pub fn init_panic_hook(app: &App, installation_id: Option<String>, session_id: S
std::process::exit(-1);
}
let app_version = if let Some(version) = app_metadata.app_version {
let app_version = if let Some(version) = app_metadata.version {
version.to_string()
} else {
option_env!("CARGO_PKG_VERSION")
@@ -130,9 +130,10 @@ pub fn init_panic_hook(app: &App, installation_id: Option<String>, session_id: S
}),
app_version: app_version.to_string(),
release_channel: RELEASE_CHANNEL.display_name().into(),
os_name: app_metadata.os_name.into(),
os_name: app_metadata.os.name.into(),
os_version: app_metadata
.os_version
.os
.version
.as_ref()
.map(SemanticVersion::to_string),
architecture: env::consts::ARCH.into(),
@@ -327,9 +328,9 @@ pub fn monitor_main_thread_hangs(
let report = HangReport {
backtrace,
app_version: metadata.app_version,
os_name: metadata.os_name.to_owned(),
os_version: metadata.os_version,
app_version: metadata.version,
os_name: metadata.os.name.to_owned(),
os_version: metadata.os.version,
architecture: env::consts::ARCH.into(),
installation_id: installation_id.clone(),
};