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
parent cbf6d827db
commit 38e902b241
8 changed files with 189 additions and 20 deletions

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>>;