Compare commits

..

3 Commits

Author SHA1 Message Date
Julian Freeman
5717b94c90 optimize 2026-03-30 22:00:00 -04:00
Julian Freeman
5048ef5e76 change icon to 32 2026-03-30 21:42:24 -04:00
Julian Freeman
11dd161b1c get icon 2026-03-30 21:25:22 -04:00
3 changed files with 131 additions and 21 deletions

View File

@@ -28,6 +28,7 @@ struct WingetPackage {
pub name: String,
pub installed_version: Option<String>,
pub available_versions: Option<Vec<String>>,
pub icon_url: Option<String>,
}
pub fn ensure_winget_dependencies(handle: &AppHandle) -> Result<(), String> {
@@ -133,15 +134,84 @@ pub fn list_updates(handle: &AppHandle) -> Vec<Software> {
let script = r#"
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$ErrorActionPreference = 'SilentlyContinue'
Add-Type -AssemblyName System.Drawing
Import-Module Microsoft.WinGet.Client -ErrorAction SilentlyContinue
$pkgs = Get-WinGetPackage -ErrorAction SilentlyContinue | Where-Object { $_.IsUpdateAvailable }
if ($pkgs) {
$pkgs | ForEach-Object {
$wshShell = New-Object -ComObject WScript.Shell
# 预加载开始菜单快捷方式
$startMenuPaths = @(
"$env:ProgramData\Microsoft\Windows\Start Menu\Programs",
"$env:AppData\Microsoft\Windows\Start Menu\Programs"
)
$lnkFiles = Get-ChildItem -Path $startMenuPaths -Filter "*.lnk" -Recurse -File
# 预加载注册表项
$registryPaths = @(
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
$regItems = Get-ItemProperty $registryPaths
$pkgs | ForEach-Object {
$p = $_
$iconUrl = $null
$foundPath = ""
# 策略 1: 寻找并解析开始菜单快捷方式 (去除箭头关键点)
$matchedLnk = $lnkFiles | Where-Object { $_.BaseName -eq $p.Name -or $p.Name -like "*$($_.BaseName)*" } | Select-Object -First 1
if ($matchedLnk) {
try {
# 解析快捷方式指向的真实目标
$target = $wshShell.CreateShortcut($matchedLnk.FullName).TargetPath
if ($target -and (Test-Path $target) -and $target.EndsWith(".exe")) {
$foundPath = $target
} else {
# 如果目标不可读或是 UWP 快捷方式,仍使用快捷方式文件提取
$foundPath = $matchedLnk.FullName
}
} catch {
$foundPath = $matchedLnk.FullName
}
}
# 策略 2: 注册表 DisplayIcon
if (-not $foundPath) {
$matchedReg = $regItems | Where-Object { $_.DisplayName -eq $p.Name -or $_.PSChildName -eq $p.Id } | Select-Object -First 1
if ($matchedReg.DisplayIcon) {
$foundPath = $matchedReg.DisplayIcon.Split(',')[0].Trim('"')
} elseif ($matchedReg.InstallLocation) {
$loc = $matchedReg.InstallLocation.Trim('"')
if (Test-Path $loc) {
$exe = Get-ChildItem -Path $loc -Filter "*.exe" -File | Select-Object -First 1
if ($exe) { $foundPath = $exe.FullName }
}
}
}
# 提取并转 Base64
if ($foundPath -and (Test-Path $foundPath)) {
try {
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($foundPath)
$bitmap = $icon.ToBitmap()
$ms = New-Object System.IO.MemoryStream
$bitmap.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
$base64 = [Convert]::ToBase64String($ms.ToArray())
$iconUrl = "data:image/png;base64,$base64"
$ms.Dispose(); $bitmap.Dispose(); $icon.Dispose()
} catch {}
}
[PSCustomObject]@{
Name = [string]$_.Name;
Id = [string]$_.Id;
InstalledVersion = [string]$_.InstalledVersion;
AvailableVersions = $_.AvailableVersions
Name = [string]$p.Name;
Id = [string]$p.Id;
InstalledVersion = [string]$p.InstalledVersion;
AvailableVersions = $p.AvailableVersions;
IconUrl = $iconUrl
}
} | ConvertTo-Json -Compress
} else {
@@ -203,7 +273,7 @@ fn map_package(p: WingetPackage) -> Software {
description: None,
version: p.installed_version,
available_version: p.available_versions.and_then(|v| v.first().cloned()),
icon_url: None,
icon_url: p.icon_url,
status: "idle".to_string(),
progress: 0.0,
}

View File

@@ -30,21 +30,30 @@
</div>
<div class="info">
<div class="title-row">
<h3 class="name">{{ software.name }}</h3>
<h3 class="name" :title="software.description">{{ software.name }}</h3>
<span class="id-badge">{{ software.id }}</span>
</div>
<p class="description" v-if="software.description">{{ software.description }}</p>
<div class="version-info">
<!-- 如果状态是已安装或者是在更新/全部列表中已经有版本号的软件 -->
<template v-if="software.status === 'installed' || (software.status === 'idle' && actionLabel === '更新') || (software.status === 'idle' && !actionLabel && software.version)">
<!-- 情况 1: 已安装软件 (包含待更新状态) -->
<template v-if="isInstalled">
<span class="version-tag">当前: {{ software.version || '--' }}</span>
</template>
<template v-else>
<span class="version-tag recommended">
推荐: {{ software.version || '最新版' }}
<!-- 仅在装机必备且当前版本低于推荐版本时显示 -->
<span
v-if="software.recommended_version && isVersionLower(software.version, software.recommended_version)"
class="version-tag recommended"
>
推荐: {{ software.recommended_version }}
</span>
</template>
<!-- 情况 2: 未安装软件 -->
<template v-else>
<span class="version-tag recommended">
推荐: {{ software.recommended_version || '最新版' }}
</span>
</template>
<!-- 情况 3: WinGet 检测到的仓库最新版本 -->
<span class="version-tag available" v-if="software.available_version">
最新: {{ software.available_version }}
</span>
@@ -127,6 +136,35 @@ const displayProgress = computed(() => {
return Math.round(props.software.progress * 100) + '%';
});
const isInstalled = computed(() => {
return props.software.status === 'installed' ||
(props.software.status === 'idle' && props.actionLabel === '更新') ||
(props.software.status === 'idle' && !props.actionLabel && props.software.installed_version);
});
const isVersionLower = (current: string | undefined | null, target: string | undefined | null) => {
if (!current || !target) return false;
if (current === target) return false;
// 简易的版本比对逻辑:按点分割比对数字
const v1 = current.split('.');
const v2 = target.split('.');
const len = Math.max(v1.length, v2.length);
for (let i = 0; i < len; i++) {
const n1 = parseInt(v1[i] || '0', 10);
const n2 = parseInt(v2[i] || '0', 10);
if (isNaN(n1) || isNaN(n2)) {
// 如果是非数字字符串比对,直接返回字符串比对结果
if (v1[i] !== v2[i]) return v1[i] < v2[i];
continue;
}
if (n1 < n2) return true;
if (n1 > n2) return false;
}
return false;
};
const placeholderColor = computed(() => {
const colors = ['#FF9500', '#FF3B30', '#34C759', '#007AFF', '#5856D6', '#AF52DE'];
let hash = 0;
@@ -211,9 +249,9 @@ const handleCardClick = () => {
}
.icon-container {
width: 48px;
height: 48px;
border-radius: 12px;
width: 32px;
height: 32px;
border-radius: 8px;
overflow: hidden;
flex-shrink: 0;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
@@ -232,7 +270,7 @@ const handleCardClick = () => {
align-items: center;
justify-content: center;
color: white;
font-size: 20px;
font-size: 14px;
font-weight: 700;
}

View File

@@ -39,10 +39,12 @@ export const useSoftwareStore = defineStore('software', {
let displayStatus = item.status;
let actionLabel = '安装';
let currentVersion = item.version; // 默认使用清单中的推荐版本
// 统一字段version 始终代表当前安装的版本recommended_version 代表清单推荐的版本
const currentVersion = installedInfo ? installedInfo.version : null;
const recommendedVersion = item.version;
if (isInstalled) {
currentVersion = installedInfo.version; // 如果已安装,显示本地真实版本
if (hasUpdate) {
actionLabel = '更新';
} else if (displayStatus === 'idle') {
@@ -54,7 +56,7 @@ export const useSoftwareStore = defineStore('software', {
return {
...item,
version: currentVersion,
recommended_version: item.version, // 额外保存一个原始推荐版本字段供前端判断
recommended_version: recommendedVersion,
status: displayStatus,
actionLabel
};