mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-10 00:33:28 +08:00
- 安装前获取维护锁并枚举同目录进程,仅检测到其他实例时触发关闭确认 - 改用 Windows 原生系统模态对话框并先收起下载进度窗口,避免确认提示被遮挡 - 单实例直接进入安装,取消确认或退出检查中止后恢复下载完成状态 - 多语言确认文案展示实际实例数量,补齐前后端与发布工作流回归测试
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
|
)
|
|
|
|
func otherWindowsUpdateProcessIDs(processes []windowsUpdateProcess) []uint32 {
|
|
result := make([]uint32, 0, len(processes))
|
|
for _, process := range processes {
|
|
result = append(result, process.PID)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func windowsUpdateCloseConfirmationRequired(goos string, confirmed bool, otherInstanceCount int) bool {
|
|
return strings.EqualFold(strings.TrimSpace(goos), "windows") && !confirmed && otherInstanceCount > 0
|
|
}
|
|
|
|
func showWindowsUpdateCloseConfirmation(ctx context.Context, title, message string) (bool, error) {
|
|
if ctx == nil {
|
|
return false, fmt.Errorf("application window is not ready")
|
|
}
|
|
response, err := wailsRuntime.MessageDialog(ctx, wailsRuntime.MessageDialogOptions{
|
|
Type: wailsRuntime.QuestionDialog,
|
|
Title: title,
|
|
Message: message,
|
|
Buttons: []string{"Yes", "No"},
|
|
DefaultButton: "No",
|
|
CancelButton: "No",
|
|
})
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return strings.EqualFold(strings.TrimSpace(response), "yes"), nil
|
|
}
|
|
|
|
func closeOtherWindowsUpdateInstancesForInstall(targetPaths []string, currentPID int) ([]uint32, error) {
|
|
instances, err := updateFindOtherWindowsInstances(targetPaths, currentPID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
pids := otherWindowsUpdateProcessIDs(instances)
|
|
if len(instances) == 0 {
|
|
return pids, nil
|
|
}
|
|
if err := updateCloseWindowsInstances(instances); err != nil {
|
|
return pids, err
|
|
}
|
|
remaining, err := updateFindOtherWindowsInstances(targetPaths, currentPID)
|
|
if err != nil {
|
|
return pids, err
|
|
}
|
|
if len(remaining) > 0 {
|
|
return pids, fmt.Errorf("GoNavi processes still running after close: %v", otherWindowsUpdateProcessIDs(remaining))
|
|
}
|
|
return pids, nil
|
|
}
|