feat(backup): 实例备份第1轮——独立备份库迁移、settings 仓库路径字段、备份进度事件
This commit is contained in:
1 parent
95a3e00b03
commit
e91ba2ae74
11 files changed
+298
-1
No files matched your search
@@ -1,6 +1,7 @@
|
||||
use super::{FriendPayload, LoadingBarId};
|
||||
use crate::event::{
|
||||
CommandPayload, EventError, InstanceBulkUpdateProgressPayload,
|
||||
CommandPayload, EventError, InstanceBackupProgressPayload,
|
||||
InstanceBulkUpdateProgressPayload,
|
||||
InstancePayloadType, LoadingBar, LoadingBarType, ProcessPayloadType,
|
||||
ServerPayloadType,
|
||||
};
|
||||
@@ -358,6 +359,21 @@ pub async fn emit_instance_bulk_update_progress(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub async fn emit_instance_backup_progress(
|
||||
payload: InstanceBackupProgressPayload,
|
||||
) -> crate::Result<()> {
|
||||
#[cfg(feature = "tauri")]
|
||||
{
|
||||
let event_state = crate::EventState::get()?;
|
||||
event_state
|
||||
.app
|
||||
.emit("instance_backup_progress", payload)
|
||||
.map_err(EventError::from)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// emit_command(CommandPayload::Something { something })
|
||||
// ie: installing a pack, opening an .mrpack, etc
|
||||
// Generally used for url deep links and file opens that we want to handle in the frontend
|
||||
|
||||
@@ -248,6 +248,57 @@ pub enum InstanceBulkUpdateProgressStage {
|
||||
Finishing,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct InstanceBackupProgressPayload {
|
||||
pub operation_id: Uuid,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub instance_id: Option<String>,
|
||||
pub operation_type: InstanceBackupOperationType,
|
||||
pub stage: InstanceBackupProgressStage,
|
||||
pub processed_bytes: u64,
|
||||
pub total_bytes: u64,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub final_state: Option<InstanceBackupOperationFinalState>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub snapshot_id: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Copy)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum InstanceBackupOperationType {
|
||||
Create,
|
||||
Restore,
|
||||
Delete,
|
||||
RepositoryMove,
|
||||
RestorePreview,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Copy)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum InstanceBackupOperationFinalState {
|
||||
Completed,
|
||||
Cancelled,
|
||||
Failed,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum InstanceBackupProgressStage {
|
||||
Scanning,
|
||||
Hashing,
|
||||
Saving,
|
||||
Validating,
|
||||
Copying,
|
||||
Restoring,
|
||||
Deleting,
|
||||
Completed,
|
||||
Cancelled,
|
||||
Failed,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[serde(tag = "event")]
|
||||
pub enum CommandPayload {
|
||||
|
||||
@@ -147,6 +147,8 @@ pub struct Settings {
|
||||
#[serde(default)]
|
||||
pub ui_font: Option<String>,
|
||||
#[serde(default)]
|
||||
pub backup_repository_path: Option<String>,
|
||||
#[serde(default)]
|
||||
pub mono_font: Option<String>,
|
||||
#[serde(default)]
|
||||
pub close_behavior: String,
|
||||
@@ -294,6 +296,7 @@ impl Settings {
|
||||
json(terracotta_public_nodes) terracotta_public_nodes,
|
||||
ui_scale,
|
||||
ui_font,
|
||||
backup_repository_path,
|
||||
mono_font,
|
||||
version
|
||||
FROM settings
|
||||
@@ -369,6 +372,7 @@ impl Settings {
|
||||
sidebar_instance_count: res.sidebar_instance_count as u32,
|
||||
ui_scale: res.ui_scale,
|
||||
ui_font: res.ui_font,
|
||||
backup_repository_path: res.backup_repository_path,
|
||||
mono_font: res.mono_font,
|
||||
close_behavior,
|
||||
auto_hide_downloads_button: res.auto_hide_downloads_button == 1,
|
||||
@@ -677,6 +681,10 @@ impl Settings {
|
||||
.bind(&self.ui_font)
|
||||
.execute(exec)
|
||||
.await?;
|
||||
sqlx::query("UPDATE settings SET backup_repository_path = ? WHERE id = 0")
|
||||
.bind(&self.backup_repository_path)
|
||||
.execute(exec)
|
||||
.await?;
|
||||
sqlx::query("UPDATE settings SET mono_font = ? WHERE id = 0")
|
||||
.bind(&self.mono_font)
|
||||
.execute(exec)
|
||||
|
||||
Reference in new issue
Block a user