整理并提交 Rust 端剩余改动

This commit is contained in:
JSR
2026-03-20 18:43:07 +08:00
parent 61f3b24a1c
commit aed72b111b
6 changed files with 49 additions and 49 deletions
+8 -12
View File
@@ -25,8 +25,8 @@ pub async fn register_url_protocol(
{
use std::process::Command;
let exe_path = std::env::current_exe()
.map_err(|e| format!("Failed to get executable path: {}", e))?;
let exe_path =
std::env::current_exe().map_err(|e| format!("Failed to get executable path: {}", e))?;
let exe_path_str = exe_path.to_string_lossy();
@@ -45,17 +45,11 @@ pub async fn register_url_protocol(
protocol, exe_path_str
);
let _ = Command::new("cmd")
.args(["/C", &reg_command])
.output();
let _ = Command::new("cmd").args(["/C", &reg_command]).output();
let _ = Command::new("cmd")
.args(["/C", &reg_command2])
.output();
let _ = Command::new("cmd").args(["/C", &reg_command2]).output();
let _ = Command::new("cmd")
.args(["/C", &reg_command3])
.output();
let _ = Command::new("cmd").args(["/C", &reg_command3]).output();
let _ = app;
@@ -83,7 +77,9 @@ pub async fn register_url_protocol(
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
{
let _ = app;
Ok(IpcResponse::error("URL protocol registration is not supported on this platform"))
Ok(IpcResponse::error(
"URL protocol registration is not supported on this platform",
))
}
}
+18 -17
View File
@@ -5,8 +5,8 @@ use std::sync::Arc;
use tauri::{AppHandle, Emitter, Manager, State};
use tokio::time::{timeout, Duration};
use crate::db::connection::{create_postgres_connection, create_sqlite_connection};
use crate::db::connection::DatabaseType;
use crate::db::connection::{create_postgres_connection, create_sqlite_connection};
use crate::db::entities::{
reasons, reward_redemptions, reward_settings, score_events, student_tags, students, tags,
};
@@ -331,16 +331,17 @@ async fn load_student_tag_pairs(
.all(conn)
.await
.map_err(|e| e.to_string())?;
let tag_rows = tags::Entity::find().all(conn).await.map_err(|e| e.to_string())?;
let tag_rows = tags::Entity::find()
.all(conn)
.await
.map_err(|e| e.to_string())?;
let link_rows = student_tags::Entity::find()
.all(conn)
.await
.map_err(|e| e.to_string())?;
let student_name_map: std::collections::HashMap<i32, String> = student_rows
.into_iter()
.map(|s| (s.id, s.name))
.collect();
let student_name_map: std::collections::HashMap<i32, String> =
student_rows.into_iter().map(|s| (s.id, s.name)).collect();
let tag_name_map: std::collections::HashMap<i32, String> =
tag_rows.into_iter().map(|t| (t.id, t.name)).collect();
@@ -486,7 +487,10 @@ async fn upsert_reason(
}
}
async fn upsert_tag(conn: &sea_orm::DatabaseConnection, data: &TagNormalized) -> Result<bool, String> {
async fn upsert_tag(
conn: &sea_orm::DatabaseConnection,
data: &TagNormalized,
) -> Result<bool, String> {
let existing = tags::Entity::find()
.filter(tags::Column::Name.eq(&data.name))
.one(conn)
@@ -702,11 +706,9 @@ async fn ensure_student_tag_pair(
id: sea_orm::ActiveValue::NotSet,
student_id: Set(student_row.id),
tag_id: Set(tag_row.id),
created_at: Set(
chrono::Utc::now()
created_at: Set(chrono::Utc::now()
.format("%Y-%m-%dT%H:%M:%S%.3fZ")
.to_string(),
),
.to_string()),
}
.insert(conn)
.await
@@ -717,10 +719,7 @@ async fn ensure_student_tag_pair(
async fn current_remote_and_local_from_state(
app_handle: &AppHandle,
app_state: &Arc<RwLock<AppState>>,
) -> Result<
Option<(sea_orm::DatabaseConnection, sea_orm::DatabaseConnection)>,
String,
> {
) -> Result<Option<(sea_orm::DatabaseConnection, sea_orm::DatabaseConnection)>, String> {
let (current_conn, db_type) = {
let state_guard = app_state.read();
let db = state_guard.db.read().clone();
@@ -1053,7 +1052,8 @@ pub async fn db_switch_connection(
) -> Result<IpcResponse<SwitchConnectionResult>, String> {
check_admin_permission(&state)?;
let (db_type, saved_connection_string, saved_status, conn) = if connection_string.starts_with("postgres://")
let (db_type, saved_connection_string, saved_status, conn) = if connection_string
.starts_with("postgres://")
|| connection_string.starts_with("postgresql://")
{
let conn = timeout(
@@ -1390,7 +1390,8 @@ pub async fn db_sync(
let db_guard = state_guard.db.read();
if let Some(conn) = db_guard.as_ref() {
let settings = state_guard.settings.read();
let status_json = settings.get_value(crate::services::settings::SettingsKey::PgConnectionStatus);
let status_json =
settings.get_value(crate::services::settings::SettingsKey::PgConnectionStatus);
let db_type = match status_json {
crate::services::settings::SettingsValue::Json(json) => json
.get("type")
+1 -1
View File
@@ -1,7 +1,7 @@
use sea_orm::{ConnectOptions, Database, DatabaseConnection, DbErr};
use std::time::Duration;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::RwLock;
use tracing::{info, warn};
+4 -1
View File
@@ -125,7 +125,10 @@ impl Migration {
let db_backend = Self::get_db_backend(sqlite);
let alter_sql = "ALTER TABLE students ADD COLUMN reward_points INTEGER DEFAULT 0";
let result = conn
.execute(Statement::from_string(db_backend.clone(), alter_sql.to_string()))
.execute(Statement::from_string(
db_backend.clone(),
alter_sql.to_string(),
))
.await;
match result {