WIP: Start on auto-update

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Max Brunsfeld <max@zed.dev>
Co-Authored-By: Keith Simmons <keith@zed.dev>
This commit is contained in:
Antonio Scandurra
2022-04-04 18:59:57 +02:00
co-authored by Nathan Sobo Max Brunsfeld Keith Simmons
parent cbf6d827db
commit 38e902b241
8 changed files with 189 additions and 20 deletions
+35 -1
View File
@@ -17,7 +17,7 @@ use crate::{
text_layout::{LineLayout, RunStyle},
AnyAction, ClipboardItem, Menu, Scene,
};
use anyhow::Result;
use anyhow::{anyhow, Result};
use async_task::Runnable;
pub use event::{Event, NavigationDirection};
use postage::oneshot;
@@ -25,6 +25,7 @@ use std::{
any::Any,
path::{Path, PathBuf},
rc::Rc,
str::FromStr,
sync::Arc,
};
use time::UtcOffset;
@@ -56,6 +57,7 @@ pub trait Platform: Send + Sync {
fn local_timezone(&self) -> UtcOffset;
fn path_for_resource(&self, name: Option<&str>, extension: Option<&str>) -> Result<PathBuf>;
fn app_version(&self) -> Result<AppVersion>;
}
pub(crate) trait ForegroundPlatform {
@@ -129,6 +131,38 @@ pub enum CursorStyle {
PointingHand,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct AppVersion {
major: usize,
minor: usize,
patch: usize,
}
impl FromStr for AppVersion {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self> {
let mut components = s.trim().split('.');
let major = components
.next()
.ok_or_else(|| anyhow!("missing major version number"))?
.parse()?;
let minor = components
.next()
.ok_or_else(|| anyhow!("missing minor version number"))?
.parse()?;
let patch = components
.next()
.ok_or_else(|| anyhow!("missing patch version number"))?
.parse()?;
Ok(Self {
major,
minor,
patch,
})
}
}
pub trait FontSystem: Send + Sync {
fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> anyhow::Result<()>;
fn load_family(&self, name: &str) -> anyhow::Result<Vec<FontId>>;
+16
View File
@@ -623,6 +623,22 @@ impl platform::Platform for MacPlatform {
}
}
}
fn app_version(&self) -> Result<platform::AppVersion> {
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: "CFBundleShortVersionString"];
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()
}
}
}
}
unsafe fn get_foreground_platform(object: &mut Object) -> &MacForegroundPlatform {
+9 -1
View File
@@ -1,4 +1,4 @@
use super::{CursorStyle, WindowBounds};
use super::{AppVersion, CursorStyle, WindowBounds};
use crate::{
geometry::vector::{vec2f, Vector2F},
AnyAction, ClipboardItem,
@@ -164,6 +164,14 @@ impl super::Platform for Platform {
fn path_for_resource(&self, _name: Option<&str>, _extension: Option<&str>) -> Result<PathBuf> {
Err(anyhow!("app not running inside a bundle"))
}
fn app_version(&self) -> Result<AppVersion> {
Ok(AppVersion {
major: 1,
minor: 0,
patch: 0,
})
}
}
impl Window {