mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
refactor: move restart field from ServerInfo to ServerStatus
The restart reason belongs with other server state (shutting_down, restarting, update_progress) rather than on the top-level ServerInfo. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -128,6 +128,7 @@ impl Public {
|
||||
update_progress: None,
|
||||
shutting_down: false,
|
||||
restarting: false,
|
||||
restart: None,
|
||||
},
|
||||
unread_notification_count: 0,
|
||||
password_hash: account.password.clone(),
|
||||
@@ -151,7 +152,6 @@ impl Public {
|
||||
kiosk: Some(kiosk).filter(|_| &*PLATFORM != "raspberrypi"),
|
||||
language,
|
||||
keyboard,
|
||||
restart: None,
|
||||
},
|
||||
package_data: AllPackageData::default(),
|
||||
ui: serde_json::from_str(*DB_UI_SEED_CELL.get().unwrap_or(&"null"))
|
||||
@@ -218,8 +218,6 @@ pub struct ServerInfo {
|
||||
pub kiosk: Option<bool>,
|
||||
pub language: Option<InternedString>,
|
||||
pub keyboard: Option<KeyboardOptions>,
|
||||
#[serde(default)]
|
||||
pub restart: Option<RestartReason>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, TS)]
|
||||
@@ -381,6 +379,8 @@ pub struct ServerStatus {
|
||||
pub shutting_down: bool,
|
||||
#[serde(default)]
|
||||
pub restarting: bool,
|
||||
#[serde(default)]
|
||||
pub restart: Option<RestartReason>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, HasModel, TS)]
|
||||
|
||||
@@ -272,7 +272,7 @@ pub async fn set_hostname_rpc(
|
||||
}
|
||||
if let Some(hostname) = &hostname {
|
||||
hostname.save(server_info)?;
|
||||
server_info.as_restart_mut().ser(&Some(RestartReason::Mdns))?;
|
||||
server_info.as_status_info_mut().as_restart_mut().ser(&Some(RestartReason::Mdns))?;
|
||||
}
|
||||
ServerHostnameInfo::load(server_info)
|
||||
})
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::account::AccountInfo;
|
||||
use crate::context::config::ServerConfig;
|
||||
use crate::context::{CliContext, InitContext, RpcContext};
|
||||
use crate::db::model::Database;
|
||||
use crate::db::model::public::{RestartReason, ServerStatus};
|
||||
use crate::db::model::public::ServerStatus;
|
||||
use crate::developer::OS_DEVELOPER_KEY_PATH;
|
||||
use crate::hostname::ServerHostname;
|
||||
use crate::middleware::auth::local::LocalAuthContext;
|
||||
@@ -375,10 +375,10 @@ pub async fn init(
|
||||
backup_progress: None,
|
||||
shutting_down: false,
|
||||
restarting: false,
|
||||
restart: None,
|
||||
};
|
||||
db.mutate(|v| {
|
||||
let server_info = v.as_public_mut().as_server_info_mut();
|
||||
server_info.as_restart_mut().ser(&None::<RestartReason>)?;
|
||||
server_info.as_ntp_synced_mut().ser(&ntp_synced)?;
|
||||
server_info.as_ram_mut().ser(&ram)?;
|
||||
server_info.as_devices_mut().ser(&devices)?;
|
||||
|
||||
@@ -354,7 +354,7 @@ pub fn kiosk<C: Context>() -> ParentHandler<C> {
|
||||
.mutate(|db| {
|
||||
let server_info = db.as_public_mut().as_server_info_mut();
|
||||
server_info.as_kiosk_mut().ser(&Some(true))?;
|
||||
server_info.as_restart_mut().ser(&Some(RestartReason::Kiosk))
|
||||
server_info.as_status_info_mut().as_restart_mut().ser(&Some(RestartReason::Kiosk))
|
||||
})
|
||||
.await
|
||||
.result?;
|
||||
@@ -371,7 +371,7 @@ pub fn kiosk<C: Context>() -> ParentHandler<C> {
|
||||
.mutate(|db| {
|
||||
let server_info = db.as_public_mut().as_server_info_mut();
|
||||
server_info.as_kiosk_mut().ser(&Some(false))?;
|
||||
server_info.as_restart_mut().ser(&Some(RestartReason::Kiosk))
|
||||
server_info.as_status_info_mut().as_restart_mut().ser(&Some(RestartReason::Kiosk))
|
||||
})
|
||||
.await
|
||||
.result?;
|
||||
@@ -1370,7 +1370,7 @@ pub async fn set_language(
|
||||
server_info
|
||||
.as_language_mut()
|
||||
.ser(&Some(language.clone()))?;
|
||||
server_info.as_restart_mut().ser(&Some(RestartReason::Language))
|
||||
server_info.as_status_info_mut().as_restart_mut().ser(&Some(RestartReason::Language))
|
||||
})
|
||||
.await
|
||||
.result?;
|
||||
|
||||
@@ -81,6 +81,7 @@ pub async fn update_system(
|
||||
.await
|
||||
.into_public()
|
||||
.into_server_info()
|
||||
.into_status_info()
|
||||
.into_restart()
|
||||
.de()?
|
||||
.is_some()
|
||||
@@ -286,7 +287,7 @@ async fn maybe_do_update(
|
||||
.mutate(|db| {
|
||||
let server_info = db.as_public_mut().as_server_info_mut();
|
||||
|
||||
if server_info.as_restart().de()?.is_some() {
|
||||
if server_info.as_status_info().as_restart().de()?.is_some() {
|
||||
return Err(Error::new(
|
||||
eyre!("{}", t!("update.already-updated-restart-required")),
|
||||
crate::ErrorKind::InvalidRequest,
|
||||
@@ -342,7 +343,7 @@ async fn maybe_do_update(
|
||||
.as_status_info_mut()
|
||||
.as_update_progress_mut()
|
||||
.ser(&None)?;
|
||||
server_info.as_restart_mut().ser(&Some(RestartReason::Update))
|
||||
server_info.as_status_info_mut().as_restart_mut().ser(&Some(RestartReason::Update))
|
||||
})
|
||||
.await
|
||||
.result?;
|
||||
|
||||
@@ -29,11 +29,12 @@ impl VersionT for Version {
|
||||
}
|
||||
#[instrument(skip_all)]
|
||||
fn up(self, db: &mut Value, _: Self::PreUpRes) -> Result<Value, Error> {
|
||||
db["public"]["serverInfo"]["statusInfo"]
|
||||
.as_object_mut()
|
||||
.map(|m| m.remove("updated"));
|
||||
|
||||
db["public"]["serverInfo"]["restart"] = Value::Null;
|
||||
let status_info = db["public"]["serverInfo"]["statusInfo"]
|
||||
.as_object_mut();
|
||||
if let Some(m) = status_info {
|
||||
m.remove("updated");
|
||||
m.insert("restart".into(), Value::Null);
|
||||
}
|
||||
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user