This commit is contained in:
Julian Freeman
2026-03-14 16:18:11 -04:00
commit 375b6fdb11
46 changed files with 7988 additions and 0 deletions

7
src-tauri/.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
# Generated by Tauri
# will have schema files for capabilities auto-completion
/gen/schemas

5445
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

26
src-tauri/Cargo.toml Normal file
View File

@@ -0,0 +1,26 @@
[package]
name = "win-softmgr"
version = "0.1.0"
description = "A Windows Software Manager"
authors = ["Julian"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "win_softmgr_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1.50.0", features = ["full"] }

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="*"
name="WinSoftMgr"
type="win32"
/>
<description>Windows Software Manager</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 & 11 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
</application>
</compatibility>
<!-- 启用 DPI 意识和长路径支持 -->
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
</assembly>

6
src-tauri/build.rs Normal file
View File

@@ -0,0 +1,6 @@
fn main() {
let mut windows = tauri_build::WindowsAttributes::new();
windows = windows.app_manifest(include_str!("admin.exe.manifest"));
tauri_build::try_build(tauri_build::Attributes::new().windows_attributes(windows))
.expect("failed to run tauri-build");
}

View File

@@ -0,0 +1,12 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"opener:default",
"core:app:default",
"core:event:default"
]
}

BIN
src-tauri/icons/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
src-tauri/icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
src-tauri/icons/icon.icns Normal file

Binary file not shown.

BIN
src-tauri/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
src-tauri/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

132
src-tauri/src/lib.rs Normal file
View File

