mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-21 18:19:03 +08:00
feat: 新增局域网浏览器访问
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -148,6 +148,7 @@ pub fn run() {
|
||||
fs_file_exists,
|
||||
fs_open_path,
|
||||
http_server_start,
|
||||
http_server_refresh_token,
|
||||
http_server_stop,
|
||||
http_server_status,
|
||||
mcp_server_start,
|
||||
@@ -174,6 +175,41 @@ pub fn setup_app(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
setup_deep_link(app)?;
|
||||
|
||||
setup_lan_http_server(app)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn setup_lan_http_server(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let handle = app.handle().clone();
|
||||
let state = handle.state::<crate::state::SafeAppState>().inner().clone();
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let enabled = {
|
||||
let state_guard = state.read();
|
||||
let db_conn = state_guard.db.read().clone();
|
||||
let mut settings = state_guard.settings.write();
|
||||
settings.attach_db(db_conn);
|
||||
if settings.initialize().await.is_err() {
|
||||
false
|
||||
} else {
|
||||
matches!(
|
||||
settings.get_value(SettingsKey::LanAccessEnabled),
|
||||
SettingsValue::Boolean(true)
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
if enabled {
|
||||
if let Err(error) =
|
||||
crate::commands::http_server_start_from_settings(handle.clone(), state.clone())
|
||||
.await
|
||||
{
|
||||
eprintln!("Failed to start LAN server from settings: {}", error);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ pub struct SettingsSpec {
|
||||
pub pg_connection_string: String,
|
||||
pub pg_connection_status: JsonValue,
|
||||
pub mobile_bottom_nav_items: JsonValue,
|
||||
pub lan_access_enabled: bool,
|
||||
}
|
||||
|
||||
impl Default for SettingsSpec {
|
||||
@@ -51,6 +52,7 @@ impl Default for SettingsSpec {
|
||||
"reasons",
|
||||
"settings"
|
||||
]),
|
||||
lan_access_enabled: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +74,7 @@ pub enum SettingsKey {
|
||||
PgConnectionString,
|
||||
PgConnectionStatus,
|
||||
MobileBottomNavItems,
|
||||
LanAccessEnabled,
|
||||
}
|
||||
|
||||
impl SettingsKey {
|
||||
@@ -92,6 +95,7 @@ impl SettingsKey {
|
||||
SettingsKey::PgConnectionString => "pg_connection_string",
|
||||
SettingsKey::PgConnectionStatus => "pg_connection_status",
|
||||
SettingsKey::MobileBottomNavItems => "mobile_bottom_nav_items",
|
||||
SettingsKey::LanAccessEnabled => "lan_access_enabled",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +116,7 @@ impl SettingsKey {
|
||||
"pg_connection_string" => Some(SettingsKey::PgConnectionString),
|
||||
"pg_connection_status" => Some(SettingsKey::PgConnectionStatus),
|
||||
"mobile_bottom_nav_items" => Some(SettingsKey::MobileBottomNavItems),
|
||||
"lan_access_enabled" => Some(SettingsKey::LanAccessEnabled),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -475,6 +480,16 @@ impl SettingsService {
|
||||
},
|
||||
);
|
||||
|
||||
defs.insert(
|
||||
SettingsKey::LanAccessEnabled,
|
||||
SettingDefinition {
|
||||
kind: SettingValueKind::Boolean,
|
||||
default_value: SettingsValue::Boolean(false),
|
||||
write_permission: PermissionRequirement::Admin,
|
||||
validate: None,
|
||||
},
|
||||
);
|
||||
|
||||
defs
|
||||
}
|
||||
|
||||
@@ -636,6 +651,10 @@ impl SettingsService {
|
||||
"settings"
|
||||
]),
|
||||
},
|
||||
lan_access_enabled: match self.get_value(SettingsKey::LanAccessEnabled) {
|
||||
SettingsValue::Boolean(b) => b,
|
||||
_ => false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user