feat: add cancellable settings path search
This commit is contained in:
+32
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user