Merge branch 'main' into auto-update

This commit is contained in:
Antonio Scandurra 2022-04-21 09:45:28 +02:00
commit fb87bacc7e
341 changed files with 21713 additions and 5967 deletions

View file

@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use client::http::{self, HttpClient};
use gpui::{
action,
actions,
elements::{Empty, MouseEventHandler, Text},
platform::AppVersion,
AsyncAppContext, Element, Entity, ModelContext, ModelHandle, MutableAppContext, Task, View,
@ -9,10 +9,11 @@ use gpui::{
};
use lazy_static::lazy_static;
use serde::Deserialize;
use settings::Settings;
use smol::{fs::File, io::AsyncReadExt, process::Command};
use std::{env, ffi::OsString, path::PathBuf, sync::Arc, time::Duration};
use surf::Request;
use workspace::{ItemHandle, Settings, StatusItemView};
use workspace::{ItemHandle, StatusItemView};
const POLL_INTERVAL: Duration = Duration::from_secs(60 * 60);
const ACCESS_TOKEN: &'static str = "618033988749894";
@ -24,6 +25,8 @@ lazy_static! {
pub static ref ZED_APP_PATH: Option<PathBuf> = env::var("ZED_APP_PATH").ok().map(PathBuf::from);
}
actions!(auto_update, [Check, DismissErrorMessage]);
#[derive(Clone, PartialEq, Eq)]
pub enum AutoUpdateStatus {
Idle,
@ -46,8 +49,6 @@ pub struct AutoUpdateIndicator {
updater: Option<ModelHandle<AutoUpdater>>,
}
action!(DismissErrorMessage);
#[derive(Deserialize)]
struct JsonRelease {
version: String,
@ -66,16 +67,15 @@ pub fn init(http_client: Arc<dyn HttpClient>, server_url: String, cx: &mut Mutab
updater
});
cx.set_global(Some(auto_updater));
cx.add_global_action(|_: &Check, cx| {
if let Some(updater) = AutoUpdater::get(cx) {
updater.update(cx, |updater, cx| updater.poll(cx));
}
});
cx.add_action(AutoUpdateIndicator::dismiss_error_message);
}
}
pub fn check(cx: &mut MutableAppContext) {
if let Some(updater) = AutoUpdater::get(cx) {
updater.update(cx, |updater, cx| updater.poll(cx));
}
}
impl AutoUpdater {
fn get(cx: &mut MutableAppContext) -> Option<ModelHandle<Self>> {
cx.default_global::<Option<ModelHandle<Self>>>().clone()