适配iOS模拟器运行并补齐Tauri移动端入口

This commit is contained in:
JSR
2026-03-18 22:20:47 +08:00
parent 139185b1c0
commit 0df8fd4b0d
5 changed files with 170 additions and 104 deletions
+4
View File
@@ -6,6 +6,10 @@ authors = ["SecScore Team"]
edition = "2021"
rust-version = "1.70"
[lib]
name = "secscore"
crate-type = ["staticlib", "cdylib", "lib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
+1 -1
View File
@@ -83,6 +83,6 @@ pub async fn register_url_protocol(
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
{
let _ = app;
Ok(IpcResponse::failure("URL protocol registration is not supported on this platform"))
Ok(IpcResponse::error("URL protocol registration is not supported on this platform"))
}
}
+57 -7
View File
@@ -1,6 +1,8 @@
use parking_lot::RwLock;
use std::sync::Arc;
use tauri::{AppHandle, Manager};
use tauri::AppHandle;
#[cfg(desktop)]
use tauri::Manager;
use crate::state::AppState;
@@ -9,6 +11,12 @@ pub async fn window_minimize(
app: AppHandle,
_state: tauri::State<'_, Arc<RwLock<AppState>>>,
) -> Result<(), String> {
#[cfg(not(desktop))]
{
let _ = app;
}
#[cfg(desktop)]
if let Some(window) = app.get_webview_window("main") {
window.minimize().map_err(|e| e.to_string())?;
}
@@ -20,7 +28,15 @@ pub async fn window_maximize(
app: AppHandle,
_state: tauri::State<'_, Arc<RwLock<AppState>>>,
) -> Result<bool, String> {
if let Some(window) = app.get_webview_window("main") {
#[cfg(not(desktop))]
{
let _ = app;
return Ok(false);
}
#[cfg(desktop)]
{
if let Some(window) = app.get_webview_window("main") {
let is_maximized = window.is_maximized().map_err(|e| e.to_string())?;
if is_maximized {
@@ -30,8 +46,9 @@ pub async fn window_maximize(
window.maximize().map_err(|e| e.to_string())?;
Ok(true)
}
} else {
Err("Window not found".to_string())
} else {
Err("Window not found".to_string())
}
}
}
@@ -40,6 +57,12 @@ pub async fn window_close(
app: AppHandle,
_state: tauri::State<'_, Arc<RwLock<AppState>>>,
) -> Result<(), String> {
#[cfg(not(desktop))]
{
let _ = app;
}
#[cfg(desktop)]
if let Some(window) = app.get_webview_window("main") {
window.hide().map_err(|e| e.to_string())?;
}
@@ -51,10 +74,19 @@ pub async fn window_is_maximized(
app: AppHandle,
_state: tauri::State<'_, Arc<RwLock<AppState>>>,
) -> Result<bool, String> {
if let Some(window) = app.get_webview_window("main") {
#[cfg(not(desktop))]
{
let _ = app;
return Ok(false);
}
#[cfg(desktop)]
{
if let Some(window) = app.get_webview_window("main") {
window.is_maximized().map_err(|e| e.to_string())
} else {
Ok(false)
} else {
Ok(false)
}
}
}
@@ -63,6 +95,12 @@ pub async fn toggle_devtools(
app: AppHandle,
_state: tauri::State<'_, Arc<RwLock<AppState>>>,
) -> Result<(), String> {
#[cfg(not(desktop))]
{
let _ = app;
}
#[cfg(desktop)]
if let Some(window) = app.get_webview_window("main") {
if window.is_devtools_open() {
window.close_devtools();
@@ -80,6 +118,12 @@ pub async fn window_resize(
app: AppHandle,
_state: tauri::State<'_, Arc<RwLock<AppState>>>,
) -> Result<(), String> {
#[cfg(not(desktop))]
{
let _ = (width, height, app);
}
#[cfg(desktop)]
if let Some(window) = app.get_webview_window("main") {
window
.set_size(tauri::Size::Physical(tauri::PhysicalSize { width, height }))
@@ -94,6 +138,12 @@ pub async fn window_set_resizable(
app: AppHandle,
_state: tauri::State<'_, Arc<RwLock<AppState>>>,
) -> Result<(), String> {
#[cfg(not(desktop))]
{
let _ = (resizable, app);
}
#[cfg(desktop)]
if let Some(window) = app.get_webview_window("main") {
window.set_resizable(resizable).map_err(|e| e.to_string())?;
}
+107 -6
View File
@@ -5,22 +5,111 @@ pub mod services;
pub mod state;
pub mod utils;
use parking_lot::RwLock;
use std::sync::Arc;
use crate::db::connection::create_sqlite_connection;
use crate::db::connection::DatabaseType;
use crate::db::migration::run_migration;
use crate::{commands::*, state::AppState};
use tauri::{App, Manager};
#[cfg(desktop)]
use tauri::{
image::Image,
menu::{Menu, MenuItem},
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
App, Manager, WindowEvent,
WindowEvent,
};
pub fn setup_app(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
#[cfg(desktop)]
{
let _ = app;
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.setup(|app| {
let state = AppState::new(app.handle().clone());
app.manage(Arc::new(RwLock::new(state)));
setup_app(app)?;
Ok(())
})
.invoke_handler(tauri::generate_handler![
student_query,
student_create,
student_update,
student_delete,
student_import_from_xlsx,
tags_get_all,
tags_get_by_student,
tags_create,
tags_delete,
tags_update_student_tags,
reason_query,
reason_create,
reason_update,
reason_delete,
event_query,
event_create,
event_delete,
event_query_by_student,
leaderboard_query,
db_settlement_query,
db_settlement_create,
db_settlement_leaderboard,
settings_get_all,
settings_get,
settings_set,
auth_get_status,
auth_login,
auth_logout,
auth_set_passwords,
auth_generate_recovery,
auth_reset_by_recovery,
auth_clear_all,
theme_list,
theme_current,
theme_set,
theme_save,
theme_delete,
auto_score_get_rules,
auto_score_add_rule,
auto_score_update_rule,
auto_score_delete_rule,
auto_score_toggle_rule,
auto_score_get_status,
auto_score_sort_rules,
log_query,
log_clear,
log_set_level,
log_write,
data_export_json,
data_import_json,
window_minimize,
window_maximize,
window_close,
window_is_maximized,
toggle_devtools,
window_resize,
window_set_resizable,
db_test_connection,
db_switch_connection,
db_get_status,
db_sync,
fs_get_config_structure,
fs_read_json,
fs_write_json,
fs_read_text,
fs_write_text,
fs_delete_file,
fs_list_files,
fs_file_exists,
http_server_start,
http_server_stop,
http_server_status,
register_url_protocol,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
pub fn setup_app(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
setup_database(app)?;
setup_tray(app)?;
@@ -81,6 +170,7 @@ fn setup_database(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
#[cfg(desktop)]
fn setup_tray(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
let show_item = MenuItem::with_id(app, "show", "显示窗口", true, None::<&str>)?;
let hide_item = MenuItem::with_id(app, "hide", "隐藏窗口", true, None::<&str>)?;
@@ -128,6 +218,12 @@ fn setup_tray(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
#[cfg(not(desktop))]
fn setup_tray(_app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
#[cfg(desktop)]
fn setup_window_events(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
if let Some(window) = app.get_webview_window("main") {
let window_clone = window.clone();
@@ -141,3 +237,8 @@ fn setup_window_events(app: &mut App) -> Result<(), Box<dyn std::error::Error>>
Ok(())
}
#[cfg(not(desktop))]
fn setup_window_events(_app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
+1 -90
View File
@@ -1,94 +1,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use parking_lot::RwLock;
use secscore::{commands::*, setup_app, state::AppState};
use std::sync::Arc;
use tauri::Manager;
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.setup(|app| {
let state = AppState::new(app.handle().clone());
app.manage(Arc::new(RwLock::new(state)));
setup_app(app)?;
Ok(())
})
.invoke_handler(tauri::generate_handler![
student_query,
student_create,
student_update,
student_delete,
student_import_from_xlsx,
tags_get_all,
tags_get_by_student,
tags_create,
tags_delete,
tags_update_student_tags,
reason_query,
reason_create,
reason_update,
reason_delete,
event_query,
event_create,
event_delete,
event_query_by_student,
leaderboard_query,
db_settlement_query,
db_settlement_create,
db_settlement_leaderboard,
settings_get_all,
settings_get,
settings_set,
auth_get_status,
auth_login,
auth_logout,
auth_set_passwords,
auth_generate_recovery,
auth_reset_by_recovery,
auth_clear_all,
theme_list,
theme_current,
theme_set,
theme_save,
theme_delete,
auto_score_get_rules,
auto_score_add_rule,
auto_score_update_rule,
auto_score_delete_rule,
auto_score_toggle_rule,
auto_score_get_status,
auto_score_sort_rules,
log_query,
log_clear,
log_set_level,
log_write,
data_export_json,
data_import_json,
window_minimize,
window_maximize,
window_close,
window_is_maximized,
toggle_devtools,
window_resize,
window_set_resizable,
db_test_connection,
db_switch_connection,
db_get_status,
db_sync,
fs_get_config_structure,
fs_read_json,
fs_write_json,
fs_read_text,
fs_write_text,
fs_delete_file,
fs_list_files,
fs_file_exists,
http_server_start,
http_server_stop,
http_server_status,
register_url_protocol,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
secscore::run();
}