feat: add cancellable settings path search

This commit is contained in:
QiuSW
2026-07-22 15:57:02 +08:00
parent a3b766f276
commit 6f08c9c9d0
8 changed files with 384 additions and 75 deletions
+32 -1
View File
@@ -3,12 +3,16 @@ package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
"strings"
"chub/internal/domain"
"chub/internal/platform/browser"
"chub/internal/platform/config"
"chub/internal/platform/logging"
"chub/internal/ui"
@@ -95,9 +99,36 @@ func writeCLIError(out io.Writer, code, message string) {
func runWindow(logger *slog.Logger) {
window := new(app.Window)
window.Option(app.Title("Chub 浏览器管理"), app.Size(unit.Dp(1100), unit.Dp(720)))
window.Option(app.Title("Chub"), app.Size(unit.Dp(1100), unit.Dp(720)))
theme := material.NewTheme()
shell := ui.NewShell(theme)
discoverer := browser.NewDiscoverer()
shell.OnPathSearch(func(ctx context.Context, field ui.PathField, current string) (string, error) {
switch field {
case ui.PathChromeExecutable:
return discoverer.Resolve(ctx, domain.BrowserChrome, "")
case ui.PathEdgeExecutable:
return discoverer.Resolve(ctx, domain.BrowserEdge, "")
case ui.PathDefaultUserData, ui.PathLogDirectory:
if err := ctx.Err(); err != nil {
return "", err
}
path := strings.TrimSpace(current)
if path == "" {
return "", errors.New("请先输入要验证的目录,或使用选择按钮")
}
info, err := os.Stat(path)
if err != nil {
return "", err
}
if !info.IsDir() {
return "", errors.New("该路径不是目录")
}
return filepath.Clean(path), nil
default:
return "", errors.New("不支持的搜索字段")
}
}, window.Invalidate)
if path, err := config.DefaultPath(); err == nil {
if store, err := config.New(path); err == nil {
if saved, err := store.Load(); err == nil {