diff --git a/ui2/ipEntry.go b/ui2/ipEntry.go deleted file mode 100644 index 9d4e7f6..0000000 --- a/ui2/ipEntry.go +++ /dev/null @@ -1,42 +0,0 @@ -//go:build windows - -package ui2 - -import ( - "errors" - "regexp" - - "fyne.io/fyne/driver/mobile" - "fyne.io/fyne/v2/widget" -) - -var ( - // IPv4 验证正则表达式(编译一次,重复使用) - ipv4Regex = regexp.MustCompile(`^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`) -) - -type ipEntry struct { - widget.Entry -} - -func (n *ipEntry) Keyboard() mobile.KeyboardType { - return mobile.NumberKeyboard -} - -func (n *ipEntry) ResetPlaceHolder() { - n.SetPlaceHolder("例如: 127.0.0.1") -} - -func NewIpEntry(ip string) *ipEntry { - e := &ipEntry{} - e.ExtendBaseWidget(e) - e.Validator = func(ip string) error { - if ipv4Regex.MatchString(ip) { - return nil - } - return errors.New("请输入正确的IP地址") - } - e.ResetPlaceHolder() - e.SetText(ip) - return e -} diff --git a/ui2/local.go b/ui2/local.go deleted file mode 100644 index 8681972..0000000 --- a/ui2/local.go +++ /dev/null @@ -1,95 +0,0 @@ -//go:build windows - -package ui2 - -import ( - "goodlink/config" - - "fyne.io/fyne/v2" - "fyne.io/fyne/v2/container" - "fyne.io/fyne/v2/widget" -) - -type LocalUI struct { - localIP string - connType int - box_local_port *portEntry - radio1 *widget.RadioGroup - radio_conn_type *widget.RadioGroup -} - -func (c *LocalUI) GetConnType2() string { - return c.radio_conn_type.Selected -} - -func (c *LocalUI) GetConnType() int { - return c.connType -} - -func (c *LocalUI) Disable() { - c.radio1.Disable() - c.box_local_port.Disable() - c.radio_conn_type.Disable() -} - -func (c *LocalUI) Enable() { - c.radio1.Enable() - c.box_local_port.Enable() - c.radio_conn_type.Enable() -} - -func (c *LocalUI) GetLocalIP() string { - return c.localIP -} - -func (c *LocalUI) GetLocalPort() string { - return c.box_local_port.Text -} - -func (c *LocalUI) GetLocalAddr() (string, error) { - return c.localIP + ":" + c.box_local_port.Text, c.box_local_port.Validate() -} - -func (c *LocalUI) GetContainer() *fyne.Container { - // 当前返回空容器,保留接口以便未来扩展 - return container.NewVBox() -} - -func NewLocalUI(myWindow *fyne.Window, configInfo *config.ConfigInfo) *LocalUI { - c := &LocalUI{ - box_local_port: NewPortEntry(configInfo.LocalPort), - radio_conn_type: widget.NewRadioGroup([]string{"主动连接", "被动连接"}, nil), - radio1: widget.NewRadioGroup([]string{"只允许本机", "允许局域网"}, nil), - } - - c.radio1.Horizontal = true - c.radio1.OnChanged = func(value string) { - switch value { - case "允许局域网": - c.localIP = "0.0.0.0" - default: - c.localIP = "127.0.0.1" - } - } - if configInfo.LocalIP == "0.0.0.0" { - c.radio1.SetSelected("允许局域网") - } else { - c.radio1.SetSelected("只允许本机") - } - - c.radio_conn_type.Horizontal = true - c.radio_conn_type.OnChanged = func(value string) { - switch value { - case "主动连接": - c.connType = 1 - default: - c.connType = 0 - } - } - if configInfo.ConnType == "" { - configInfo.ConnType = "被动连接" - } - c.radio_conn_type.SetSelected(configInfo.ConnType) - - return c -} diff --git a/ui2/log.go b/ui2/log.go index 0140899..238edae 100644 --- a/ui2/log.go +++ b/ui2/log.go @@ -4,7 +4,6 @@ package ui2 import ( "fmt" - "regexp" "sync" "fyne.io/fyne/v2" @@ -12,9 +11,6 @@ import ( "fyne.io/fyne/v2/widget" ) -// 匹配日志日期前缀的正则表达式,如 "2024/01/01 " 或 "2024-01-01 ",保留时间部分 -var logDateTimeRegex = regexp.MustCompile(`^\d{4}[/-]\d{2}[/-]\d{2}\s+`) - const ( // 日志最大条目数,避免内存占用过大 maxLogEntries = 500 diff --git a/ui2/portEntry.go b/ui2/portEntry.go deleted file mode 100644 index 61b9297..0000000 --- a/ui2/portEntry.go +++ /dev/null @@ -1,37 +0,0 @@ -//go:build windows - -package ui2 - -import ( - "errors" - "strconv" - - "fyne.io/fyne/driver/mobile" - "fyne.io/fyne/v2/widget" -) - -type portEntry struct { - widget.Entry -} - -func (n *portEntry) Keyboard() mobile.KeyboardType { - return mobile.NumberKeyboard -} - -func (n *portEntry) ResetPlaceHolder() { - n.SetPlaceHolder("范围: 1-65535") -} - -func NewPortEntry(port string) *portEntry { - e := &portEntry{} - e.ExtendBaseWidget(e) - e.Validator = func(port string) error { - if n, err := strconv.Atoi(port); err == nil && n >= 1 && n <= 65535 { - return nil - } - return errors.New("请输入正确的端口号") - } - e.ResetPlaceHolder() - e.SetText(port) - return e -} diff --git a/ui2/remote.go b/ui2/remote.go deleted file mode 100644 index 45a22a8..0000000 --- a/ui2/remote.go +++ /dev/null @@ -1,103 +0,0 @@ -//go:build windows - -package ui2 - -import ( - "goodlink/config" - - "fyne.io/fyne/v2" - "fyne.io/fyne/v2/container" - "fyne.io/fyne/v2/widget" -) - -type RemoteUI struct { - box_remote_ip *ipEntry - box_remote_port *portEntry - radio *widget.RadioGroup -} - -func (c *RemoteUI) Disable() { - c.box_remote_ip.Disable() - c.box_remote_port.Disable() - c.radio.Disable() -} - -func (c *RemoteUI) Enable() { - c.box_remote_ip.Enable() - c.box_remote_port.Enable() - c.radio.Enable() -} - -func (c *RemoteUI) GetRemoteType() string { - return c.radio.Selected -} - -func (c *RemoteUI) GetRemoteIP() string { - return c.box_remote_ip.Text -} - -func (c *RemoteUI) GetRemotePort() string { - return c.box_remote_port.Text -} - -func (c *RemoteUI) GetRemoteAddr() (string, error) { - if c.box_remote_ip.Validate() != nil { - return "", c.box_remote_ip.Validate() - } - if c.box_remote_port.Validate() != nil { - return "", c.box_remote_port.Validate() - } - return c.box_remote_ip.Text + ":" + c.box_remote_port.Text, nil -} - -func (c *RemoteUI) GetContainer() *fyne.Container { - // 当前返回空容器,保留接口以便未来扩展 - return container.NewVBox() -} - -func NewRemoteUI(myWindow *fyne.Window, configInfo *config.ConfigInfo) *RemoteUI { - c := &RemoteUI{ - radio: widget.NewRadioGroup([]string{"代理模式", "转发模式"}, nil), - box_remote_ip: NewIpEntry(configInfo.RemoteIP), - box_remote_port: NewPortEntry(configInfo.RemotePort), - } - - c.radio.Horizontal = true - c.radio.OnChanged = func(value string) { - switch value { - case "转发模式": - c.box_remote_ip.SetText(configInfo.RemoteIP) - c.box_remote_ip.ResetPlaceHolder() - c.box_remote_ip.Enable() - - c.box_remote_port.SetText(configInfo.RemotePort) - c.box_remote_port.ResetPlaceHolder() - c.box_remote_port.Enable() - default: - if c.box_remote_ip.Validate() == nil { - configInfo.RemoteIP = c.box_remote_ip.Text - } - c.box_remote_ip.SetText("") - c.box_remote_ip.SetPlaceHolder("无需配置") - c.box_remote_ip.Disable() - - if c.box_remote_port.Validate() == nil { - configInfo.RemotePort = c.box_remote_port.Text - } - c.box_remote_port.SetText("") - c.box_remote_port.SetPlaceHolder("无需配置") - c.box_remote_port.Disable() - } - } - - switch configInfo.RemoteType { - case "转发模式": - c.radio.SetSelected(configInfo.RemoteType) - c.box_remote_ip.SetText(configInfo.RemoteIP) - c.box_remote_port.SetText(configInfo.RemotePort) - default: - c.radio.SetSelected("代理模式") - } - - return c -} diff --git a/ui2/start.go b/ui2/start.go index 4230969..d491435 100644 --- a/ui2/start.go +++ b/ui2/start.go @@ -264,27 +264,13 @@ func start_button_click() { case 0: switch GetWorkType() { case workTypeLocal: - if m_ui_local.GetLocalPort() == "" { - //SetLogLabel("请填写访问端口号") - //return - } case workTypeRemote: - switch m_ui_remote.GetRemoteType() { - case "代理模式": - case "转发模式": - } } // 保存配置文件, 下次启动加载 configByte, _ := json.Marshal(&config.ConfigInfo{ - WorkType: GetWorkType(), - TunKey: m_validated_key.Text, - ConnType: m_ui_local.GetConnType2(), - LocalIP: m_ui_local.GetLocalIP(), - LocalPort: m_ui_local.GetLocalPort(), - RemoteType: m_ui_remote.GetRemoteType(), - RemoteIP: m_ui_remote.GetRemoteIP(), - RemotePort: m_ui_remote.GetRemotePort(), + WorkType: GetWorkType(), + TunKey: m_validated_key.Text, }) log.Println(string(configByte)) os.Remove("goodlink.json") diff --git a/ui2/ui.go b/ui2/ui.go index 372fe06..33c53e8 100644 --- a/ui2/ui.go +++ b/ui2/ui.go @@ -42,8 +42,6 @@ var ( m_btn_local *widget.Button m_btn_remote *widget.Button m_validated_key *widget.Entry - m_ui_local *LocalUI - m_ui_remote *RemoteUI m_button_key_create *widget.Button m_button_key_paste *widget.Button m_btn_local_bg *canvas.Rectangle // 本地端按钮高亮背景 @@ -215,9 +213,6 @@ func GetMainUI(myWindow *fyne.Window) *fyne.Container { log.Println("自动生成密钥:", configInfo.TunKey) } - m_ui_local = NewLocalUI(myWindow, &configInfo) - m_ui_remote = NewRemoteUI(myWindow, &configInfo) - // 创建各个UI组件 workTypeSelector := createWorkTypeSelector(&configInfo) keyInputSection := createKeyInputSection(&configInfo) @@ -225,8 +220,6 @@ func GetMainUI(myWindow *fyne.Window) *fyne.Container { // 设置需要控制的UI组件列表(必须在所有组件创建后设置) setUIComponents([]uiComponent{ - m_ui_local, - m_ui_remote, &entryWrapper{entry: m_validated_key}, &buttonWrapper{btn: m_button_key_create}, &buttonWrapper{btn: m_button_key_paste}, @@ -248,11 +241,6 @@ func GetMainUI(myWindow *fyne.Window) *fyne.Container { // 根据工作模式显示对应的配置 updateConfigDisplay := func() { configContainer.RemoveAll() - if GetWorkType() == workTypeLocal { - configContainer.Add(m_ui_local.GetContainer()) - } else { - configContainer.Add(m_ui_remote.GetContainer()) - } configContainer.Refresh() }