mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-08-18 12:07:02 +08:00
v0.3.8
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cursor/internal/appdata"
|
||||
serverconfig "cursor/internal/backend/server/config"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
// UserConfig 定义了当前模块中的 UserConfig 类型。
|
||||
type UserConfig = serverconfig.Config
|
||||
|
||||
// LoadUserConfig 用于处理与 LoadUserConfig 相关的逻辑。
|
||||
func (s *ProxyService) LoadUserConfig() (UserConfig, error) {
|
||||
if s == nil {
|
||||
return serverconfig.DefaultConfig(), nil
|
||||
}
|
||||
app := application.Get()
|
||||
ctx := context.Background()
|
||||
if app != nil {
|
||||
ctx = app.Context()
|
||||
}
|
||||
if s.backendHost != nil {
|
||||
return s.backendHost.LoadConfig(ctx)
|
||||
}
|
||||
if s.store == nil {
|
||||
return serverconfig.DefaultConfig(), nil
|
||||
}
|
||||
return s.store.Load(ctx)
|
||||
}
|
||||
|
||||
// SaveUserConfig 用于处理与 SaveUserConfig 相关的逻辑。
|
||||
func (s *ProxyService) SaveUserConfig(cfg UserConfig) error {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
app := application.Get()
|
||||
ctx := context.Background()
|
||||
if app != nil {
|
||||
ctx = app.Context()
|
||||
}
|
||||
var (
|
||||
normalized UserConfig
|
||||
err error
|
||||
)
|
||||
if s.backendHost != nil {
|
||||
normalized, err = s.backendHost.SaveConfig(ctx, cfg)
|
||||
} else if s.store != nil {
|
||||
normalized, err = s.store.Save(ctx, cfg)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.emitUserConfigChanged(normalized)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ProxyService) emitUserConfigChanged(cfg UserConfig) {
|
||||
app := application.Get()
|
||||
if app == nil {
|
||||
return
|
||||
}
|
||||
app.Event.Emit("user-config:changed", cfg)
|
||||
}
|
||||
|
||||
// resolveUserConfigPath 用于处理与 resolveUserConfigPath 相关的逻辑。
|
||||
func resolveUserConfigPath() string {
|
||||
return appdata.ConfigFilePath()
|
||||
}
|
||||
|
||||
// resolveLogsRootPath 用于处理与 resolveLogsRootPath 相关的逻辑。
|
||||
func resolveLogsRootPath() string {
|
||||
return appdata.LogsRootPath()
|
||||
}
|
||||
|
||||
// ResolveLogsRootPath 用于处理与 ResolveLogsRootPath 相关的逻辑。
|
||||
func ResolveLogsRootPath() string {
|
||||
return resolveLogsRootPath()
|
||||
}
|
||||
|
||||
// ResolveSettingsRootPath 用于处理与 ResolveSettingsRootPath 相关的逻辑。
|
||||
func ResolveSettingsRootPath() string {
|
||||
return appdata.RootDir()
|
||||
}
|
||||
Reference in New Issue
Block a user