@@ -399,34 +399,33 @@ func (p *PKGInstaller) Install() error {
399399}
400400
401401func (p * PKGInstaller ) installWithAppleScript () error {
402- slog .Info ("installing with AppleScript for elevated privileges" ,)
403- // 使用AppleScript请求管理员权限并执行安装
404- script := fmt .Sprintf (`
405- set pkgPath to "%s"
406- set installCommand to "installer -pkg " & quoted form of pkgPath & " -target /"
407- try
408- do shell script installCommand with administrator privileges
409- return "INSTALL_SUCCESS"
410- on error errMsg number errNum
411- return "INSTALL_FAILED: " & errMsg & " (错误码: " & errNum & ")"
412- end try
413- ` , p .pkgPath )
414-
415- cmd := exec .Command ("osascript" , "-e" , script )
416-
417- output , err := cmd .CombinedOutput ()
418- if err != nil {
419- slog .Error ("AppleScript execution failed:" , err )
420- return fmt .Errorf ("AppleScript excute failed: %v" , err )
421- }
402+ slog .Info ("installing with AppleScript for elevated privileges" )
422403
423- slog . Info ( "AppleScript output:" , "output" , string ( output ))
424- if ! strings . Contains ( string ( output ), "INSTALL_SUCCESS" ) {
425- return fmt . Errorf ( "installation failed via AppleScript: %s" , string ( output ))
426- }
404+ // 弹出提示框,询问用户是否打开安装包目录
405+ alertScript := fmt . Sprintf ( `
406+ display dialog "需要手动安装新版本。是否打开安装包所在目录?" buttons {"取消", "打开目录"} default button "打开目录"
407+ ` , p . pkgPath )
427408
428- slog .Info ("install successfully via AppleScript" )
429- return nil
409+ cmd := exec .Command ("osascript" , "-e" , alertScript )
410+ output , err := cmd .CombinedOutput ()
411+ if err != nil {
412+ slog .Error ("AppleScript alert failed:" , err )
413+ return fmt .Errorf ("AppleScript alert failed: %v" , err )
414+ }
415+
416+ if ! strings .Contains (string (output ), "打开目录" ) {
417+ return fmt .Errorf ("用户取消了安装" )
418+ }
419+
420+ // 打开安装包所在目录
421+ dir := filepath .Dir (p .pkgPath )
422+ openCmd := exec .Command ("open" , dir )
423+ if err := openCmd .Run (); err != nil {
424+ slog .Error ("打开目录失败:" , err )
425+ return fmt .Errorf ("打开目录失败: %v" , err )
426+ }
427+
428+ return fmt .Errorf ("请手动双击安装包进行安装" )
430429}
431430
432431func (p * PKGInstaller ) VerifyInstallation () error {
0 commit comments