@@ -3,6 +3,10 @@ use serde::{Deserialize, Serialize};
33use std:: time:: SystemTime ;
44use tauri:: { AppHandle , Emitter , command} ;
55
6+ mod update_linux;
7+ mod update_mac;
8+ mod update_windows;
9+
610#[ derive( Debug , Clone , Serialize , Deserialize ) ]
711pub struct UpdateInfo {
812 pub version : String ,
@@ -118,14 +122,21 @@ async fn get_latest_release(
118122// 查找平台对应的文件
119123fn get_platform_asset ( assets : & [ GitHubAsset ] ) -> Option < & GitHubAsset > {
120124 let os = std:: env:: consts:: OS ;
121- info ! ( "检查更新 -> 当前平台: {}" , os) ;
125+ let arch = std:: env:: consts:: ARCH ;
126+ info ! ( "检查更新 -> 当前平台: {} {}" , os, arch) ;
122127
123128 for asset in assets {
124129 let name = asset. name . to_lowercase ( ) ;
125130
126131 let matches = match os {
127- "windows" => name. contains ( "windows" ) || name. contains ( "win" ) || name. ends_with ( ".exe" ) ,
128- "macos" => name. contains ( "macos" ) || name. contains ( "darwin" ) || name. ends_with ( ".dmg" ) ,
132+ "windows" => {
133+ if arch == "x86_64" {
134+ name. contains ( "x64" ) && ( name. ends_with ( ".exe" ) || name. ends_with ( ".msi" ) )
135+ } else {
136+ name. contains ( "windows" ) || name. ends_with ( ".exe" ) || name. ends_with ( ".msi" )
137+ }
138+ }
139+ "macos" => name. contains ( "universal" ) && name. ends_with ( ".dmg" ) ,
129140 "linux" => name. contains ( "linux" ) || name. ends_with ( ".appimage" ) ,
130141 _ => false ,
131142 } ;
@@ -136,7 +147,6 @@ fn get_platform_asset(assets: &[GitHubAsset]) -> Option<&GitHubAsset> {
136147 }
137148 }
138149
139- // 如果没找到匹配的,返回第一个
140150 assets. first ( )
141151}
142152
@@ -179,7 +189,22 @@ async fn do_update(
179189 let temp_dir = std:: env:: temp_dir ( ) . join ( "codeforge_update" ) ;
180190 std:: fs:: create_dir_all ( & temp_dir) ?;
181191
182- let file_name = format ! ( "update_{}.exe" , update_info. version) ;
192+ // 根据平台确定文件扩展名
193+ let os = std:: env:: consts:: OS ;
194+ let file_extension = match os {
195+ "windows" => {
196+ if update_info. url . contains ( ".msi" ) {
197+ "msi"
198+ } else {
199+ "exe"
200+ }
201+ }
202+ "macos" => "dmg" ,
203+ "linux" => "appimage" ,
204+ _ => "bin" ,
205+ } ;
206+
207+ let file_name = format ! ( "update_{}.{}" , update_info. version, file_extension) ;
183208 let download_path = temp_dir. join ( & file_name) ;
184209
185210 info ! ( "检查更新 -> 下载更新文件: {}" , update_info. url) ;
@@ -257,12 +282,16 @@ async fn do_update(
257282 Ok ( ( ) )
258283}
259284
260- // 安装更新
285+ // 安装更新函数
261286async fn do_install (
262287 update_path : & std:: path:: Path ,
263288) -> Result < ( ) , Box < dyn std:: error:: Error + Send + Sync > > {
264- let current_exe = std:: env:: current_exe ( ) ?;
265- std:: fs:: copy ( update_path, & current_exe) ?;
289+ let os = std:: env:: consts:: OS ;
266290
267- Ok ( ( ) )
291+ match os {
292+ "windows" => update_windows:: install ( update_path) . await ,
293+ "macos" => update_mac:: install ( update_path) . await ,
294+ "linux" => update_linux:: install ( update_path) . await ,
295+ _ => Err ( "不支持的操作系统" . into ( ) ) ,
296+ }
268297}
0 commit comments