refactor(tauri): 移除持久化存储和HTTP插件优化应用架构

- 移除了 tauri-plugin-persisted-scope 和 tauri-plugin-http 插件依赖
- 从桌面功能权限中移除了文件系统和HTTP访问权限
- 删除了相关的存储键常量定义
- 修改悬浮列表窗口创建逻辑,移除页面类型参数和动态计算功能
- 主窗口配置调整为非透明背景并设置白色背景色
- 移除了前端悬浮列表中互动课堂和智评会议相关功能组件
- 更新Cargo.lock移除相关依赖包确保构建一致性
This commit is contained in:
2026-03-15 11:32:31 +08:00
parent f795de3292
commit a3b31f0ff9
15 changed files with 167 additions and 873 deletions

View File

@ -6,8 +6,8 @@ use tauri::{AppHandle, Window};
/// 创建悬浮列表窗口
#[tauri::command]
pub async fn create_float_list_window(app: AppHandle, page_type: &str) -> Result<String, String> {
create_float_list_window_impl(std::sync::Arc::new(app), page_type).await.map(|_| "success".to_string())
pub async fn create_float_list_window(app: AppHandle) -> Result<String, String> {
create_float_list_window_impl(std::sync::Arc::new(app)).await.map(|_| "success".to_string())
}
/// 创建弹出框窗口

View File

@ -1,25 +1,22 @@
use std::sync::Arc;
use crate::{
constants::{common::*, window::*},
storage::SessionStorage,
constants::common::*,
window::{
WindowLabel,
derive::FloatListInfo,
util::{get_monitor_for_window, show_windows_by_label},
},
};
use tauri::{AppHandle, LogicalPosition, LogicalSize, Manager, Runtime, WebviewUrl, WebviewWindowBuilder, utils::config::BackgroundThrottlingPolicy};
use tauri::{AppHandle, LogicalPosition, LogicalSize, Runtime, WebviewUrl, WebviewWindowBuilder, utils::config::BackgroundThrottlingPolicy};
/// 创建悬浮列表窗口(内部实现)
pub async fn create_float_list_window_impl<R: Runtime>(app: Arc<AppHandle<R>>, page_type: &str) -> Result<(), String> {
let app_handle = Arc::clone(&app);
let page_type_owned = page_type.to_string();
pub async fn create_float_list_window_impl<R: Runtime>(app: Arc<AppHandle<R>>) -> Result<(), String> {
if show_windows_by_label(app.as_ref(), WindowLabel::FLOAT_LIST) {
return Ok(());
}
// 悬浮列表尺寸
let float_info = calculate_float_info_sync(app.as_ref(), page_type);
let float_info = calculate_float_info_sync();
// 获取屏幕尺寸优先为main窗口所在屏幕主窗口没有打开时才找主屏幕
let monitor = get_monitor_for_window(app.as_ref())?;
// 获取屏幕缩放因子
@ -27,10 +24,7 @@ pub async fn create_float_list_window_impl<R: Runtime>(app: Arc<AppHandle<R>>, p
let page_size: LogicalSize<f64> = monitor.work_area().size.to_logical(scale_factor);
let screen_width = page_size.width;
let screen_height = page_size.height;
let url = format!(
"floating-list-window.html?isShowInteraction={}&isShowTutorship={}",
float_info.is_show_interaction, float_info.is_show_tutorship
);
let url = format!("floating-list-window.html");
let label = WindowLabel::FLOAT_LIST.as_ref();
// 创建悬浮球窗口,直接在初始化时设置好位置和尺寸
@ -73,78 +67,15 @@ pub async fn create_float_list_window_impl<R: Runtime>(app: Arc<AppHandle<R>>, p
// 窗口显示后等待200毫秒再执行动画
tokio::spawn(async move {
tokio::time::sleep(tokio::time::Duration::from_millis(200)).await;
let _ = animate_to_bottom_right(&app_handle, window, screen_width as i32, screen_height as i32, &page_type_owned).await;
let _ = animate_to_bottom_right(window, screen_width as i32, screen_height as i32).await;
});
Ok(())
}
/// 根据用户登录状态和课程选择情况动态计算弹出窗口高度
pub fn calculate_float_info_sync<R: Runtime>(app: &AppHandle<R>, page_type: &str) -> FloatListInfo {
pub fn calculate_float_info_sync() -> FloatListInfo {
// 默认基础项目数
let mut item_num = 4;
let mut is_show_interaction = false;
let mut is_show_tutorship = false;
// 获取会话存储实例
let storage = match app.try_state::<SessionStorage>() {
Some(s) => s,
None => {
log::error!("获取会话存储实例失败,使用默认值");
let item_height = 64;
let popup_height = item_height * item_num + 40;
let popup_width = 60;
return FloatListInfo {
width: popup_width as u32,
height: popup_height as u32,
is_show_interaction,
is_show_tutorship,
};
}
};
// 从会话存储中获取用户信息和课程信息来判断是否增加项目数
let user_info_exists = match storage.get::<serde_json::Value>(STORAGE_KEY_USER_INFO) {
Some(Ok(value)) => {
// 检查必要的字段是否存在
value.get("id").is_some()
}
_ => false,
};
let tutorship_info_exists = match storage.get::<serde_json::Value>(STORAGE_KEY_TUTORSHIP) {
Some(Ok(value)) => {
// 检查必要的字段是否存在
value.get("id").is_some()
}
_ => false,
};
let course_info_exists = match storage.get::<serde_json::Value>(STORAGE_KEY_COURSE) {
Some(Ok(value)) => {
// 检查必要的字段是否存在
value.get("id").is_some()
}
_ => false,
};
if user_info_exists {
if page_type == "interaction" {
is_show_interaction = true;
// 如果能获取到用户信息和课程信息,则增加项目数
if course_info_exists {
item_num += 5;
}
} else if page_type == "tutorship" {
// 如果能获取到用户信息和课程信息,则增加项目数
if course_info_exists {
is_show_interaction = true;
item_num += 5;
}
if tutorship_info_exists {
is_show_tutorship = true;
item_num += 3;
}
}
}
let item_num = 4;
// 每个item高度
let item_height = 64;
// 总高度 = item高度 * 项目数 + 额外用于移动按钮和时间部分的高度
@ -155,19 +86,11 @@ pub fn calculate_float_info_sync<R: Runtime>(app: &AppHandle<R>, page_type: &str
FloatListInfo {
width: popup_width as u32,
height: popup_height as u32,
is_show_tutorship,
is_show_interaction,
}
}
/// 使用抛物线动画将窗口移动到右下角
pub async fn animate_to_bottom_right<R: Runtime>(
app: &AppHandle<R>,
window: tauri::WebviewWindow<R>,
screen_width: i32,
screen_height: i32,
page_type: &str,
) -> Result<(), String> {
pub async fn animate_to_bottom_right<R: Runtime>(window: tauri::WebviewWindow<R>, screen_width: i32, screen_height: i32) -> Result<(), String> {
// 获取当前窗口位置和大小
let current_position_physical = window.outer_position().map_err(|e| format!("获取窗口位置失败: {}", e))?;
let current_size_physical = window.outer_size().map_err(|e| format!("获取窗口大小失败: {}", e))?;
@ -225,7 +148,7 @@ pub async fn animate_to_bottom_right<R: Runtime>(
}
// 确保最终位置准确, 再次获取窗口大小和缩放因子
let float_info = calculate_float_info_sync(app, page_type);
let float_info = calculate_float_info_sync();
let current_size_physical = window.outer_size().map_err(|e| format!("获取窗口大小失败: {}", e))?;
let scale_factor = window.scale_factor().map_err(|e| format!("获取缩放因子失败: {}", e))?;
let current_size = current_size_physical.to_logical::<i32>(scale_factor);

View File

@ -1,5 +1,7 @@
use crate::constants::{common::APP_NAME, window::*};
use crate::window::{util::show_windows_by_label, WindowLabel};
use crate::window::{WindowLabel, util::show_windows_by_label};
use tauri::utils::config::BackgroundThrottlingPolicy;
use tauri::window::Color;
use tauri::{AppHandle, Runtime, WebviewUrl, WebviewWindowBuilder};
/// 根据tauri.conf.json配置创建主窗口
@ -17,7 +19,9 @@ pub async fn create_main_window_impl<R: Runtime>(app: &AppHandle<R>) -> Result<(
.resizable(true)
.fullscreen(false)
.decorations(false)
.transparent(true)
.transparent(false)
.background_throttling(BackgroundThrottlingPolicy::Disabled)
.background_color(Color(255, 255, 255, 255))
.always_on_top(false)
.center()
.shadow(true)

View File

@ -29,10 +29,6 @@ pub struct FloatListInfo {
pub width: u32,
/// 弹出框的高度
pub height: u32,
/** 是否显示互动课堂相关按钮 */
pub is_show_interaction: bool,
/** 是否显示智评会议相关按钮 */
pub is_show_tutorship: bool,
}
/// 弹出框位置信息