feat(safety): temporary write-unlock window for read-only connections

This commit is contained in:
Farahani authored and GitHub committed 2026-08-27 17:37:54 +08:00
1 parent 7933b7656f
commit 955558c81f
66 files changed
+1176 -124

No files matched your search

+33
View File
@@ -2108,6 +2108,39 @@ pub async fn save_connection_database_info(
state.save_connection_database_info(&connection_id, database_info).await
}
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WriteUnlockState {
pub remaining_ms: u64,
}
#[tauri::command]
pub async fn unlock_connection_writes(
state: State<'_, Arc<AppState>>,
connection_id: String,
duration_secs: u64,
) -> Result<WriteUnlockState, String> {
if !state.configs.read().await.contains_key(&connection_id) {
return Err("Connection not found".to_string());
}
let remaining_ms = state.write_unlock_windows.unlock(&connection_id, duration_secs).await?;
Ok(WriteUnlockState { remaining_ms })
}
#[tauri::command]
pub async fn lock_connection_writes(state: State<'_, Arc<AppState>>, connection_id: String) -> Result<(), String> {
state.write_unlock_windows.lock(&connection_id).await;
Ok(())
}
#[tauri::command]
pub async fn connection_write_unlock_state(
state: State<'_, Arc<AppState>>,
connection_id: String,
) -> Result<WriteUnlockState, String> {
Ok(WriteUnlockState { remaining_ms: state.write_unlock_windows.remaining_ms(&connection_id).await })
}
/// Check whether a connection has read-only protection enabled.
/// Returns an error if the connection is read-only, preventing write operations.
pub async fn ensure_connection_writable(
+3
View File
@@ -1879,6 +1879,9 @@ pub fn run() {
commands::connection::connection_identifier_quote,
commands::connection::connection_database_info,
commands::connection::save_connection_database_info,
commands::connection::unlock_connection_writes,
commands::connection::lock_connection_writes,
commands::connection::connection_write_unlock_state,
commands::connection::save_connections,
commands::connection::load_connections,
commands::connection::save_sidebar_layout,