mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-30 15:19:59 +08:00
- 后端新增 JVMListResources 与 JVMGetValue 接口并补齐回归测试 - Sidebar 基于能力探测展示 JVM 模式节点并懒加载资源节点 - TabManager 接入 JVMOverview、JVMResourceBrowser 与模式徽标展示 - 补齐 JVM Tab 元数据与连接持久化 sanitize 逻辑 - 更新需求追踪文档并记录 Task 4 验证结果与残余风险
98 lines
2.8 KiB
Go
98 lines
2.8 KiB
Go
package app
|
|
|
|
import (
|
|
"GoNavi-Wails/internal/connection"
|
|
"GoNavi-Wails/internal/jvm"
|
|
)
|
|
|
|
var newJVMProvider = jvm.NewProvider
|
|
|
|
func resolveJVMProvider(cfg connection.ConnectionConfig) (connection.ConnectionConfig, jvm.Provider, error) {
|
|
normalized, err := jvm.NormalizeConnectionConfig(cfg)
|
|
if err != nil {
|
|
return connection.ConnectionConfig{}, nil, err
|
|
}
|
|
|
|
provider, err := newJVMProvider(normalized.JVM.PreferredMode)
|
|
if err != nil {
|
|
return connection.ConnectionConfig{}, nil, err
|
|
}
|
|
|
|
return normalized, provider, nil
|
|
}
|
|
|
|
func (a *App) TestJVMConnection(cfg connection.ConnectionConfig) connection.QueryResult {
|
|
normalized, provider, err := resolveJVMProvider(cfg)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
|
|
if err := provider.TestConnection(a.ctx, normalized); err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
|
|
return connection.QueryResult{Success: true, Message: "JVM 连接成功"}
|
|
}
|
|
|
|
func (a *App) JVMListResources(cfg connection.ConnectionConfig, parentPath string) connection.QueryResult {
|
|
normalized, provider, err := resolveJVMProvider(cfg)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
|
|
items, err := provider.ListResources(a.ctx, normalized, parentPath)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
|
|
return connection.QueryResult{Success: true, Data: items}
|
|
}
|
|
|
|
func (a *App) JVMGetValue(cfg connection.ConnectionConfig, resourcePath string) connection.QueryResult {
|
|
normalized, provider, err := resolveJVMProvider(cfg)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
|
|
value, err := provider.GetValue(a.ctx, normalized, resourcePath)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
|
|
return connection.QueryResult{Success: true, Data: value}
|
|
}
|
|
|
|
func (a *App) JVMProbeCapabilities(cfg connection.ConnectionConfig) connection.QueryResult {
|
|
normalized, err := jvm.NormalizeConnectionConfig(cfg)
|
|
if err != nil {
|
|
return connection.QueryResult{Success: false, Message: err.Error()}
|
|
}
|
|
|
|
items := make([]jvm.Capability, 0, len(normalized.JVM.AllowedModes))
|
|
for _, mode := range normalized.JVM.AllowedModes {
|
|
provider, providerErr := newJVMProvider(mode)
|
|
if providerErr != nil {
|
|
items = append(items, jvm.Capability{
|
|
Mode: mode,
|
|
DisplayLabel: jvm.ModeDisplayLabel(mode),
|
|
Reason: providerErr.Error(),
|
|
})
|
|
continue
|
|
}
|
|
|
|
caps, probeErr := provider.ProbeCapabilities(a.ctx, normalized)
|
|
if probeErr != nil {
|
|
items = append(items, jvm.Capability{
|
|
Mode: mode,
|
|
DisplayLabel: jvm.ModeDisplayLabel(mode),
|
|
Reason: probeErr.Error(),
|
|
})
|
|
continue
|
|
}
|
|
|
|
items = append(items, caps...)
|
|
}
|
|
|
|
return connection.QueryResult{Success: true, Data: items}
|
|
}
|