优化win版本交互
This commit is contained in:
Binary file not shown.
@@ -1041,13 +1041,38 @@ func GenerateAndWriteConfig(opts ConfigOptions) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("配置文件绝对路径: %s\n", configFile)
|
|
||||||
fmt.Printf("Gateway Token: %s\n", token)
|
|
||||||
fmt.Println("请妥善保存此 Token,用于远程连接 Gateway。")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetConfigPath 获取配置文件路径
|
||||||
|
func GetConfigPath() (string, error) {
|
||||||
|
userHome, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return filepath.Join(userHome, ".openclaw", "openclaw.json"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGatewayToken 获取 Gateway Token
|
||||||
|
func GetGatewayToken() (string, error) {
|
||||||
|
configPath, err := GetConfigPath()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
data, err := os.ReadFile(configPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
var config OpenclawConfig
|
||||||
|
if err := json.Unmarshal(data, &config); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if config.Gateway.Auth != nil {
|
||||||
|
return config.Gateway.Auth.Token, nil
|
||||||
|
}
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
// StartGateway 启动网关
|
// StartGateway 启动网关
|
||||||
func StartGateway() error {
|
func StartGateway() error {
|
||||||
cmdName, err := GetOpenclawPath()
|
cmdName, err := GetOpenclawPath()
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package ui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -80,6 +78,9 @@ type Model struct {
|
|||||||
gatewayOk bool
|
gatewayOk bool
|
||||||
checkDone bool
|
checkDone bool
|
||||||
|
|
||||||
|
configPath string
|
||||||
|
gatewayToken string
|
||||||
|
|
||||||
envRefreshActive bool
|
envRefreshActive bool
|
||||||
envRefreshAttempt int
|
envRefreshAttempt int
|
||||||
envRefreshMax int
|
envRefreshMax int
|
||||||
@@ -95,6 +96,8 @@ type checkMsg struct {
|
|||||||
gitVer string
|
gitVer string
|
||||||
gitOk bool
|
gitOk bool
|
||||||
gatewayRunning bool
|
gatewayRunning bool
|
||||||
|
configPath string
|
||||||
|
gatewayToken string
|
||||||
}
|
}
|
||||||
|
|
||||||
type actionResultMsg struct {
|
type actionResultMsg struct {
|
||||||
@@ -170,6 +173,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.gitVer = msg.gitVer
|
m.gitVer = msg.gitVer
|
||||||
m.gitOk = msg.gitOk
|
m.gitOk = msg.gitOk
|
||||||
m.gatewayOk = msg.gatewayRunning
|
m.gatewayOk = msg.gatewayRunning
|
||||||
|
m.configPath = msg.configPath
|
||||||
|
m.gatewayToken = msg.gatewayToken
|
||||||
m.checkDone = true
|
m.checkDone = true
|
||||||
if m.envRefreshActive {
|
if m.envRefreshActive {
|
||||||
expect := m.envRefreshExpectInstalled
|
expect := m.envRefreshExpectInstalled
|
||||||
@@ -471,13 +476,26 @@ func (m Model) renderDashboard() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
statusPanel := style.PanelStyle.Render(lipgloss.JoinVertical(lipgloss.Left,
|
statusRows := []string{
|
||||||
style.SubHeaderStyle.Render("系统状态"),
|
style.SubHeaderStyle.Render("系统状态"),
|
||||||
fmt.Sprintf("Node.js 环境: %s", nodeStatus),
|
fmt.Sprintf("Node.js 环境: %s", nodeStatus),
|
||||||
fmt.Sprintf("Git 环境: %s", gitStatus),
|
fmt.Sprintf("Git 环境: %s", gitStatus),
|
||||||
fmt.Sprintf("OpenClaw 核心: %s", openclawStatus),
|
fmt.Sprintf("OpenClaw 核心: %s", openclawStatus),
|
||||||
fmt.Sprintf("网关进程: %s", gwStatus),
|
fmt.Sprintf("网关进程: %s", gwStatus),
|
||||||
))
|
}
|
||||||
|
|
||||||
|
if m.openclawOk && m.configPath != "" {
|
||||||
|
statusRows = append(statusRows, "")
|
||||||
|
statusRows = append(statusRows, fmt.Sprintf("配置文件: %s", m.configPath))
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.gatewayOk && m.gatewayToken != "" {
|
||||||
|
statusRows = append(statusRows, "")
|
||||||
|
url := fmt.Sprintf("http://127.0.0.1:18789/?token=%s", m.gatewayToken)
|
||||||
|
statusRows = append(statusRows, fmt.Sprintf("访问地址: %s", style.SuccessStyle.Render(url)))
|
||||||
|
}
|
||||||
|
|
||||||
|
statusPanel := style.PanelStyle.Render(lipgloss.JoinVertical(lipgloss.Left, statusRows...))
|
||||||
|
|
||||||
// 3. 菜单
|
// 3. 菜单
|
||||||
menuItems := []struct{ title, desc string }{
|
menuItems := []struct{ title, desc string }{
|
||||||
@@ -645,6 +663,10 @@ func checkEnvCmd() tea.Msg {
|
|||||||
openclawVer, openclawOk := sys.CheckOpenclaw()
|
openclawVer, openclawOk := sys.CheckOpenclaw()
|
||||||
gitVer, gitOk := sys.CheckGit()
|
gitVer, gitOk := sys.CheckGit()
|
||||||
gwRun := sys.IsGatewayRunning()
|
gwRun := sys.IsGatewayRunning()
|
||||||
|
|
||||||
|
cfgPath, _ := sys.GetConfigPath()
|
||||||
|
token, _ := sys.GetGatewayToken()
|
||||||
|
|
||||||
return checkMsg{
|
return checkMsg{
|
||||||
nodeVer: nodeVer,
|
nodeVer: nodeVer,
|
||||||
nodeOk: nodeOk,
|
nodeOk: nodeOk,
|
||||||
@@ -653,6 +675,8 @@ func checkEnvCmd() tea.Msg {
|
|||||||
gitVer: gitVer,
|
gitVer: gitVer,
|
||||||
gitOk: gitOk,
|
gitOk: gitOk,
|
||||||
gatewayRunning: gwRun,
|
gatewayRunning: gwRun,
|
||||||
|
configPath: cfgPath,
|
||||||
|
gatewayToken: token,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,9 +724,7 @@ func runSaveConfigCmd(opts sys.ConfigOptions) tea.Cmd {
|
|||||||
err := sys.GenerateAndWriteConfig(opts)
|
err := sys.GenerateAndWriteConfig(opts)
|
||||||
msg := ""
|
msg := ""
|
||||||
if err == nil {
|
if err == nil {
|
||||||
userHome, _ := os.UserHomeDir()
|
msg = "配置已保存!"
|
||||||
path := filepath.Join(userHome, ".openclaw", "openclaw.json")
|
|
||||||
msg = fmt.Sprintf("配置文件路径: %s", path)
|
|
||||||
}
|
}
|
||||||
return actionResultMsg{err: err, successMsg: msg}
|
return actionResultMsg{err: err, successMsg: msg}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user