mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-19 21:14:21 +08:00
整理并提交 Rust 端剩余改动
This commit is contained in:
@@ -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", ®_command])
|
||||
.output();
|
||||
let _ = Command::new("cmd").args(["/C", ®_command]).output();
|
||||
|
||||
let _ = Command::new("cmd")
|
||||
.args(["/C", ®_command2])
|
||||
.output();
|
||||
let _ = Command::new("cmd").args(["/C", ®_command2]).output();
|
||||
|
||||
let _ = Command::new("cmd")
|
||||
.args(["/C", ®_command3])
|
||||
.output();
|
||||
let _ = Command::new("cmd").args(["/C", ®_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",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
.format("%Y-%m-%dT%H:%M:%S%.3fZ")
|
||||
.to_string(),
|
||||
),
|
||||
created_at: Set(chrono::Utc::now()
|
||||
.format("%Y-%m-%dT%H:%M:%S%.3fZ")
|
||||
.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")
|
||||
|
||||
@@ -117,14 +117,14 @@ pub async fn reason_create(
|
||||
updated_at: Set(now),
|
||||
};
|
||||
|
||||
match new_reason.insert(conn).await {
|
||||
Ok(inserted) => {
|
||||
realtime_dual_write_sync(state.inner()).await?;
|
||||
Ok(IpcResponse::success(inserted.id))
|
||||
}
|
||||
Err(e) => Ok(IpcResponse::error(&format!(
|
||||
"Failed to create reason: {}",
|
||||
e
|
||||
match new_reason.insert(conn).await {
|
||||
Ok(inserted) => {
|
||||
realtime_dual_write_sync(state.inner()).await?;
|
||||
Ok(IpcResponse::success(inserted.id))
|
||||
}
|
||||
Err(e) => Ok(IpcResponse::error(&format!(
|
||||
"Failed to create reason: {}",
|
||||
e
|
||||
))),
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -37,15 +37,15 @@ pub async fn window_maximize(
|
||||
#[cfg(desktop)]
|
||||
{
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let is_maximized = window.is_maximized().map_err(|e| e.to_string())?;
|
||||
let is_maximized = window.is_maximized().map_err(|e| e.to_string())?;
|
||||
|
||||
if is_maximized {
|
||||
window.unmaximize().map_err(|e| e.to_string())?;
|
||||
Ok(false)
|
||||
} else {
|
||||
window.maximize().map_err(|e| e.to_string())?;
|
||||
Ok(true)
|
||||
}
|
||||
if is_maximized {
|
||||
window.unmaximize().map_err(|e| e.to_string())?;
|
||||
Ok(false)
|
||||
} else {
|
||||
window.maximize().map_err(|e| e.to_string())?;
|
||||
Ok(true)
|
||||
}
|
||||
} else {
|
||||
Err("Window not found".to_string())
|
||||
}
|
||||
@@ -83,7 +83,7 @@ pub async fn window_is_maximized(
|
||||
#[cfg(desktop)]
|
||||
{
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
window.is_maximized().map_err(|e| e.to_string())
|
||||
window.is_maximized().map_err(|e| e.to_string())
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user