@@ -0,0 +1,132 @@
pub mod winget;
use std::fs;
use std::process::Command;
use std::os::windows::process::CommandExt;
use tokio::sync::mpsc;
use tauri::{AppHandle, Manager, State, Emitter};
use serde::Serialize;
use winget::{Software, list_all_software, list_updates};
struct AppState {
install_tx: mpsc::Sender<String>,
}
#[tauri::command]
fn get_essentials(app: AppHandle) -> Vec<Software> {
let app_data_dir = app.path().app_data_dir().unwrap_or_default();
if !app_data_dir.exists() {
let _ = fs::create_dir_all(&app_data_dir);
}
let file_path = app_data_dir.join("setup-essentials.json");
if !file_path.exists() {
let default_essentials = vec![
Software {
id: "Microsoft.PowerToys".to_string(),
name: "PowerToys".to_string(),
description: Some("Microsoft PowerToys 是一组实用程序,供高级用户调整和简化其 Windows 10 和 11 体验。".to_string()),
version: None,
available_version: None,
icon_url: Some("https://raw.githubusercontent.com/microsoft/PowerToys/master/doc/images/logo.png".to_string()),
status: "idle".to_string(),
progress: 0.0,
},
Software {
id: "Google.Chrome".to_string(),
name: "Google Chrome".to_string(),
description: Some("Google Chrome 是一款快速、安全且免费的浏览器。".to_string()),
version: None,
available_version: None,
icon_url: Some("https://www.google.com/chrome/static/images/chrome-logo.svg".to_string()),
status: "idle".to_string(),
progress: 0.0,
}
];
let _ = fs::write(&file_path, serde_json::to_string_pretty(&default_essentials).unwrap());
return default_essentials;
}
let content = fs::read_to_string(file_path).unwrap_or_else(|_| "[]".to_string());
serde_json::from_str(&content).unwrap_or_default()
}
#[tauri::command]
async fn get_all_software() -> Vec<Software> {
tokio::task::spawn_blocking(move || list_all_software()).await.unwrap_or_default()
}
#[tauri::command]
async fn get_updates() -> Vec<Software> {
tokio::task::spawn_blocking(move || list_updates()).await.unwrap_or_default()
}
#[tauri::command]
async fn install_software(id: String, state: State<'_, AppState>) -> Result<(), String> {
state.install_tx.send(id).await.map_err(|e| e.to_string())
}
#[derive(Clone, Serialize)]
struct InstallProgress {
id: String,
status: String,
progress: f32,
}
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.setup(move |app| {
let handle = app.handle().clone();
// 在 setup 闭包中初始化,此时运行时已就绪
let (tx, mut rx) = mpsc::channel::<String>(100);
// 托管状态
app.manage(AppState { install_tx: tx });
// 后台安装队列
tauri::async_runtime::spawn(async move {
while let Some(id) = rx.recv().await {
let _ = handle.emit("install-status", InstallProgress {
id: id.clone(),
status: "installing".to_string(),
progress: 0.5,
});
let id_for_cmd = id.clone();
let status_result = tokio::task::spawn_blocking(move || {
let output = Command::new("winget")
.args([
"install", "--id", &id_for_cmd, "-e", "--silent",
"--accept-package-agreements", "--accept-source-agreements",
"--disable-interactivity"
])
.creation_flags(0x08000000)
.output();
match output {
Ok(out) if out.status.success() => "success",
_ => "error",
}
}).await.unwrap_or("error");
let _ = handle.emit("install-status", InstallProgress {
id: id.clone(),
status: status_result.to_string(),
progress: 1.0,
});
}
});
Ok(())
})
.invoke_handler(tauri::generate_handler![
get_essentials,
get_all_software,
get_updates,
install_software
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

6
src-tauri/src/main.rs Normal file
View File

@@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
win_softmgr_lib::run();
}

91
src-tauri/src/winget.rs Normal file
View File

@@ -0,0 +1,91 @@
use serde::{Deserialize, Serialize};
use std::process::Command;
use std::os::windows::process::CommandExt;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Software {
pub id: String,
pub name: String,
pub description: Option<String>,
pub version: Option<String>,
pub available_version: Option<String>,
pub icon_url: Option<String>,
pub status: String, // "idle", "pending", "installing", "success", "error"
pub progress: f32,
}
pub fn list_all_software() -> Vec<Software> {
// winget list
let output = Command::new("winget")
.args(["list", "--accept-source-agreements"])
.creation_flags(0x08000000) // CREATE_NO_WINDOW
.output();
match output {
Ok(out) => parse_winget_output(String::from_utf8_lossy(&out.stdout).to_string()),
Err(_) => vec![],
}
}
pub fn list_updates() -> Vec<Software> {
// winget upgrade
let output = Command::new("winget")
.args(["upgrade", "--accept-source-agreements"])
.creation_flags(0x08000000)
.output();
match output {
Ok(out) => parse_winget_output(String::from_utf8_lossy(&out.stdout).to_string()),
Err(_) => vec![],
}
}
fn parse_winget_output(output: String) -> Vec<Software> {
let mut softwares = Vec::new();
let lines: Vec<&str> = output.lines().collect();
if lines.len() < 3 {
return softwares;
}
// 查找表头行以确定列偏移量
// 通常格式: Name Id Version Available Source
let header_idx = lines.iter().position(|l| l.contains("Id") && l.contains("Name")).unwrap_or(0);
let header = lines[header_idx];
let id_pos = header.find("Id").unwrap_or(0);
let version_pos = header.find("Version").unwrap_or(0);
let available_pos = header.find("Available").unwrap_or(header.len());
let source_pos = header.find("Source").unwrap_or(header.len());
for line in &lines[header_idx + 2..] {
if line.trim().is_empty() || line.starts_with('-') {
continue;
}
if line.len() < version_pos { continue; }
let name = line[..id_pos].trim().to_string();
let id = line[id_pos..version_pos].trim().to_string();
let version = line[version_pos..available_pos.min(line.len())].trim().to_string();
let available_version = if available_pos < line.len() {
Some(line[available_pos..source_pos.min(line.len())].trim().to_string())
} else {
None
};
softwares.push(Software {
id,
name,
description: None,
version: Some(version),
available_version,
icon_url: None,
status: "idle".to_string(),
progress: 0.0,
});
}
softwares
}

35
src-tauri/tauri.conf.json Normal file
View File

@@ -0,0 +1,35 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "win-softmgr",
"version": "0.1.0",
"identifier": "top.volan.win-softmgr",
"build": {
"beforeDevCommand": "pnpm dev",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "pnpm build",
"frontendDist": "../dist"
},
"app": {
"windows": [
{
"title": "Windows 软件管理",
"width": 1200,
"height": 800
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}