Skip to content

Commit 1b47e14

Browse files
committed
feat: mac自动更新方式修改
1 parent 90627b5 commit 1b47e14

6 files changed

Lines changed: 31 additions & 42 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
mv Oadin.app pkgroot/Oadin/Oadin.app
7777
chmod +x installer/mac/preinstall
7878
chmod +x installer/mac/postinstall
79-
chmod +x installer/mac/uninstall.sh
79+
chmod +x installer/mac/uninstall
8080
# 添加文件大小检查
8181
echo "=== Mac 二进制文件详细信息 ==="
8282
# echo "二进制文件大小: $(du -h pkgroot/Oadin/oadin | cut -f1)"

installer/mac/create-app.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
exec > /tmp/oadin_createapp.log 2>&1
32
set -e
43

54
APP_NAME="Oadin"
@@ -81,7 +80,7 @@ cat > "Oadin.app/Contents/Info.plist" << EOF
8180
<key>LSMinimumSystemVersion</key>
8281
<string>11.0</string>
8382
<key>LSUIElement</key>
84-
<false/>
83+
<true/>
8584
<key>NSHighResolutionCapable</key>
8685
<true/>
8786
<key>NSHumanReadableCopyright</key>

installer/mac/postinstall

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ if [ "$REAL_USER" != "root" ] && [ -n "$REAL_USER" ]; then
4646
source ~/.bashrc
4747
fi
4848
export HOME=\"$USER_HOME\"
49-
# 必须用 Finder 双击 .app 或 open Oadin.app 启动,不能用终端 ./Oadin.app/Contents/MacOS/oadin-app 直接运行,否则 macOS 依然认为你是“无界面进程”。
50-
# \"${MACOS_DIR}/oadin-app\" &
49+
\"${MACOS_DIR}/oadin-app\" &
5150
"
52-
open "/Applications/Oadin.app" &
5351
echo "Oadin installation completed successfully"
5452
else
5553
echo "Warning: Cannot determine real user, skipping auto-launch"

installer/mac/preinstall

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,8 @@ if [ -d "$APP_PATH" ]; then
2626
fi
2727
sleep 2
2828

29-
# pkill -f "oadin" 2>/dev/null || true
30-
# pkill -f "Oadin AI Service Manager" 2>/dev/null || true
31-
# 支持覆盖更新
32-
MY_PID=$$
33-
MY_PARENT_PID=$(ps -o ppid= -p $$ | tr -d ' ')
34-
for pid in $(pgrep -f "Oadin AI Service Manager"); do
35-
if [ "$pid" != "$MY_PID" ] && [ "$pid" != "$MY_PARENT_PID" ]; then
36-
kill -9 "$pid" 2>/dev/null || true
37-
fi
38-
done
29+
pkill -f "oadin" 2>/dev/null || true
30+
pkill -f "Oadin AI Service Manager" 2>/dev/null || true
3931

4032
sleep 2
4133

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
exec > /tmp/oadin_uninstall.log 2>&1
23
set -e
34

45
APP_BUNDLE="/Applications/Oadin.app"

tray/updater.go

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -399,34 +399,33 @@ func (p *PKGInstaller) Install() error {
399399
}
400400

401401
func (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

432431
func (p *PKGInstaller) VerifyInstallation() error {

0 commit comments

Comments
 (0)