Files
tauri-meeting/src/utils/tauri/windows-action.ts
O昵称重要吗O bfaad97f61 feat(websocket): 优化投屏状态管理并新增全员禁麦功能
- 重构 Redis 投屏状态存储,统一使用 screenShareOwnerUid 字段
- 移除冗余的 screenShareUid 字段,简化房间状态数据结构
- 新增 client_mute_all_students 消息类型支持全员禁麦功能
- 实现创建者权限验证的全员禁麦逻辑,排除老师角色用户
- 优化 Tauri 桌面应用悬浮窗创建接口,支持状态参数传递
- 添加悬浮窗关闭功能及教师端静音状态同步机制
- 修复学生端界面中投屏状态变量命名不一致问题
- 统一按钮样式规范,提升界面组件一致性
2026-03-15 18:21:15 +08:00

104 lines
2.6 KiB
TypeScript

import { WebviewWindow } from '@tauri-apps/api/webviewWindow';
import { type WindowLabel, windowLabel } from './windows-util';
import { invoke } from '@tauri-apps/api/core';
import { LogicalPosition, LogicalSize, currentMonitor } from '@tauri-apps/api/window';
import { ElMessage as Toast } from 'element-plus';
/**
* 创建悬浮球窗口
*/
export async function createFloatListWindow(pageType: 'interaction' | 'tutorship', isTeacherMuted = false) {
try {
await invoke('create_float_list_window', { page_type: pageType, isTeacherMuted });
} catch (error: any) {
console.error('创建悬浮球窗口时出错:', error);
Toast.error('悬浮球创建失败');
}
}
/**
* 关闭悬浮球窗口
*/
export async function closeFloatListWindow() {
try {
await invoke('close_float_list_window');
} catch (error: any) {
console.error('关闭悬浮球窗口时出错:', error);
}
}
/**
* 创建主窗口
*/
export async function createMainWindow() {
try {
await invoke('create_main_window');
} catch (error: any) {
console.error('创建主窗口时出错:', error);
Toast.error('创建主窗口失败');
}
}
/**
* 调整窗口位置和大小
*/
export async function moveAndResizeWindow(x: number, y: number, width: number, height: number) {
const win = WebviewWindow.getCurrent();
await win.setSize(new LogicalSize(width, height));
// 获取当前显示器信息
const _currentMonitor = await currentMonitor();
const scaleFactor = await win.scaleFactor();
// 如果有当前显示器信息,则将相对坐标转换为绝对坐标
if (_currentMonitor) {
const monitorPos = _currentMonitor.position.toLogical(scaleFactor);
await win.setPosition(new LogicalPosition(x + monitorPos.x, y + monitorPos.y));
} else {
await win.setPosition(new LogicalPosition(x, y));
}
return Promise.resolve(true);
}
/**
* 关闭当前窗口
*/
export async function closeCurrentWindow() {
const win = WebviewWindow.getCurrent();
if (win.label === windowLabel.main) {
await win.hide();
} else {
await win.close();
}
}
/**
* 根据 label 关闭指定窗口
*/
export async function closeWindowByLabel(label: WindowLabel) {
try {
if (!label) {
return;
}
const win = await WebviewWindow.getByLabel(label);
if (!win) {
return;
}
if (win.label === windowLabel.main) {
await win.hide();
} else {
await win.close();
}
} catch (error) {
console.log('关闭错误或已被关闭====', error);
}
}
/**
* 最小化当前窗口
*/
export async function minimizeCurrentWindow() {
const win = WebviewWindow.getCurrent();
await win.minimize();
}