版本管理,优化
This commit is contained in:
@@ -7,6 +7,9 @@ yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# 发布暂存目录
|
||||
release_stage/
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "thing",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"version": "26.8.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set "SCRIPT=%~dp0release.ps1"
|
||||
|
||||
echo ================================================
|
||||
echo Thing Build Pubilsh
|
||||
echo 发布目标:https://gitea.atie.fun/LFeng/Thing
|
||||
echo ================================================
|
||||
echo.
|
||||
|
||||
:: ---------- 版本号 ----------
|
||||
set "VERSION="
|
||||
set /p "VERSION=请输入版本号(如 26.8.1,直接回车沿用当前版本): "
|
||||
set "VER_ARG="
|
||||
if not "%VERSION%"=="" set "VER_ARG=-Version %VERSION%"
|
||||
|
||||
:: ---------- 发布模式 ----------
|
||||
echo.
|
||||
echo [1] Build + Pubilsh Gitea
|
||||
echo [2] Build Only
|
||||
echo [3] Pubilsh Gitea
|
||||
set "MODE="
|
||||
set /p "MODE=请输入数字选择(回车默认 1): "
|
||||
if "%MODE%"=="" set "MODE=1"
|
||||
|
||||
set "EXTRA="
|
||||
if "%MODE%"=="2" (
|
||||
set "EXTRA=-SkipPush"
|
||||
) else if "%MODE%"=="3" (
|
||||
set "EXTRA=-SkipBuild"
|
||||
)
|
||||
|
||||
:: ---------- Gitea Token(仅完整发布模式需要) ----------
|
||||
if "%MODE%"=="1" if not defined GITEA_TOKEN (
|
||||
echo.
|
||||
echo 未检测到环境变量 GITEA_TOKEN,上传到 Gitea 需要它。
|
||||
echo 可在此临时输入(仅本次会话生效),留空则自动改为"只构建不上传"。
|
||||
set /p "GITEA_TOKEN=请输入 Gitea Token: "
|
||||
if "!GITEA_TOKEN!"=="" (
|
||||
set "EXTRA=-SkipPush"
|
||||
set "MODE=2"
|
||||
echo [提示] 已切换为"只构建并整理产物,不上传"。
|
||||
)
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Start:release.ps1 %VER_ARG% %EXTRA%
|
||||
echo ------------------------------------------------
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT%" %VER_ARG% %EXTRA%
|
||||
set "RESULT=%ERRORLEVEL%"
|
||||
|
||||
echo.
|
||||
if "%RESULT%"=="0" (
|
||||
echo 执行完成。
|
||||
) else (
|
||||
echo 执行出错,请查看上方日志。
|
||||
)
|
||||
echo.
|
||||
pause
|
||||
@@ -0,0 +1,166 @@
|
||||
# ============================================================
|
||||
# Thing 构建发布脚本(目标:自建 Gitea release)
|
||||
#
|
||||
# 用法:
|
||||
# .\scripts\release.ps1 -Version 0.2.0 # 同步版本号 + 构建 + 发布
|
||||
# .\scripts\release.ps1 -Version 0.2.0 -SkipBuild # 复用现有构建产物,直接发布
|
||||
# .\scripts\release.ps1 -Version 0.2.0 -SkipPush # 只构建+整理产物,不上传
|
||||
#
|
||||
# 发布产物(上传到 https://gitea.atie.fun/LFeng/Thing 的 v{Version} release):
|
||||
# thing_{v}_x64.exe 便携免安装版(无内核)
|
||||
# thing_{v}_x64.msi 安装版 MSI(去掉 tauri 默认的 _en-US 后缀)
|
||||
# thing_{v}_x64-setup.exe 安装版 NSIS
|
||||
# thing-hk_{v}.zip ThingHK 硬件监控内核(mihomo 继续走代理模块内置的 GitHub 下载)
|
||||
#
|
||||
# 前提:
|
||||
# - Gitea token 已配置为环境变量 GITEA_TOKEN(-SkipPush 时不需要)
|
||||
# - 可选 -NotesPath 指定 release notes 文件(Markdown 文本),
|
||||
# 缺省时使用 scripts/release-notes.md(若存在),否则用简单占位文本
|
||||
# ============================================================
|
||||
|
||||
param(
|
||||
[string]$Version = '',
|
||||
[switch]$SkipBuild,
|
||||
[switch]$SkipPush,
|
||||
[string]$NotesPath = ''
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$Root = Split-Path -Parent $PSScriptRoot
|
||||
$TargetDir = Join-Path $Root 'src-tauri\target\release'
|
||||
$BundleDir = Join-Path $TargetDir 'bundle'
|
||||
$RepoOwner = 'LFeng'
|
||||
$RepoName = 'Thing'
|
||||
$ApiBase = 'https://gitea.atie.fun/api/v1'
|
||||
$Product = 'thing'
|
||||
|
||||
function Write-Step([string]$msg) { Write-Host "`n==> $msg" -ForegroundColor Cyan }
|
||||
|
||||
# ---------- 0. 版本号 ----------
|
||||
if ([string]::IsNullOrWhiteSpace($Version)) {
|
||||
$conf = Get-Content (Join-Path $Root 'src-tauri\tauri.conf.json') -Raw | ConvertFrom-Json
|
||||
$Version = $conf.version
|
||||
Write-Step "未指定 -Version,沿用现有版本 $Version"
|
||||
}
|
||||
# 校验 X.Y.Z 格式
|
||||
if ($Version -notmatch '^\d+\.\d+\.\d+$') {
|
||||
throw "版本号格式错误(应为 X.Y.Z):$Version"
|
||||
}
|
||||
Write-Step "发布版本:v$Version"
|
||||
|
||||
# ---------- 1. 同步版本号到三处 ----------
|
||||
$tauriConf = Join-Path $Root 'src-tauri\tauri.conf.json'
|
||||
$cargoToml = Join-Path $Root 'src-tauri\Cargo.toml'
|
||||
$pkgJson = Join-Path $Root 'package.json'
|
||||
|
||||
$t = Get-Content $tauriConf -Raw
|
||||
$t = $t -replace '("version"\s*:\s*")[^"]*(")', "`${1}$Version`${2}"
|
||||
[System.IO.File]::WriteAllText($tauriConf, $t, (New-Object System.Text.UTF8Encoding($false)))
|
||||
|
||||
$c = Get-Content $cargoToml -Raw
|
||||
$c = $c -replace '(?m)^(version\s*=\s*")[^"]*(")', "`${1}$Version`${2}"
|
||||
[System.IO.File]::WriteAllText($cargoToml, $c, (New-Object System.Text.UTF8Encoding($false)))
|
||||
|
||||
$p = Get-Content $pkgJson -Raw
|
||||
$p = $p -replace '("version"\s*:\s*")[^"]*(")', "`${1}$Version`${2}"
|
||||
[System.IO.File]::WriteAllText($pkgJson, $p, (New-Object System.Text.UTF8Encoding($false)))
|
||||
Write-Step "版本号已同步:tauri.conf.json / Cargo.toml / package.json"
|
||||
|
||||
# ---------- 2. 构建 ----------
|
||||
if (-not $SkipBuild) {
|
||||
Write-Step '开始构建(bun run tauri build)...'
|
||||
Push-Location $Root
|
||||
try { bun run tauri build }
|
||||
finally { Pop-Location }
|
||||
if ($LASTEXITCODE -ne 0) { throw 'tauri build 失败' }
|
||||
} else {
|
||||
Write-Step '跳过构建,复用现有产物'
|
||||
}
|
||||
|
||||
# ---------- 3. 整理产物 ----------
|
||||
# 版本号此时已解析,再确定暂存目录
|
||||
$StageDir = Join-Path $Root "release_stage\$Version"
|
||||
New-Item -ItemType Directory -Force -Path $StageDir | Out-Null
|
||||
|
||||
$exeSrc = Join-Path $TargetDir "$Product.exe"
|
||||
$msiSrc = Join-Path $BundleDir "msi\${Product}_${Version}_x64_en-US.msi"
|
||||
$nsisSrc = Join-Path $BundleDir "nsis\${Product}_${Version}_x64-setup.exe"
|
||||
$hkSrc = Join-Path $Root 'src-tauri\binaries\ThingHK.exe'
|
||||
|
||||
$exeOut = Join-Path $StageDir "${Product}_${Version}_x64.exe"
|
||||
$msiOut = Join-Path $StageDir "${Product}_${Version}_x64.msi"
|
||||
$nsisOut = Join-Path $StageDir "${Product}_${Version}_x64-setup.exe"
|
||||
$hkZip = Join-Path $StageDir "thing-hk_${Version}.zip"
|
||||
|
||||
if (Test-Path $exeSrc) { Copy-Item $exeSrc $exeOut } else { Write-Warning "缺少便携版:$exeSrc" }
|
||||
if (Test-Path $msiSrc) { Copy-Item $msiSrc $msiOut } else { Write-Warning "缺少 MSI(已跳过重命名):$msiSrc" }
|
||||
if (Test-Path $nsisSrc) { Copy-Item $nsisSrc $nsisOut } else { Write-Warning "缺少 NSIS:$nsisSrc" }
|
||||
|
||||
if (Test-Path $hkSrc) {
|
||||
$tmp = Join-Path $env:TEMP "thinghk_$([guid]::NewGuid().ToString('N'))"
|
||||
New-Item -ItemType Directory -Force -Path $tmp | Out-Null
|
||||
Copy-Item $hkSrc (Join-Path $tmp 'ThingHK.exe')
|
||||
Compress-Archive -Path (Join-Path $tmp 'ThingHK.exe') -DestinationPath $hkZip -Force
|
||||
Remove-Item -Recurse -Force $tmp
|
||||
Write-Step "ThingHK 内核包:$hkZip"
|
||||
} else {
|
||||
Write-Warning "缺少 ThingHK.exe:$hkSrc"
|
||||
}
|
||||
|
||||
Write-Step "产物已整理到:$StageDir"
|
||||
Get-ChildItem $StageDir | Select-Object Name, @{n='Size(MB)';e={[math]::Round($_.Length/1MB,1)}} | Format-Table -AutoSize
|
||||
|
||||
# ---------- 4. 上传到 Gitea ----------
|
||||
if ($SkipPush) {
|
||||
Write-Step '已跳过上传(-SkipPush)'
|
||||
exit 0
|
||||
}
|
||||
|
||||
$token = $env:GITEA_TOKEN
|
||||
if ([string]::IsNullOrWhiteSpace($token)) {
|
||||
throw '未设置环境变量 GITEA_TOKEN,无法发布到 Gitea(或使用 -SkipPush 跳过上传)'
|
||||
}
|
||||
$auth = @{ Authorization = "token $token" }
|
||||
|
||||
# 4.1 release notes
|
||||
if (-not [string]::IsNullOrWhiteSpace($NotesPath)) {
|
||||
$body = Get-Content $NotesPath -Raw
|
||||
} elseif (Test-Path (Join-Path $PSScriptRoot 'release-notes.md')) {
|
||||
$body = Get-Content (Join-Path $PSScriptRoot 'release-notes.md') -Raw
|
||||
} else {
|
||||
$body = "Thing v$Version"
|
||||
}
|
||||
|
||||
# 4.2 创建 release(已存在同名 tag 则复用)
|
||||
Write-Step "创建 release v$Version ..."
|
||||
$releaseUrl = "$ApiBase/repos/$RepoOwner/$RepoName/releases"
|
||||
$releasePayload = @{
|
||||
tag_name = "v$Version"
|
||||
name = "Thing v$Version"
|
||||
body = $body
|
||||
draft = $false
|
||||
prerelease = $false
|
||||
} | ConvertTo-Json
|
||||
|
||||
try {
|
||||
$release = Invoke-RestMethod -Method Post -Uri $releaseUrl -Headers $auth -ContentType 'application/json' -Body $releasePayload
|
||||
} catch {
|
||||
# tag 已存在:尝试用该 tag 查找现有 release,后续资产上传会追加
|
||||
Write-Warning "创建 release 失败,尝试复用已有 release:$_"
|
||||
$release = Invoke-RestMethod -Method Get -Uri "$releaseUrl/tags/v$Version" -Headers $auth
|
||||
}
|
||||
$releaseId = $release.id
|
||||
Write-Step "release id=$releaseId"
|
||||
|
||||
# 4.3 逐个上传资产
|
||||
$assets = @($exeOut, $msiOut, $nsisOut, $hkZip) | Where-Object { Test-Path $_ }
|
||||
foreach ($file in $assets) {
|
||||
$name = Split-Path $file -Leaf
|
||||
Write-Step "上传 $name ..."
|
||||
$assetUrl = "$releaseUrl/$releaseId/assets?name=$([uri]::EscapeDataString($name))"
|
||||
$resp = Invoke-RestMethod -Method Post -Uri $assetUrl -Headers $auth -ContentType 'application/octet-stream' -InFile $file
|
||||
Write-Host " -> $($resp.browser_download_url)" -ForegroundColor Green
|
||||
}
|
||||
|
||||
Write-Step "发布完成:https://gitea.atie.fun/$RepoOwner/$RepoName/releases/tag/v$Version"
|
||||
Generated
+1
-1
@@ -4743,7 +4743,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thing"
|
||||
version = "0.1.0"
|
||||
version = "26.8.1"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"base64 0.22.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "thing"
|
||||
version = "0.1.0"
|
||||
version = "26.8.1"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
@@ -46,6 +46,8 @@ pub mod events {
|
||||
pub const SCREENSHOT_PIN_SHORTCUT: &str = "screenshot-pin-shortcut";
|
||||
// 内核安装进度
|
||||
pub const KERNEL_INSTALL_PROGRESS: &str = "kernel-install-progress";
|
||||
// 应用更新进度
|
||||
pub const UPDATE_PROGRESS: &str = "update-progress";
|
||||
// 进程与下载
|
||||
pub const PROCESS_STATUS_CHANGED: &str = "process-status-changed";
|
||||
pub const DOWNLOAD_ADDED: &str = "download-added";
|
||||
|
||||
@@ -15,6 +15,7 @@ mod setup;
|
||||
mod shortcut;
|
||||
mod snap_fix;
|
||||
mod tray_menu;
|
||||
mod updater;
|
||||
mod win32_util;
|
||||
|
||||
use download_engine::{
|
||||
@@ -77,6 +78,7 @@ use quickpanel::{
|
||||
quickpanel_unregister_shortcut,
|
||||
};
|
||||
use tray_menu::{tray_menu_action, tray_menu_hide, tray_menu_ready};
|
||||
use updater::{app_version, update_check, update_install, update_thinghk};
|
||||
|
||||
#[tauri::command]
|
||||
fn quit_app(app: tauri::AppHandle) {
|
||||
@@ -101,6 +103,8 @@ fn export_bindings() {
|
||||
// 生成命令失败时直接 throw,与原生 invoke 一致,前端无需解包 helper
|
||||
.error_handling(ErrorHandlingMode::Throw)
|
||||
.commands(collect_commands![
|
||||
// 应用更新(4)
|
||||
app_version, update_check, update_install, update_thinghk,
|
||||
// proxy(20)
|
||||
proxy_activate_profile, proxy_check_kernel_update, proxy_clear_system_proxy,
|
||||
proxy_close_connection, proxy_delete_profile, proxy_get_settings,
|
||||
@@ -163,6 +167,10 @@ pub fn run() {
|
||||
.manage(ProcessManager::new())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
quit_app,
|
||||
app_version,
|
||||
update_check,
|
||||
update_install,
|
||||
update_thinghk,
|
||||
process_start,
|
||||
process_stop,
|
||||
process_status,
|
||||
|
||||
@@ -0,0 +1,457 @@
|
||||
//! 应用自更新模块。
|
||||
//! 更新源为自建 Gitea:`https://gitea.atie.fun/LFeng/Thing` 的 release 资产。
|
||||
//! - 便携版(无 unins000.exe 且不在 Program Files):下载新 thing.exe → update.bat 覆盖重启
|
||||
//! - 安装版(NSIS):下载新 setup.exe → 提权静默安装 /S
|
||||
//! - ThingHK 内核:下载 thing-hk_{v}.zip → 停止监控内核 → 覆盖 {app_data}/monitor/cores/ThingHK.exe
|
||||
//! mihomo 内核更新继续复用代理模块已有的 GitHub 下载机制,不在此模块处理。
|
||||
use futures_util::StreamExt;
|
||||
use serde::Serialize;
|
||||
use specta::Type;
|
||||
use std::fs;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use tauri::{AppHandle, Emitter, Manager};
|
||||
|
||||
use crate::constants::events::UPDATE_PROGRESS;
|
||||
|
||||
/// 发布仓库(Gitea)
|
||||
const GITEA_REPO: &str = "LFeng/Thing";
|
||||
const GITEA_BASE: &str = "https://gitea.atie.fun";
|
||||
|
||||
/// release 中的一个资产
|
||||
#[derive(Debug, Clone, Serialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UpdateAsset {
|
||||
pub name: String,
|
||||
pub size: u64,
|
||||
pub browser_download_url: String,
|
||||
}
|
||||
|
||||
/// 检查更新的结果
|
||||
#[derive(Debug, Clone, Serialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UpdateCheckResult {
|
||||
pub current_version: String,
|
||||
pub latest_version: String,
|
||||
pub has_update: bool,
|
||||
/// portable | installed
|
||||
pub install_type: String,
|
||||
pub release_name: String,
|
||||
pub release_body: String,
|
||||
pub assets: Vec<UpdateAsset>,
|
||||
}
|
||||
|
||||
/// 更新进度事件载荷(与内核安装进度同构,独立事件便于 UI 区分)
|
||||
#[derive(Serialize, Clone, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UpdateProgress {
|
||||
pub stage: String,
|
||||
pub percent: u8,
|
||||
#[specta(type = f64)]
|
||||
pub downloaded_bytes: u64,
|
||||
#[specta(type = Option<f64>)]
|
||||
pub total_bytes: Option<u64>,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
// ---------- 版本比较 ----------
|
||||
|
||||
/// 解析 vX.Y.Z 为数字元组用于比较;解析失败返回 (0,0,0)
|
||||
fn parse_version(v: &str) -> (u32, u32, u32) {
|
||||
let s = v.trim().trim_start_matches('v');
|
||||
let mut parts = s.split('.');
|
||||
let major = parts.next().and_then(|p| p.parse().ok()).unwrap_or(0);
|
||||
let minor = parts.next().and_then(|p| p.parse().ok()).unwrap_or(0);
|
||||
let patch = parts
|
||||
.next()
|
||||
.map(|p| p.chars().take_while(|c| c.is_ascii_digit()).collect::<String>())
|
||||
.and_then(|p| p.parse().ok())
|
||||
.unwrap_or(0);
|
||||
(major, minor, patch)
|
||||
}
|
||||
|
||||
fn version_gt(a: &str, b: &str) -> bool {
|
||||
parse_version(a) > parse_version(b)
|
||||
}
|
||||
|
||||
// ---------- Gitea API ----------
|
||||
|
||||
struct LatestRelease {
|
||||
tag_name: String,
|
||||
name: String,
|
||||
body: String,
|
||||
assets: Vec<UpdateAsset>,
|
||||
}
|
||||
|
||||
async fn fetch_latest_release() -> Result<LatestRelease, String> {
|
||||
let url = format!("{}/api/v1/repos/{}/releases/latest", GITEA_BASE, GITEA_REPO);
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(15))
|
||||
.build()
|
||||
.map_err(|e| format!("创建 HTTP 客户端失败: {}", e))?;
|
||||
let resp = client
|
||||
.get(&url)
|
||||
.header("User-Agent", "thing-app")
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("请求 Gitea API 失败: {}", e))?;
|
||||
if !resp.status().is_success() {
|
||||
return Err(format!("Gitea API 返回 HTTP {}", resp.status()));
|
||||
}
|
||||
let json: serde_json::Value = resp
|
||||
.json()
|
||||
.await
|
||||
.map_err(|e| format!("解析 Gitea 响应失败: {}", e))?;
|
||||
let mut assets = Vec::new();
|
||||
if let Some(list) = json.get("assets").and_then(|v| v.as_array()) {
|
||||
for a in list {
|
||||
if let (Some(name), Some(url)) = (
|
||||
a.get("name").and_then(|v| v.as_str()),
|
||||
a.get("browser_download_url").and_then(|v| v.as_str()),
|
||||
) {
|
||||
assets.push(UpdateAsset {
|
||||
name: name.to_string(),
|
||||
size: a.get("size").and_then(|v| v.as_u64()).unwrap_or(0),
|
||||
browser_download_url: url.to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(LatestRelease {
|
||||
tag_name: json.get("tag_name").and_then(|v| v.as_str()).unwrap_or("").to_string(),
|
||||
name: json.get("name").and_then(|v| v.as_str()).unwrap_or("").to_string(),
|
||||
body: json.get("body").and_then(|v| v.as_str()).unwrap_or("").to_string(),
|
||||
assets,
|
||||
})
|
||||
}
|
||||
|
||||
// ---------- 下载 / 解压 ----------
|
||||
|
||||
/// 下载文件到 dest,期间通过 UPDATE_PROGRESS 事件上报进度
|
||||
async fn download_with_progress(app: &AppHandle, url: &str, dest: &Path) -> Result<(), String> {
|
||||
let client = reqwest::Client::new();
|
||||
let resp = client
|
||||
.get(url)
|
||||
.header("User-Agent", "thing-app")
|
||||
.timeout(std::time::Duration::from_secs(30))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("下载请求失败: {}", e))?;
|
||||
if !resp.status().is_success() {
|
||||
return Err(format!("下载失败: HTTP {}", resp.status()));
|
||||
}
|
||||
let total = resp.content_length();
|
||||
let mut stream = resp.bytes_stream();
|
||||
let mut file = fs::File::create(dest).map_err(|e| format!("创建文件失败: {}", e))?;
|
||||
let mut downloaded: u64 = 0;
|
||||
let mut last_percent: u8 = 0;
|
||||
while let Some(chunk) = stream.next().await {
|
||||
let chunk = chunk.map_err(|e| format!("读取下载流失败: {}", e))?;
|
||||
file.write_all(&chunk).map_err(|e| format!("写入文件失败: {}", e))?;
|
||||
downloaded += chunk.len() as u64;
|
||||
let percent = match total {
|
||||
Some(t) if t > 0 => ((downloaded as f64 / t as f64) * 100.0) as u8,
|
||||
_ => 0,
|
||||
};
|
||||
if percent >= last_percent + 1 {
|
||||
last_percent = percent;
|
||||
let _ = app.emit(
|
||||
UPDATE_PROGRESS,
|
||||
UpdateProgress {
|
||||
stage: "downloading".into(),
|
||||
percent,
|
||||
downloaded_bytes: downloaded,
|
||||
total_bytes: total,
|
||||
message: format!(
|
||||
"已下载 {:.2} MB / {:.2} MB",
|
||||
downloaded as f64 / 1024.0 / 1024.0,
|
||||
total.unwrap_or(0) as f64 / 1024.0 / 1024.0
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
file.flush().map_err(|e| format!("flush 失败: {}", e))?;
|
||||
let _ = app.emit(
|
||||
UPDATE_PROGRESS,
|
||||
UpdateProgress {
|
||||
stage: "downloaded".into(),
|
||||
percent: 100,
|
||||
downloaded_bytes: downloaded,
|
||||
total_bytes: total,
|
||||
message: "下载完成".into(),
|
||||
},
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 用 zip crate 解压(纯 Rust,避免 PowerShell 执行策略问题)
|
||||
fn extract_zip(zip_path: &Path, dest: &Path) -> Result<(), String> {
|
||||
let file = fs::File::open(zip_path).map_err(|e| format!("打开 zip 失败: {}", e))?;
|
||||
let mut archive = zip::ZipArchive::new(file).map_err(|e| format!("读取 zip 失败: {}", e))?;
|
||||
for i in 0..archive.len() {
|
||||
let mut entry = archive
|
||||
.by_index(i)
|
||||
.map_err(|e| format!("读取条目失败: {}", e))?;
|
||||
let outpath = match entry.enclosed_name() {
|
||||
Some(p) => dest.join(p),
|
||||
None => continue,
|
||||
};
|
||||
if entry.is_dir() {
|
||||
fs::create_dir_all(&outpath).map_err(|e| e.to_string())?;
|
||||
} else {
|
||||
if let Some(parent) = outpath.parent() {
|
||||
fs::create_dir_all(parent).map_err(|e| e.to_string())?;
|
||||
}
|
||||
let mut outfile = fs::File::create(&outpath).map_err(|e| e.to_string())?;
|
||||
let mut buf = [0u8; 8192];
|
||||
loop {
|
||||
let n = entry.read(&mut buf).map_err(|e| e.to_string())?;
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
outfile.write_all(&buf[..n]).map_err(|e| e.to_string())?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// ---------- 安装类型 / ShellExecute ----------
|
||||
|
||||
/// 判断当前是便携版还是安装版。
|
||||
/// NSIS 安装会在程序目录生成 unins000.exe;MSI 通常安装到 Program Files。
|
||||
fn is_installed_version() -> bool {
|
||||
if let Ok(exe) = std::env::current_exe() {
|
||||
if let Some(dir) = exe.parent() {
|
||||
if dir.join("unins000.exe").exists() {
|
||||
return true;
|
||||
}
|
||||
let p = dir.to_string_lossy().to_lowercase();
|
||||
if p.contains("program files") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// 通过 ShellExecuteW 启动程序/文档(绕过 Job Object,脱离主进程生命周期)
|
||||
fn shell_execute(verb: &str, file: &Path, params: &str, show: i32) -> Result<(), String> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use windows_sys::Win32::UI::Shell::ShellExecuteW;
|
||||
let file_w: Vec<u16> = file.as_os_str().encode_wide().chain(std::iter::once(0)).collect();
|
||||
let verb_w: Vec<u16> = verb.encode_utf16().chain(std::iter::once(0)).collect();
|
||||
let params_w: Vec<u16> = params.encode_utf16().chain(std::iter::once(0)).collect();
|
||||
let res = unsafe {
|
||||
ShellExecuteW(
|
||||
0 as isize,
|
||||
verb_w.as_ptr(),
|
||||
file_w.as_ptr(),
|
||||
params_w.as_ptr(),
|
||||
std::ptr::null(),
|
||||
show,
|
||||
)
|
||||
};
|
||||
if (res as isize) <= 32 {
|
||||
return Err(format!("ShellExecuteW 失败 (code={})", res));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let _ = (verb, file, params, show);
|
||||
Err("仅支持 Windows".into())
|
||||
}
|
||||
}
|
||||
|
||||
/// 便携版:写 update.bat 等待主进程退出 → 覆盖 exe → 重新启动
|
||||
fn apply_portable_update(new_exe: &Path) -> Result<(), String> {
|
||||
let cur_exe = std::env::current_exe().map_err(|e| format!("获取当前程序路径失败: {}", e))?;
|
||||
let cur_dir = cur_exe.parent().ok_or("无法确定程序目录".to_string())?;
|
||||
let bat_path = cur_dir.join("update.bat");
|
||||
let script = format!(
|
||||
"@echo off\r\n\
|
||||
:wait\r\n\
|
||||
tasklist /FI \"IMAGENAME eq thing.exe\" 2>nul | findstr /i \"thing.exe\" >nul\r\n\
|
||||
if not errorlevel 1 (\r\n\
|
||||
ping -n 2 127.0.0.1 >nul\r\n\
|
||||
goto wait\r\n\
|
||||
)\r\n\
|
||||
copy /y \"{new}\" \"{cur}\" >nul\r\n\
|
||||
if errorlevel 1 exit /b 1\r\n\
|
||||
start \"\" \"{cur}\"\r\n\
|
||||
del \"{new}\" >nul 2>nul\r\n\
|
||||
del \"%~f0\" >nul 2>nul\r\n",
|
||||
new = new_exe.display(),
|
||||
cur = cur_exe.display()
|
||||
);
|
||||
fs::write(&bat_path, script).map_err(|e| format!("写入更新脚本失败: {}", e))?;
|
||||
// 用 cmd /c 启动 bat 并隐藏窗口;ShellExecute 启动的进程不属于本进程 Job,
|
||||
// 主进程退出后 update.bat 仍能继续执行
|
||||
let windir = std::env::var("WINDIR").unwrap_or_else(|_| "C:\\Windows".into());
|
||||
let cmd_exe = Path::new(&windir).join("System32").join("cmd.exe");
|
||||
shell_execute("open", &cmd_exe, &format!("/c \"{}\"", bat_path.display()), 0)
|
||||
}
|
||||
|
||||
// ---------- 命令 ----------
|
||||
|
||||
/// 获取当前应用版本
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub fn app_version(app: AppHandle) -> String {
|
||||
app.package_info().version.to_string()
|
||||
}
|
||||
|
||||
/// 检查 Gitea 最新 release,返回版本对比与可用资产
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn update_check(app: AppHandle) -> Result<UpdateCheckResult, String> {
|
||||
let latest = fetch_latest_release().await?;
|
||||
let latest_version = latest.tag_name.trim_start_matches('v').to_string();
|
||||
let current_version = app.package_info().version.to_string();
|
||||
let has_update = version_gt(&latest_version, ¤t_version);
|
||||
Ok(UpdateCheckResult {
|
||||
current_version,
|
||||
latest_version,
|
||||
has_update,
|
||||
install_type: if is_installed_version() { "installed".into() } else { "portable".into() },
|
||||
release_name: latest.name,
|
||||
release_body: latest.body,
|
||||
assets: latest.assets,
|
||||
})
|
||||
}
|
||||
|
||||
/// 更新应用本体。
|
||||
/// 便携版:下载 thing_{v}_x64.exe → update.bat 覆盖重启;
|
||||
/// 安装版:下载 thing_{v}_x64-setup.exe → 提权静默安装 /S。
|
||||
/// 下载进度通过 UPDATE_PROGRESS 事件上报,调用方返回前会触发应用退出。
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn update_install(app: AppHandle) -> Result<(), String> {
|
||||
let latest = fetch_latest_release().await?;
|
||||
let installed = is_installed_version();
|
||||
let (target_name, target_url) = if installed {
|
||||
latest
|
||||
.assets
|
||||
.iter()
|
||||
.find(|a| a.name.ends_with("-setup.exe"))
|
||||
.map(|a| (a.name.clone(), a.browser_download_url.clone()))
|
||||
.ok_or("未在 release 中找到安装包 (setup.exe)".to_string())?
|
||||
} else {
|
||||
latest
|
||||
.assets
|
||||
.iter()
|
||||
.find(|a| a.name.ends_with(".exe") && !a.name.contains("setup"))
|
||||
.map(|a| (a.name.clone(), a.browser_download_url.clone()))
|
||||
.ok_or("未在 release 中找到便携版程序 (thing.exe)".to_string())?
|
||||
};
|
||||
let temp_dir = std::env::temp_dir().join("thing-update");
|
||||
fs::create_dir_all(&temp_dir).map_err(|e| format!("创建临时目录失败: {}", e))?;
|
||||
let dest = temp_dir.join(&target_name);
|
||||
download_with_progress(&app, &target_url, &dest).await?;
|
||||
let _ = app.emit(
|
||||
UPDATE_PROGRESS,
|
||||
UpdateProgress {
|
||||
stage: "applying".into(),
|
||||
percent: 100,
|
||||
downloaded_bytes: 0,
|
||||
total_bytes: None,
|
||||
message: if installed { "正在启动安装程序...".into() } else { "正在替换程序文件...".into() },
|
||||
},
|
||||
);
|
||||
if installed {
|
||||
// 提权静默安装 /S;UAC 确认期间主进程已退出,安装器可正常覆盖
|
||||
shell_execute("runas", &dest, "/S", 0)?;
|
||||
} else {
|
||||
apply_portable_update(&dest)?;
|
||||
}
|
||||
// 延迟退出,确保 ShellExecute 已拉起子进程
|
||||
app.exit(0);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 更新 ThingHK 内核:下载 thing-hk_{v}.zip → 停止监控内核 → 覆盖内核文件
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn update_thinghk(app: AppHandle) -> Result<(), String> {
|
||||
let latest = fetch_latest_release().await?;
|
||||
let asset = latest
|
||||
.assets
|
||||
.iter()
|
||||
.find(|a| a.name.starts_with("thing-hk_") && a.name.ends_with(".zip"))
|
||||
.ok_or("未在 release 中找到 ThingHK 内核包".to_string())?;
|
||||
// 停止监控内核(含提权模式的 /shutdown 兜底由前端先停模块),避免 exe 被占用
|
||||
if let Some(monitor) = app.try_state::<crate::monitor_kernel::MonitorKernel>() {
|
||||
monitor.stop_subscription(&app).await;
|
||||
}
|
||||
if let Some(pm) = app.try_state::<crate::process_manager::ProcessManager>() {
|
||||
let _ = pm.stop("monitor");
|
||||
}
|
||||
// 等待进程退出释放文件句柄
|
||||
tokio::time::sleep(std::time::Duration::from_millis(600)).await;
|
||||
let temp_dir = std::env::temp_dir().join("thing-update");
|
||||
fs::create_dir_all(&temp_dir).map_err(|e| format!("创建临时目录失败: {}", e))?;
|
||||
let zip_path = temp_dir.join(&asset.name);
|
||||
download_with_progress(&app, &asset.browser_download_url, &zip_path).await?;
|
||||
let _ = app.emit(
|
||||
UPDATE_PROGRESS,
|
||||
UpdateProgress {
|
||||
stage: "extracting".into(),
|
||||
percent: 95,
|
||||
downloaded_bytes: 0,
|
||||
total_bytes: None,
|
||||
message: "正在解压内核...".into(),
|
||||
},
|
||||
);
|
||||
let extract_dir = temp_dir.join("thinghk_extract");
|
||||
let _ = fs::remove_dir_all(&extract_dir);
|
||||
extract_zip(&zip_path, &extract_dir)?;
|
||||
// 在解压目录中查找 ThingHK.exe
|
||||
let exe_path = find_thinghk_exe(&extract_dir).ok_or("内核包中未找到 ThingHK.exe".to_string())?;
|
||||
let app_data = app
|
||||
.path()
|
||||
.app_data_dir()
|
||||
.map_err(|e| format!("获取数据目录失败: {}", e))?;
|
||||
let cores_dir = app_data.join("monitor").join("cores");
|
||||
fs::create_dir_all(&cores_dir).map_err(|e| format!("创建内核目录失败: {}", e))?;
|
||||
fs::copy(&exe_path, cores_dir.join("ThingHK.exe"))
|
||||
.map_err(|e| format!("覆盖内核文件失败(请确认监控模块已停止): {}", e))?;
|
||||
// 清理临时文件
|
||||
let _ = fs::remove_file(&zip_path);
|
||||
let _ = fs::remove_dir_all(&extract_dir);
|
||||
let _ = app.emit(
|
||||
UPDATE_PROGRESS,
|
||||
UpdateProgress {
|
||||
stage: "done".into(),
|
||||
percent: 100,
|
||||
downloaded_bytes: 0,
|
||||
total_bytes: None,
|
||||
message: "ThingHK 内核更新完成".into(),
|
||||
},
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn find_thinghk_exe(dir: &Path) -> Option<PathBuf> {
|
||||
if let Ok(entries) = fs::read_dir(dir) {
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
if let Some(found) = find_thinghk_exe(&path) {
|
||||
return Some(found);
|
||||
}
|
||||
} else if path
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.map(|s| s.eq_ignore_ascii_case("ThingHK.exe"))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Some(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "thing",
|
||||
"version": "0.1.0",
|
||||
"version": "26.8.1",
|
||||
"identifier": "thing.lfeng.me",
|
||||
"build": {
|
||||
"beforeDevCommand": "bun run dev",
|
||||
|
||||
@@ -42,6 +42,11 @@ const hasSearchContent = computed(() => {
|
||||
return searchQuery.value.trim().length > 0
|
||||
})
|
||||
|
||||
/** 模块 id → 名称 查找表(用于搜索结果中标注所属模块) */
|
||||
const moduleNameById = computed(() => {
|
||||
return new Map(props.modules.map(m => [m.id, m.name]))
|
||||
})
|
||||
|
||||
const handleSearchSelect = (moduleId: string) => {
|
||||
emit('search', moduleId)
|
||||
searchQuery.value = ''
|
||||
@@ -50,6 +55,10 @@ const handleSearchSelect = (moduleId: string) => {
|
||||
|
||||
const handleSettingSelect = (item: SearchItem) => {
|
||||
emit('search', item.moduleId)
|
||||
// 记录待跳转 tab:模块挂载后由 useModuleTabs 自动切换(模块已挂载时同样生效)
|
||||
if (item.tab) {
|
||||
tabsStore.setPendingTab(item.moduleId, item.tab)
|
||||
}
|
||||
if (item.action) {
|
||||
item.action()
|
||||
}
|
||||
@@ -323,14 +332,19 @@ const handleBlur = () => {
|
||||
class="w-full px-3 py-2 text-left text-sm hover:bg-accent transition-colors flex items-center gap-2"
|
||||
@click="handleSettingSelect(item)"
|
||||
>
|
||||
<Settings class="size-4 text-muted-foreground" />
|
||||
<Settings class="size-4 text-muted-foreground shrink-0" />
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<span class="truncate">{{ item.title }}</span>
|
||||
<span class="shrink-0 text-[10px] text-muted-foreground/70 px-1 py-px rounded bg-muted">
|
||||
{{ moduleNameById.get(item.moduleId) || item.moduleId }}
|
||||
</span>
|
||||
</div>
|
||||
<span v-if="item.description" class="block text-xs text-muted-foreground truncate">
|
||||
{{ item.description }}
|
||||
</span>
|
||||
</div>
|
||||
<ChevronRight class="size-4 text-muted-foreground" />
|
||||
<ChevronRight class="size-4 text-muted-foreground shrink-0" />
|
||||
</button>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -4,6 +4,19 @@ import { invoke as __TAURI_INVOKE } from "@tauri-apps/api/core";
|
||||
|
||||
/** Commands */
|
||||
export const commands = {
|
||||
/** 获取当前应用版本 */
|
||||
appVersion: () => __TAURI_INVOKE<string>("app_version"),
|
||||
/** 检查 Gitea 最新 release,返回版本对比与可用资产 */
|
||||
updateCheck: () => __TAURI_INVOKE<UpdateCheckResult>("update_check"),
|
||||
/**
|
||||
* 更新应用本体。
|
||||
* 便携版:下载 thing_{v}_x64.exe → update.bat 覆盖重启;
|
||||
* 安装版:下载 thing_{v}_x64-setup.exe → 提权静默安装 /S。
|
||||
* 下载进度通过 UPDATE_PROGRESS 事件上报,调用方返回前会触发应用退出。
|
||||
*/
|
||||
updateInstall: () => __TAURI_INVOKE<null>("update_install"),
|
||||
/** 更新 ThingHK 内核:下载 thing-hk_{v}.zip → 停止监控内核 → 覆盖内核文件 */
|
||||
updateThinghk: () => __TAURI_INVOKE<null>("update_thinghk"),
|
||||
proxyActivateProfile: (id: string) => __TAURI_INVOKE<null>("proxy_activate_profile", { id }),
|
||||
proxyCheckKernelUpdate: () => __TAURI_INVOKE<KernelUpdateInfo>("proxy_check_kernel_update"),
|
||||
proxyClearSystemProxy: () => __TAURI_INVOKE<null>("proxy_clear_system_proxy"),
|
||||
@@ -480,6 +493,25 @@ export type TaskStatus =
|
||||
/** 错误 */
|
||||
"error";
|
||||
|
||||
/** release 中的一个资产 */
|
||||
export type UpdateAsset = {
|
||||
name: string,
|
||||
size: number,
|
||||
browserDownloadUrl: string,
|
||||
};
|
||||
|
||||
/** 检查更新的结果 */
|
||||
export type UpdateCheckResult = {
|
||||
currentVersion: string,
|
||||
latestVersion: string,
|
||||
hasUpdate: boolean,
|
||||
/** portable | installed */
|
||||
installType: string,
|
||||
releaseName: string,
|
||||
releaseBody: string,
|
||||
assets: UpdateAsset[],
|
||||
};
|
||||
|
||||
/** 窗口信息(窗口拾取 / 枚举) */
|
||||
export type WindowInfo = {
|
||||
hwnd: number,
|
||||
|
||||
@@ -38,6 +38,8 @@ export const EVENTS = {
|
||||
screenshotExported: 'screenshot-exported',
|
||||
// 内核安装进度
|
||||
kernelInstallProgress: 'kernel-install-progress',
|
||||
// 应用更新进度
|
||||
updateProgress: 'update-progress',
|
||||
// 监控 OSD
|
||||
osdStateUpdate: 'osd-state-update',
|
||||
osdContentSize: 'osd-content-size',
|
||||
|
||||
@@ -12,12 +12,15 @@ import { useModuleTabsStore, type ModuleTab } from '@/stores/moduleTabsStore'
|
||||
* ```ts
|
||||
* // 模块 <script setup> 顶部
|
||||
* const activeTab = ref('overview')
|
||||
* const tabsListRef = useModuleTabs(activeTab, [
|
||||
* const tabsListRef = useModuleTabs('proxy', activeTab, [
|
||||
* { value: 'overview', label: '概览' },
|
||||
* { value: 'settings', label: '设置' }
|
||||
* ])
|
||||
* ```
|
||||
*
|
||||
* 第一个参数为模块 id:搜索导航跳转时,模块挂载后会自动
|
||||
* 消费 moduleTabsStore 中对应的待跳转 tab(pendingTab)。
|
||||
*
|
||||
* ```vue
|
||||
* <!-- 模板中给 TabsList 包一层带 ref 的 div -->
|
||||
* <div ref="tabsListRef">
|
||||
@@ -29,7 +32,8 @@ import { useModuleTabsStore, type ModuleTab } from '@/stores/moduleTabsStore'
|
||||
* 1. onMounted 时注册标签到 moduleTabsStore,TitleBar 据此渲染浮动切换器
|
||||
* 2. 用 IntersectionObserver 监听 TabsList 可见性(rootMargin 裁剪 TitleBar 高度)
|
||||
* 3. 双向 watch 同步本地 activeTab 与 store.activeTab
|
||||
* 4. onUnmounted 时清理 observer 并注销标签
|
||||
* 4. 消费搜索导航的待跳转 tab(模块尚未挂载的场景)
|
||||
* 5. onUnmounted 时清理 observer 并注销标签
|
||||
*
|
||||
* ## 约束
|
||||
* - TitleBar 高度固定为 40px (h-10),composable 内部已用 44px 裁剪(含缓冲)
|
||||
@@ -37,6 +41,7 @@ import { useModuleTabsStore, type ModuleTab } from '@/stores/moduleTabsStore'
|
||||
* - 模块卸载时务必让 composable 的 onUnmounted 执行(已自动处理,无需手动调用)
|
||||
*/
|
||||
export function useModuleTabs(
|
||||
moduleId: string,
|
||||
activeTab: Ref<string>,
|
||||
tabs: ModuleTab[]
|
||||
): Ref<HTMLElement | null> {
|
||||
@@ -45,6 +50,15 @@ export function useModuleTabs(
|
||||
|
||||
let observer: IntersectionObserver | null = null
|
||||
|
||||
/** 应用待跳转 tab(若属于当前模块的 tab 列表) */
|
||||
const applyPendingTab = () => {
|
||||
const pending = tabsStore.consumePendingTab(moduleId)
|
||||
if (pending && tabs.some(t => t.value === pending)) {
|
||||
activeTab.value = pending
|
||||
tabsStore.setActiveTab(pending)
|
||||
}
|
||||
}
|
||||
|
||||
const setupObserver = () => {
|
||||
const el = tabsListRef.value
|
||||
if (!el || observer) return
|
||||
@@ -75,10 +89,19 @@ export function useModuleTabs(
|
||||
}
|
||||
})
|
||||
|
||||
// 模块已挂载时(搜索结果选中同一模块),pendingTab 变化 → 直接切换 tab
|
||||
watch(() => tabsStore.pendingTab, (p) => {
|
||||
if (p?.moduleId === moduleId) {
|
||||
applyPendingTab()
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
tabsStore.registerTabs(tabs, activeTab.value)
|
||||
await nextTick()
|
||||
setupObserver()
|
||||
// 搜索导航跳转:模块刚挂载,消费待跳转 tab
|
||||
applyPendingTab()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
|
||||
@@ -6,6 +6,9 @@ import 'vue-sonner/style.css'
|
||||
import { createLogger } from './lib/logger'
|
||||
const logger = createLogger('main')
|
||||
|
||||
// 禁用 WebView 默认右键菜单(桌面应用体验,主窗口与独立窗口共用)
|
||||
document.addEventListener('contextmenu', (e) => e.preventDefault())
|
||||
|
||||
// 全局未捕获异常日志
|
||||
window.addEventListener('error', (event) => {
|
||||
logger.error(`全局JS错误: ${event.message} @ ${event.filename}:${event.lineno}`)
|
||||
|
||||
@@ -32,7 +32,7 @@ const store = useClipboardStore()
|
||||
|
||||
const activeTab = ref('history')
|
||||
const tabsStore = useModuleTabsStore()
|
||||
const tabsListRef = useModuleTabs(activeTab, [
|
||||
const tabsListRef = useModuleTabs('clipboard', activeTab, [
|
||||
{ value: 'history', label: '历史' },
|
||||
{ value: 'pinned', label: '固定' },
|
||||
{ value: 'settings', label: '设置' },
|
||||
|
||||
@@ -5,7 +5,44 @@ const searchItems: SearchIndexItem[] = [
|
||||
{
|
||||
title: '剪贴板历史',
|
||||
description: '查看和管理剪贴板记录',
|
||||
keywords: ['剪贴板', '复制', '粘贴', 'clipboard', 'copy', 'paste']
|
||||
keywords: ['剪贴板', '复制', '粘贴', 'clipboard', 'copy', 'paste'],
|
||||
tab: 'history'
|
||||
},
|
||||
{
|
||||
title: '固定记录',
|
||||
description: '查看固定的剪贴板条目',
|
||||
keywords: ['固定', '收藏', 'pin', '置顶'],
|
||||
tab: 'pinned'
|
||||
},
|
||||
{
|
||||
title: '剪贴板设置',
|
||||
description: '历史数量、图片收录与快捷弹窗快捷键',
|
||||
keywords: ['设置', 'setting', '选项', '配置'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '快捷弹窗快捷键',
|
||||
description: '配置全局快捷键唤起剪贴板弹窗',
|
||||
keywords: ['快捷键', '热键', 'shortcut', 'hotkey', '弹窗', 'popup'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '最大历史条数',
|
||||
description: '设置剪贴板历史记录数量上限',
|
||||
keywords: ['历史', '数量', '上限', '条数', 'max', 'limit'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '图片大小上限',
|
||||
description: '设置收录图片的大小上限 (KB)',
|
||||
keywords: ['图片', '大小', '上限', 'image', 'kb', '体积'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '记录图片',
|
||||
description: '是否收录复制/截图的图片',
|
||||
keywords: ['图片', '截图', '收录', 'image', 'capture'],
|
||||
tab: 'settings'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ const logger = createLogger('downloader')
|
||||
// ===== 主 Tab 状态 =====
|
||||
const activeTab = ref('tasks')
|
||||
const tabsStore = useModuleTabsStore()
|
||||
const tabsListRef = useModuleTabs(activeTab, [
|
||||
const tabsListRef = useModuleTabs('downloader', activeTab, [
|
||||
{ value: 'tasks', label: '下载任务' },
|
||||
{ value: 'settings', label: '设置' },
|
||||
{ value: 'extension', label: '浏览器扩展' }
|
||||
|
||||
@@ -5,22 +5,44 @@ const searchItems: SearchIndexItem[] = [
|
||||
{
|
||||
title: '下载任务',
|
||||
description: '查看与管理下载任务',
|
||||
keywords: ['下载', 'download', '任务', 'task']
|
||||
keywords: ['下载', 'download', '任务', 'task'],
|
||||
tab: 'tasks'
|
||||
},
|
||||
{
|
||||
title: '添加下载',
|
||||
description: '添加 HTTP/HTTPS 直链下载',
|
||||
keywords: ['添加', '链接', 'url', 'add', '新建']
|
||||
keywords: ['添加', '链接', 'url', 'add', '新建'],
|
||||
tab: 'tasks'
|
||||
},
|
||||
{
|
||||
title: '下载设置',
|
||||
description: '配置下载目录、并发数与速度限制',
|
||||
keywords: ['设置', 'setting', '速度', '目录', '并发']
|
||||
keywords: ['设置', 'setting', '速度', '目录', '并发'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '下载目录',
|
||||
description: '设置任务默认保存目录',
|
||||
keywords: ['目录', '保存', '路径', 'dir', 'folder', '下载位置'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '并发下载数',
|
||||
description: '设置同时下载的任务数量上限',
|
||||
keywords: ['并发', '数量', 'concurrent', '线程'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '速度限制',
|
||||
description: '设置全局下载/上传限速',
|
||||
keywords: ['限速', '速度', '速率', 'rate', 'limit', '带宽'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '浏览器扩展',
|
||||
description: '安装 Thing Extension 接管浏览器下载',
|
||||
keywords: ['扩展', 'extension', '浏览器', 'chrome', 'edge']
|
||||
keywords: ['扩展', 'extension', '浏览器', 'chrome', 'edge'],
|
||||
tab: 'extension'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ const store = useMonitorStore()
|
||||
|
||||
// ===== Tab 配置(注册到 TitleBar 浮动切换器) =====
|
||||
const activeTab = ref('overview')
|
||||
const tabsListRef = useModuleTabs(activeTab, [
|
||||
const tabsListRef = useModuleTabs('monitor', activeTab, [
|
||||
{ value: 'overview', label: '概览' },
|
||||
{ value: 'details', label: '详细' },
|
||||
{ value: 'osd', label: 'OSD 显示' },
|
||||
|
||||
@@ -6,7 +6,56 @@ const searchItems: SearchIndexItem[] = [
|
||||
{
|
||||
title: '硬件监控',
|
||||
description: '查看系统硬件状态',
|
||||
keywords: ['监控', '硬件', 'cpu', '内存', 'monitor', 'hardware']
|
||||
keywords: ['监控', '硬件', 'cpu', '内存', 'monitor', 'hardware'],
|
||||
tab: 'overview'
|
||||
},
|
||||
{
|
||||
title: '详细数据',
|
||||
description: '查看各传感器详细读数',
|
||||
keywords: ['详细', '数据', '传感器', 'sensor', '温度', '转速'],
|
||||
tab: 'details'
|
||||
},
|
||||
{
|
||||
title: 'OSD 显示',
|
||||
description: '配置悬浮窗显示项、位置与外观',
|
||||
keywords: ['osd', '悬浮窗', '小窗', '显示', 'overlay'],
|
||||
tab: 'osd'
|
||||
},
|
||||
{
|
||||
title: 'OSD 悬浮窗位置',
|
||||
description: '设置悬浮窗在屏幕中的位置',
|
||||
keywords: ['位置', '悬浮窗', '屏幕', 'position', 'osd'],
|
||||
tab: 'osd'
|
||||
},
|
||||
{
|
||||
title: '警告阈值',
|
||||
description: '设置传感器告警阈值与颜色',
|
||||
keywords: ['阈值', '告警', '警告', 'threshold', '颜色'],
|
||||
tab: 'osd'
|
||||
},
|
||||
{
|
||||
title: '监控设置',
|
||||
description: '内核控制、自动启动与监控项配置',
|
||||
keywords: ['设置', 'setting', '配置', '选项'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '启动监控内核',
|
||||
description: '启动或停止 ThingHK 监控内核',
|
||||
keywords: ['内核', '启动', '停止', 'kernel', 'thinghk', '控制'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '自动启动监控内核',
|
||||
description: '应用启动时自动运行监控内核',
|
||||
keywords: ['自动启动', '开机', '内核', 'autoStart'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '监控项配置',
|
||||
description: '选择要监控的传感器分组与项目',
|
||||
keywords: ['监控项', '传感器', '分组', 'sensor', '配置'],
|
||||
tab: 'settings'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ const onConfirmOpenChange = (open: boolean) => {
|
||||
const activeTab = ref('overview')
|
||||
// 浮动标签切换器:注册到 TitleBar,滚动遮挡时自动显示
|
||||
const tabsStore = useModuleTabsStore()
|
||||
const tabsListRef = useModuleTabs(activeTab, [
|
||||
const tabsListRef = useModuleTabs('proxy', activeTab, [
|
||||
{ value: 'overview', label: '概览' },
|
||||
{ value: 'proxies', label: '节点' },
|
||||
{ value: 'profiles', label: '订阅' },
|
||||
|
||||
@@ -7,22 +7,110 @@ const searchItems: SearchIndexItem[] = [
|
||||
{
|
||||
title: '代理设置',
|
||||
description: '配置网络代理、端口与控制接口',
|
||||
keywords: ['代理', 'proxy', '网络', 'network', '端口', 'port']
|
||||
keywords: ['代理', 'proxy', '网络', 'network', '端口', 'port'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '订阅管理',
|
||||
description: '导入与更新 Clash/mihomo 订阅',
|
||||
keywords: ['订阅', 'subscription', 'profile', '导入']
|
||||
keywords: ['订阅', 'subscription', 'profile', '导入'],
|
||||
tab: 'profiles'
|
||||
},
|
||||
{
|
||||
title: '节点选择',
|
||||
description: '切换代理节点并测试延迟',
|
||||
keywords: ['节点', 'node', '延迟', 'delay', '测速']
|
||||
keywords: ['节点', 'node', '延迟', 'delay', '测速'],
|
||||
tab: 'proxies'
|
||||
},
|
||||
{
|
||||
title: '系统代理',
|
||||
description: '开启或关闭 Windows 系统代理',
|
||||
keywords: ['系统代理', 'system proxy', '开关', 'toggle']
|
||||
keywords: ['系统代理', 'system proxy', '开关', 'toggle'],
|
||||
tab: 'overview'
|
||||
},
|
||||
{
|
||||
title: '导入订阅',
|
||||
description: '填入订阅地址导入新配置',
|
||||
keywords: ['导入', '订阅地址', 'import', 'url', '添加订阅'],
|
||||
tab: 'profiles'
|
||||
},
|
||||
{
|
||||
title: '更新订阅',
|
||||
description: '手动更新订阅配置',
|
||||
keywords: ['更新订阅', 'update', '刷新订阅'],
|
||||
tab: 'profiles'
|
||||
},
|
||||
{
|
||||
title: '自动切换节点',
|
||||
description: '定时测速并自动切换到最优节点',
|
||||
keywords: ['自动切换', 'auto switch', '智能', '最优节点', '测速'],
|
||||
tab: 'overview'
|
||||
},
|
||||
{
|
||||
title: '代理组测速',
|
||||
description: '测试代理组所有节点的延迟',
|
||||
keywords: ['测速', '延迟', 'delay', 'test', 'ping'],
|
||||
tab: 'proxies'
|
||||
},
|
||||
{
|
||||
title: '运行模式',
|
||||
description: '规则 / 全局 / 直连模式切换',
|
||||
keywords: ['模式', 'mode', 'rule', 'global', 'direct', '规则', '全局', '直连'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '混合代理端口',
|
||||
description: '配置 mihomo 混合代理端口',
|
||||
keywords: ['端口', 'port', 'mixed', '混合'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '控制接口地址',
|
||||
description: '配置外部控制接口地址',
|
||||
keywords: ['控制接口', 'external', 'controller', 'api', '地址'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: 'API 密钥',
|
||||
description: '设置 mihomo 外部 API 密钥',
|
||||
keywords: ['密钥', 'secret', 'token', '鉴权', 'api'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '允许局域网连接',
|
||||
description: '允许其他设备通过本机代理上网',
|
||||
keywords: ['局域网', 'lan', 'allowLan', '共享'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '日志级别',
|
||||
description: '配置 mihomo 日志输出级别',
|
||||
keywords: ['日志', 'log', 'level', 'debug', 'info'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '启动时自动启动 mihomo',
|
||||
description: '应用启动时自动运行代理内核',
|
||||
keywords: ['自动启动', 'autoStart', '开机', '启动内核'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '启动时自动开启系统代理',
|
||||
description: 'mihomo 启动后自动设置 Windows 系统代理',
|
||||
keywords: ['系统代理', '自动', 'autoSystemProxy'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '更新内核',
|
||||
description: '检查并更新 mihomo 内核版本',
|
||||
keywords: ['内核', '更新', 'kernel', 'update', '升级'],
|
||||
tab: 'overview'
|
||||
},
|
||||
{
|
||||
title: '安装内核',
|
||||
description: '首次安装 mihomo 内核',
|
||||
keywords: ['内核', '安装', 'kernel', 'install', '下载'],
|
||||
tab: 'overview'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -8,6 +8,31 @@ const searchItems: SearchIndexItem[] = [
|
||||
title: '快速面板',
|
||||
description: '全局快捷键唤起命令面板',
|
||||
keywords: ['快速面板', '快速启动', '搜索', '命令', 'quickpanel', 'launcher', 'spotlight']
|
||||
},
|
||||
{
|
||||
title: '唤起快捷键',
|
||||
description: '配置全局快捷键打开快速面板',
|
||||
keywords: ['快捷键', '热键', 'shortcut', 'hotkey', '唤起', '打开']
|
||||
},
|
||||
{
|
||||
title: '唤起位置',
|
||||
description: '设置面板弹出位置(屏幕中央 / 鼠标位置)',
|
||||
keywords: ['位置', '弹出', '光标', 'position', 'popup']
|
||||
},
|
||||
{
|
||||
title: '默认搜索引擎',
|
||||
description: '设置快速面板网页搜索的搜索引擎',
|
||||
keywords: ['搜索引擎', '搜索', '引擎', 'search', 'engine', 'bing', 'google']
|
||||
},
|
||||
{
|
||||
title: '文件索引',
|
||||
description: '构建与管理本地文件搜索索引',
|
||||
keywords: ['文件', '索引', '搜索', 'index', '目录', 'file']
|
||||
},
|
||||
{
|
||||
title: '自定义命令',
|
||||
description: '添加自定义启动命令',
|
||||
keywords: ['自定义', '命令', 'command', '启动']
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip
|
||||
const store = useScreenshotStore()
|
||||
|
||||
const activeTab = ref('settings')
|
||||
const tabsListRef = useModuleTabs(activeTab, [
|
||||
const tabsListRef = useModuleTabs('screenshot', activeTab, [
|
||||
{ value: 'settings', label: '设置' },
|
||||
{ value: 'history', label: '历史' },
|
||||
])
|
||||
|
||||
@@ -5,7 +5,44 @@ const searchItems: SearchIndexItem[] = [
|
||||
{
|
||||
title: '截图工具',
|
||||
description: '捕获屏幕截图',
|
||||
keywords: ['截图', '屏幕', 'screenshot', 'capture']
|
||||
keywords: ['截图', '屏幕', 'screenshot', 'capture'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '截图历史',
|
||||
description: '查看和管理截图记录',
|
||||
keywords: ['历史', '记录', 'history', '截图'],
|
||||
tab: 'history'
|
||||
},
|
||||
{
|
||||
title: '截图快捷键',
|
||||
description: '配置全局截图快捷键',
|
||||
keywords: ['快捷键', '热键', 'shortcut', 'hotkey', '截图'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '贴图快捷键',
|
||||
description: '配置全局贴图快捷键',
|
||||
keywords: ['贴图', '快捷键', 'pin', 'shortcut'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '延时截图',
|
||||
description: '设置截图延时秒数',
|
||||
keywords: ['延时', '延迟', 'delay', '定时截图'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '自动保存到目录',
|
||||
description: '截图完成后自动保存到指定目录',
|
||||
keywords: ['自动保存', '目录', '路径', 'save', 'dir'],
|
||||
tab: 'settings'
|
||||
},
|
||||
{
|
||||
title: '历史保留数量',
|
||||
description: '设置截图历史记录保留上限',
|
||||
keywords: ['历史', '数量', '上限', 'history', 'limit'],
|
||||
tab: 'settings'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -1,27 +1,119 @@
|
||||
<script setup lang="ts">
|
||||
import { Monitor, Sun, Moon, Sparkles, Layers, LogOut, Package, GripVertical } from '@lucide/vue'
|
||||
import { Monitor, Sun, Moon, Sparkles, Layers, LogOut, Package, GripVertical, Info, RefreshCw, Download, Check, Loader2 } from '@lucide/vue'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Progress } from '@/components/ui/progress'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { useAppStore, type Theme, type EffectType, type ModuleInfo } from '@/stores/appStore'
|
||||
import { useSearchStore } from '@/stores/searchStore'
|
||||
import { useProcessStore } from '@/stores/processStore'
|
||||
import { getModuleIcon } from '@/modules/icons'
|
||||
import { commands, type UpdateCheckResult } from '@/lib/bindings'
|
||||
import { EVENTS } from '@/lib/constants'
|
||||
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { VueDraggable } from 'vue-draggable-plus'
|
||||
|
||||
const appStore = useAppStore()
|
||||
const searchStore = useSearchStore()
|
||||
const processStore = useProcessStore()
|
||||
|
||||
// ===== 关于 / 更新 =====
|
||||
|
||||
/** 更新进度事件载荷(与 Rust UpdateProgress 对应) */
|
||||
interface UpdateProgress {
|
||||
stage: string
|
||||
percent: number
|
||||
downloadedBytes: number
|
||||
totalBytes: number | null
|
||||
message: string
|
||||
}
|
||||
|
||||
/** 当前应用版本(启动时读取) */
|
||||
const currentVersion = ref('')
|
||||
/** 检查更新的结果 */
|
||||
const updateResult = ref<UpdateCheckResult | null>(null)
|
||||
const checking = ref(false)
|
||||
/** 应用本体更新中 */
|
||||
const appUpdating = ref(false)
|
||||
/** ThingHK 内核更新中 */
|
||||
const kernelUpdating = ref(false)
|
||||
const progress = ref<UpdateProgress | null>(null)
|
||||
const thinghkExists = ref(false)
|
||||
let progressUnlisten: UnlistenFn | null = null
|
||||
|
||||
const installTypeText = computed(() =>
|
||||
updateResult.value?.installType === 'installed' ? '安装版' : '便携版',
|
||||
)
|
||||
|
||||
const loadAppInfo = async () => {
|
||||
try {
|
||||
currentVersion.value = await commands.appVersion()
|
||||
} catch { /* 忽略:后端未就绪 */ }
|
||||
try {
|
||||
const info = await invoke('monitor_kernel_info') as { exists?: boolean }
|
||||
thinghkExists.value = info?.exists ?? false
|
||||
} catch { /* 忽略:内核未就绪 */ }
|
||||
}
|
||||
|
||||
/** 检查 Gitea 最新 release */
|
||||
const checkUpdate = async () => {
|
||||
if (checking.value || appUpdating.value) return
|
||||
checking.value = true
|
||||
try {
|
||||
updateResult.value = await commands.updateCheck()
|
||||
} catch (e) {
|
||||
console.error('[updater] 检查更新失败', e)
|
||||
} finally {
|
||||
checking.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 下载并应用应用更新(便携版替换 exe / 安装版静默安装),触发应用退出重启 */
|
||||
const installUpdate = async () => {
|
||||
if (appUpdating.value) return
|
||||
appUpdating.value = true
|
||||
try {
|
||||
await commands.updateInstall()
|
||||
} catch (e) {
|
||||
console.error('[updater] 应用更新失败', e)
|
||||
appUpdating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 更新 ThingHK 内核:后端先停止监控内核再覆盖文件 */
|
||||
const updateThinghkKernel = async () => {
|
||||
if (kernelUpdating.value) return
|
||||
kernelUpdating.value = true
|
||||
try {
|
||||
await commands.updateThinghk()
|
||||
await loadAppInfo()
|
||||
} catch (e) {
|
||||
console.error('[updater] ThingHK 更新失败', e)
|
||||
} finally {
|
||||
kernelUpdating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 系统真实深浅色偏好,来自 appStore(应用启动时初始化,仅通过 onThemeChanged 更新,
|
||||
// 不受 setTheme 污染),用于"跟随系统"卡片色块。
|
||||
const systemDark = computed(() => appStore.systemDark)
|
||||
|
||||
onMounted(() => {
|
||||
loadAppInfo()
|
||||
// 监听更新进度事件(应用更新与 ThingHK 内核更新共用)
|
||||
listen<UpdateProgress>(EVENTS.updateProgress, (e) => {
|
||||
progress.value = e.payload
|
||||
if (e.payload.stage === 'done') {
|
||||
kernelUpdating.value = false
|
||||
progress.value = null
|
||||
}
|
||||
}).then((fn) => {
|
||||
progressUnlisten = fn
|
||||
})
|
||||
searchStore.registerAction('settings', 0, () => appStore.setTheme('light'))
|
||||
searchStore.registerAction('settings', 1, () => appStore.setTheme('dark'))
|
||||
searchStore.registerAction('settings', 2, () => appStore.setTheme('system'))
|
||||
@@ -29,10 +121,21 @@ onMounted(() => {
|
||||
searchStore.registerAction('settings', 4, () => appStore.setEffect('mica'))
|
||||
searchStore.registerAction('settings', 5, () => appStore.setEffect('acrylic'))
|
||||
searchStore.registerAction('settings', 6, () => appStore.toggleAutoStart())
|
||||
// 新增设置项(模块管理/关于/退出):仅定位滚动到对应卡片
|
||||
searchStore.registerAction('settings', 7, () => scrollToCard('settings-card-modules'))
|
||||
searchStore.registerAction('settings', 8, () => scrollToCard('settings-card-about'))
|
||||
searchStore.registerAction('settings', 9, () => scrollToCard('settings-card-about'))
|
||||
searchStore.registerAction('settings', 10, () => scrollToCard('settings-card-about'))
|
||||
searchStore.registerAction('settings', 11, () => scrollToCard('settings-card-quit'))
|
||||
// 主动刷新所有进程状态,确保内核 badge 显示当前真实状态(而非过期缓存)
|
||||
processStore.refreshAll().catch(() => { /* 忽略:后端可能未就绪 */ })
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
progressUnlisten?.()
|
||||
progressUnlisten = null
|
||||
})
|
||||
|
||||
const themes: Array<{ id: Theme; name: string; color: string; icon: typeof Sun }> = [
|
||||
{ id: 'light', name: '浅色模式', color: '#f8fafc', icon: Sun },
|
||||
{ id: 'dark', name: '深色模式', color: '#1e293b', icon: Moon },
|
||||
@@ -82,6 +185,25 @@ const quitApp = async () => {
|
||||
await invoke('quit_app')
|
||||
}
|
||||
|
||||
/** 滚动到指定卡片(搜索导航定位用)。
|
||||
* 模块为异步加载,若卡片尚未渲染则短暂重试,直到模块挂载完成。 */
|
||||
const scrollToCard = (id: string) => {
|
||||
const tryScroll = (): boolean => {
|
||||
const el = document.getElementById(id)
|
||||
if (!el) return false
|
||||
el.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
return true
|
||||
}
|
||||
if (tryScroll()) return
|
||||
let attempts = 0
|
||||
const timer = window.setInterval(() => {
|
||||
attempts++
|
||||
if (tryScroll() || attempts >= 20) {
|
||||
window.clearInterval(timer)
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
|
||||
/** 判断模块开关是否处于处理中状态 */
|
||||
const isModuleToggling = (moduleId: string): boolean => {
|
||||
return appStore.togglingModules.has(moduleId)
|
||||
@@ -243,7 +365,7 @@ const onDragEnd = () => {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<Card id="settings-card-modules">
|
||||
<CardHeader>
|
||||
<CardTitle class="flex items-center gap-2">
|
||||
<Package class="size-5 text-primary" />
|
||||
@@ -313,7 +435,104 @@ const onDragEnd = () => {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<Card id="settings-card-about">
|
||||
<CardHeader>
|
||||
<CardTitle class="flex items-center gap-2">
|
||||
<Info class="size-5 text-primary" />
|
||||
关于
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="space-y-1">
|
||||
<!-- 应用版本 + 检查更新 -->
|
||||
<div class="flex items-center justify-between py-2">
|
||||
<div class="space-y-1">
|
||||
<Label class="text-base font-medium">应用版本</Label>
|
||||
<p class="text-sm text-muted-foreground">
|
||||
Thing v{{ currentVersion || '…' }}
|
||||
<span v-if="updateResult" class="ml-1 text-xs px-1.5 py-0.5 rounded-full bg-muted">
|
||||
{{ installTypeText }}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
:disabled="checking || appUpdating"
|
||||
@click="checkUpdate"
|
||||
>
|
||||
<RefreshCw v-if="!checking" class="size-3.5 mr-1.5" />
|
||||
<Loader2 v-else class="size-3.5 mr-1.5 animate-spin" />
|
||||
{{ checking ? '检查中...' : '检查更新' }}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- 更新结果 -->
|
||||
<div v-if="updateResult" class="rounded-lg border border-border/50 p-3 space-y-2">
|
||||
<div v-if="updateResult.hasUpdate" class="space-y-2">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm font-medium">
|
||||
发现新版本 v{{ updateResult.latestVersion }}
|
||||
</span>
|
||||
<span class="text-xs text-muted-foreground">当前 v{{ updateResult.currentVersion }}</span>
|
||||
</div>
|
||||
<p
|
||||
v-if="updateResult.releaseBody"
|
||||
class="text-xs text-muted-foreground whitespace-pre-wrap max-h-20 overflow-y-auto"
|
||||
>
|
||||
{{ updateResult.releaseBody }}
|
||||
</p>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button size="sm" :disabled="appUpdating" @click="installUpdate">
|
||||
<Download class="size-3.5 mr-1.5" />
|
||||
{{ appUpdating ? '更新中...' : '下载并更新' }}
|
||||
</Button>
|
||||
<span class="text-xs text-muted-foreground">
|
||||
{{ installTypeText === '安装版' ? '将静默安装新版并重启' : '将替换程序文件并重启' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="flex items-center gap-1.5 text-sm text-muted-foreground">
|
||||
<Check class="size-4 text-green-500" />
|
||||
已是最新版本
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 应用更新进度 -->
|
||||
<div v-if="appUpdating && progress" class="space-y-1.5 py-1">
|
||||
<div class="flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span>{{ progress.message }}</span>
|
||||
<span class="font-mono">{{ progress.percent }}%</span>
|
||||
</div>
|
||||
<Progress :model-value="progress.percent" />
|
||||
</div>
|
||||
|
||||
<!-- ThingHK 内核 -->
|
||||
<div class="flex items-center justify-between py-2 border-t border-border/50">
|
||||
<div class="space-y-1">
|
||||
<Label class="text-base font-medium">ThingHK 内核</Label>
|
||||
<p class="text-sm text-muted-foreground">
|
||||
{{ thinghkExists ? '已安装' : '未安装' }} · 更新前请先停用监控模块
|
||||
</p>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" :disabled="kernelUpdating" @click="updateThinghkKernel">
|
||||
<Loader2 v-if="kernelUpdating && !progress" class="size-3.5 mr-1.5 animate-spin" />
|
||||
<Package v-else class="size-3.5 mr-1.5" />
|
||||
{{ kernelUpdating ? '更新中...' : '更新内核' }}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- ThingHK 更新进度 -->
|
||||
<div v-if="kernelUpdating && progress" class="space-y-1.5 py-1">
|
||||
<div class="flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span>{{ progress.message }}</span>
|
||||
<span class="font-mono">{{ progress.percent }}%</span>
|
||||
</div>
|
||||
<Progress :model-value="progress.percent" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card id="settings-card-quit">
|
||||
<CardHeader>
|
||||
<CardTitle class="flex items-center gap-2">
|
||||
<LogOut class="size-5 text-destructive" />
|
||||
|
||||
@@ -37,6 +37,31 @@ const searchItems: SearchIndexItem[] = [
|
||||
title: '开机自启',
|
||||
description: '启动 Windows 时自动运行应用',
|
||||
keywords: ['开机', '自启', '自动', 'auto', 'start']
|
||||
},
|
||||
{
|
||||
title: '模块管理',
|
||||
description: '启用/禁用模块与拖拽排序',
|
||||
keywords: ['模块', '管理', '排序', '禁用', '启用', 'module']
|
||||
},
|
||||
{
|
||||
title: '检查更新',
|
||||
description: '检查并下载应用新版本',
|
||||
keywords: ['更新', '版本', '升级', 'update', 'check', 'release']
|
||||
},
|
||||
{
|
||||
title: '应用版本',
|
||||
description: '查看当前应用版本与安装方式',
|
||||
keywords: ['版本', 'version', 'about', '关于']
|
||||
},
|
||||
{
|
||||
title: 'ThingHK 内核',
|
||||
description: '查看监控内核安装状态并更新',
|
||||
keywords: ['内核', 'thinghk', 'kernel', '监控', '更新']
|
||||
},
|
||||
{
|
||||
title: '退出程序',
|
||||
description: '彻底退出 Thing 应用',
|
||||
keywords: ['退出', '关闭', 'quit', 'exit', '结束']
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -247,7 +247,8 @@ export const useAppStore = defineStore('app', () => {
|
||||
moduleId,
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
keywords: item.keywords
|
||||
keywords: item.keywords,
|
||||
tab: item.tab
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -28,6 +28,27 @@ export const useModuleTabsStore = defineStore('moduleTabs', () => {
|
||||
/** 是否显示浮动切换器(TabsList 滚出可视区时为 true) */
|
||||
const floatingVisible = ref<boolean>(false)
|
||||
|
||||
/** 待跳转 tab(搜索导航设置):{ moduleId, tab },模块挂载/已挂载时消费 */
|
||||
const pendingTab = ref<{ moduleId: string; tab: string } | null>(null)
|
||||
|
||||
/** 设置待跳转 tab(搜索结果点击时调用) */
|
||||
const setPendingTab = (moduleId: string, tab: string) => {
|
||||
pendingTab.value = { moduleId, tab }
|
||||
}
|
||||
|
||||
/**
|
||||
* 消费指定模块的待跳转 tab(返回 tab 值并清除)。
|
||||
* 仅在 moduleId 匹配时消费,避免误切当前已挂载模块的 tab。
|
||||
*/
|
||||
const consumePendingTab = (moduleId: string): string | null => {
|
||||
if (pendingTab.value && pendingTab.value.moduleId === moduleId) {
|
||||
const tab = pendingTab.value.tab
|
||||
pendingTab.value = null
|
||||
return tab
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** 当前模块注册的保存处理函数(null 表示无保存按钮,如自动保存模块) */
|
||||
const saveHandler = ref<(() => unknown) | null>(null)
|
||||
/** 保存中状态(驱动按钮 disabled + loading 图标) */
|
||||
@@ -93,6 +114,7 @@ export const useModuleTabsStore = defineStore('moduleTabs', () => {
|
||||
tabs,
|
||||
activeTab,
|
||||
floatingVisible,
|
||||
pendingTab,
|
||||
saveHandler,
|
||||
saving,
|
||||
saveVisible,
|
||||
@@ -100,6 +122,8 @@ export const useModuleTabsStore = defineStore('moduleTabs', () => {
|
||||
unregisterTabs,
|
||||
setFloatingVisible,
|
||||
setActiveTab,
|
||||
setPendingTab,
|
||||
consumePendingTab,
|
||||
registerSave,
|
||||
runSave
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ export interface SearchIndexItem {
|
||||
title: string
|
||||
description?: string
|
||||
keywords: string[]
|
||||
/** 跳转目标:模块内部 tab(如 proxy 的 'settings'),无 tab 则只切换模块 */
|
||||
tab?: string
|
||||
}
|
||||
|
||||
export interface SearchIndexConfig {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { moduleRegistry } from '@/modules/registry'
|
||||
import { getTextForms, bestScore } from '@/modules/quickpanel/engine'
|
||||
|
||||
export interface SearchItem {
|
||||
id: string
|
||||
@@ -8,6 +9,8 @@ export interface SearchItem {
|
||||
title: string
|
||||
description?: string
|
||||
keywords: string[]
|
||||
/** 跳转目标:模块内部 tab(无则只切换模块) */
|
||||
tab?: string
|
||||
action?: () => void
|
||||
}
|
||||
|
||||
@@ -29,7 +32,8 @@ export const useSearchStore = defineStore('search', () => {
|
||||
moduleId,
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
keywords: item.keywords
|
||||
keywords: item.keywords,
|
||||
tab: item.tab
|
||||
}
|
||||
if (!items.value.find(i => i.id === searchItem.id)) {
|
||||
items.value.push(searchItem)
|
||||
@@ -76,14 +80,21 @@ export const useSearchStore = defineStore('search', () => {
|
||||
|
||||
const search = (query: string) => {
|
||||
if (!query.trim()) return []
|
||||
const lowerQuery = query.toLowerCase()
|
||||
return items.value.filter(item => {
|
||||
const titleMatch = item.title.toLowerCase().includes(lowerQuery)
|
||||
const descMatch = item.description ? item.description.toLowerCase().includes(lowerQuery) : false
|
||||
const keywordMatch = item.keywords.some(k => k.toLowerCase().includes(lowerQuery))
|
||||
const moduleIdMatch = item.moduleId.toLowerCase().includes(lowerQuery)
|
||||
return titleMatch || descMatch || keywordMatch || moduleIdMatch
|
||||
// 复用快速面板匹配引擎:标题/描述/关键词/模块名 多形态模糊匹配(支持拼音、子序列)
|
||||
const scored = items.value
|
||||
.map(item => {
|
||||
let score = Math.max(
|
||||
bestScore(query, getTextForms(item.title)),
|
||||
bestScore(query, getTextForms(item.description ?? '')),
|
||||
bestScore(query, getTextForms(item.keywords.join(' ')))
|
||||
)
|
||||
const moduleName = moduleRegistry.getConfig(item.moduleId)?.name ?? item.moduleId
|
||||
score = Math.max(score, bestScore(query, getTextForms(moduleName)) * 0.9)
|
||||
return { item, score }
|
||||
})
|
||||
.filter(e => e.score > 0)
|
||||
.sort((a, b) => b.score - a.score)
|
||||
return scored.map(e => e.item)
|
||||
}
|
||||
|
||||
const getItemsByModule = (moduleId: string) => {
|
||||
|
||||
@@ -161,6 +161,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* 桌面应用体验:默认禁止文本选中(按钮/下拉框/标题等控件文字不可拖动选择),
|
||||
输入框、文本域、可编辑区域仍允许选择/复制 */
|
||||
html, body, #app {
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
input, textarea, [contenteditable='true'] {
|
||||
user-select: text;
|
||||
-webkit-user-select: text;
|
||||
}
|
||||
|
||||
#app {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
|
||||
Reference in New Issue
Block a user