完善编辑功能
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
"core:window:allow-minimize",
|
||||
"core:window:allow-toggle-maximize",
|
||||
"core:window:allow-close",
|
||||
"core:window:allow-destroy",
|
||||
"core:window:allow-start-dragging",
|
||||
"opener:default",
|
||||
"dialog:default"
|
||||
|
||||
@@ -552,12 +552,37 @@ struct SyncStats {
|
||||
skipped: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
enum SyncFileAction {
|
||||
Upload,
|
||||
Download,
|
||||
DeleteLocal,
|
||||
DeleteRemote,
|
||||
Skip,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct SyncFileDetail {
|
||||
path: String,
|
||||
action: SyncFileAction,
|
||||
size: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct SyncResult {
|
||||
message: String,
|
||||
last_sync_at: String,
|
||||
stats: SyncStats,
|
||||
files: Vec<SyncFileDetail>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct SyncConfigSaveResult {
|
||||
config_path: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
@@ -1173,6 +1198,7 @@ async fn sync_workspace(
|
||||
let remote_files = scan_remote_files(&op).await?;
|
||||
let mut history = load_sync_history(app, &key)?;
|
||||
let mut stats = SyncStats::default();
|
||||
let mut file_details = Vec::new();
|
||||
|
||||
let all_paths: BTreeSet<String> = local_files
|
||||
.keys()
|
||||
@@ -1199,6 +1225,11 @@ async fn sync_workspace(
|
||||
)
|
||||
.await?;
|
||||
stats.uploaded += 1;
|
||||
file_details.push(SyncFileDetail {
|
||||
path: relative.clone(),
|
||||
action: SyncFileAction::Upload,
|
||||
size: local.map(|item| item.size).unwrap_or(0),
|
||||
});
|
||||
}
|
||||
SyncAction::Download => {
|
||||
let local_path = local_path_for(workspace, &relative);
|
||||
@@ -1216,6 +1247,11 @@ async fn sync_workspace(
|
||||
fs::write(&local_path, bytes)
|
||||
.map_err(|e| format!("无法写入本地文件 {}: {}", local_path.display(), e))?;
|
||||
stats.downloaded += 1;
|
||||
file_details.push(SyncFileDetail {
|
||||
path: relative.clone(),
|
||||
action: SyncFileAction::Download,
|
||||
size: remote.map(|item| item.size).unwrap_or(0),
|
||||
});
|
||||
}
|
||||
SyncAction::DeleteLocal => {
|
||||
let local_path = local_path_for(workspace, &relative);
|
||||
@@ -1225,6 +1261,11 @@ async fn sync_workspace(
|
||||
}
|
||||
history.files.remove(&relative);
|
||||
stats.deleted_local += 1;
|
||||
file_details.push(SyncFileDetail {
|
||||
path: relative.clone(),
|
||||
action: SyncFileAction::DeleteLocal,
|
||||
size: local.map(|item| item.size).unwrap_or(0),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
SyncAction::DeleteRemote => {
|
||||
@@ -1236,10 +1277,23 @@ async fn sync_workspace(
|
||||
.await?;
|
||||
history.files.remove(&relative);
|
||||
stats.deleted_remote += 1;
|
||||
file_details.push(SyncFileDetail {
|
||||
path: relative.clone(),
|
||||
action: SyncFileAction::DeleteRemote,
|
||||
size: remote.map(|item| item.size).unwrap_or(0),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
SyncAction::Skip => {
|
||||
stats.skipped += 1;
|
||||
file_details.push(SyncFileDetail {
|
||||
path: relative.clone(),
|
||||
action: SyncFileAction::Skip,
|
||||
size: local
|
||||
.map(|item| item.size)
|
||||
.or_else(|| remote.map(|item| item.size))
|
||||
.unwrap_or(0),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1282,6 +1336,7 @@ async fn sync_workspace(
|
||||
message: "同步完成".to_string(),
|
||||
last_sync_at,
|
||||
stats,
|
||||
files: file_details,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1291,8 +1346,13 @@ fn load_sync_config(app: tauri::AppHandle) -> Result<SyncConfig, String> {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn save_sync_config(app: tauri::AppHandle, config: SyncConfig) -> Result<(), String> {
|
||||
save_sync_config_to_disk(&app, &config)
|
||||
fn save_sync_config(
|
||||
app: tauri::AppHandle,
|
||||
config: SyncConfig,
|
||||
) -> Result<SyncConfigSaveResult, String> {
|
||||
save_sync_config_to_disk(&app, &config)?;
|
||||
let config_path = sync_config_path(&app)?.to_string_lossy().into_owned();
|
||||
Ok(SyncConfigSaveResult { config_path })
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -1430,7 +1490,7 @@ pub fn run() {
|
||||
let id = event.id().0.as_str();
|
||||
match id {
|
||||
"quit" => {
|
||||
std::process::exit(0);
|
||||
let _ = app_handle.emit("menu-quit", ());
|
||||
}
|
||||
"open" => {
|
||||
let handle = app_handle.clone();
|
||||
|
||||
Reference in New Issue
Block a user