Add auto update setting
This commit is contained in:
parent
17e8172dc3
commit
c2de0f6b5e
3 changed files with 26 additions and 1 deletions
|
@ -90,6 +90,8 @@
|
||||||
// Send anonymized usage data like what languages you're using Zed with.
|
// Send anonymized usage data like what languages you're using Zed with.
|
||||||
"metrics": true
|
"metrics": true
|
||||||
},
|
},
|
||||||
|
// Automatically update Zed
|
||||||
|
"auto_update": true,
|
||||||
// Git gutter behavior configuration.
|
// Git gutter behavior configuration.
|
||||||
"git": {
|
"git": {
|
||||||
// Control whether the git gutter is shown. May take 2 values:
|
// Control whether the git gutter is shown. May take 2 values:
|
||||||
|
|
|
@ -9,6 +9,7 @@ use gpui::{
|
||||||
MutableAppContext, Task, WeakViewHandle,
|
MutableAppContext, Task, WeakViewHandle,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use settings::Settings;
|
||||||
use smol::{fs::File, io::AsyncReadExt, process::Command};
|
use smol::{fs::File, io::AsyncReadExt, process::Command};
|
||||||
use std::{ffi::OsString, sync::Arc, time::Duration};
|
use std::{ffi::OsString, sync::Arc, time::Duration};
|
||||||
use update_notification::UpdateNotification;
|
use update_notification::UpdateNotification;
|
||||||
|
@ -53,7 +54,23 @@ pub fn init(http_client: Arc<dyn HttpClient>, server_url: String, cx: &mut Mutab
|
||||||
let server_url = server_url;
|
let server_url = server_url;
|
||||||
let auto_updater = cx.add_model(|cx| {
|
let auto_updater = cx.add_model(|cx| {
|
||||||
let updater = AutoUpdater::new(version, http_client, server_url.clone());
|
let updater = AutoUpdater::new(version, http_client, server_url.clone());
|
||||||
updater.start_polling(cx).detach();
|
|
||||||
|
let mut update_subscription = cx
|
||||||
|
.global::<Settings>()
|
||||||
|
.auto_update
|
||||||
|
.then(|| updater.start_polling(cx));
|
||||||
|
|
||||||
|
cx.observe_global::<Settings, _>(move |updater, cx| {
|
||||||
|
if cx.global::<Settings>().auto_update {
|
||||||
|
if update_subscription.is_none() {
|
||||||
|
*(&mut update_subscription) = Some(updater.start_polling(cx))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(&mut update_subscription).take();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
updater
|
updater
|
||||||
});
|
});
|
||||||
cx.set_global(Some(auto_updater));
|
cx.set_global(Some(auto_updater));
|
||||||
|
|
|
@ -53,6 +53,7 @@ pub struct Settings {
|
||||||
pub theme: Arc<Theme>,
|
pub theme: Arc<Theme>,
|
||||||
pub telemetry_defaults: TelemetrySettings,
|
pub telemetry_defaults: TelemetrySettings,
|
||||||
pub telemetry_overrides: TelemetrySettings,
|
pub telemetry_overrides: TelemetrySettings,
|
||||||
|
pub auto_update: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||||
|
@ -312,6 +313,8 @@ pub struct SettingsFileContent {
|
||||||
pub theme: Option<String>,
|
pub theme: Option<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub telemetry: TelemetrySettings,
|
pub telemetry: TelemetrySettings,
|
||||||
|
#[serde(default)]
|
||||||
|
pub auto_update: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||||
|
@ -375,6 +378,7 @@ impl Settings {
|
||||||
theme: themes.get(&defaults.theme.unwrap()).unwrap(),
|
theme: themes.get(&defaults.theme.unwrap()).unwrap(),
|
||||||
telemetry_defaults: defaults.telemetry,
|
telemetry_defaults: defaults.telemetry,
|
||||||
telemetry_overrides: Default::default(),
|
telemetry_overrides: Default::default(),
|
||||||
|
auto_update: defaults.auto_update.unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,6 +431,7 @@ impl Settings {
|
||||||
self.language_overrides = data.languages;
|
self.language_overrides = data.languages;
|
||||||
self.telemetry_overrides = data.telemetry;
|
self.telemetry_overrides = data.telemetry;
|
||||||
self.lsp = data.lsp;
|
self.lsp = data.lsp;
|
||||||
|
merge(&mut self.auto_update, data.auto_update);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_language_defaults(
|
pub fn with_language_defaults(
|
||||||
|
@ -573,6 +578,7 @@ impl Settings {
|
||||||
metrics: Some(true),
|
metrics: Some(true),
|
||||||
},
|
},
|
||||||
telemetry_overrides: Default::default(),
|
telemetry_overrides: Default::default(),
|
||||||
|
auto_update: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue