diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-11 17:41:19 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-11 17:49:55 +0200 |
commit | 8c4162b31875e1773ac19ea748b22d27b5e3d490 (patch) | |
tree | d5bcc37b6183fd62e37b31460050d242b130d1db /ui/editdialog.go | |
parent | ui: tunnel cloning (diff) | |
download | wireguard-windows-8c4162b31875e1773ac19ea748b22d27b5e3d490.tar.xz wireguard-windows-8c4162b31875e1773ac19ea748b22d27b5e3d490.zip |
ui: allow editing existing tunnels without changing name
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | ui/editdialog.go | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/ui/editdialog.go b/ui/editdialog.go index b4ed8ebe..72382120 100644 --- a/ui/editdialog.go +++ b/ui/editdialog.go @@ -28,13 +28,9 @@ type EditDialog struct { } func runTunnelEditDialog(owner walk.Form, tunnel *service.Tunnel, clone bool) *conf.Config { - var ( - title string - name string - ) - dlg := &EditDialog{} + var title string if tunnel == nil || clone { title = "Create new tunnel" } else { @@ -46,11 +42,10 @@ func runTunnelEditDialog(owner walk.Form, tunnel *service.Tunnel, clone bool) *c pk, _ := conf.NewPrivateKey() dlg.config = conf.Config{Interface: conf.Interface{PrivateKey: *pk}} } else { - name = tunnel.Name + dlg.config, _ = tunnel.StoredConfig() if clone { - name += "-copy" + dlg.config.Name += "-copy" } - dlg.config, _ = tunnel.StoredConfig() } layout := walk.NewGridLayout() @@ -71,7 +66,7 @@ func runTunnelEditDialog(owner walk.Form, tunnel *service.Tunnel, clone bool) *c dlg.nameEdit, _ = walk.NewLineEdit(dlg) layout.SetRange(dlg.nameEdit, walk.Rectangle{1, 0, 1, 1}) - dlg.nameEdit.SetText(name) + dlg.nameEdit.SetText(dlg.config.Name) pubkeyLabel, _ := walk.NewTextLabel(dlg) layout.SetRange(pubkeyLabel, walk.Rectangle{0, 1, 1, 1}) @@ -114,6 +109,10 @@ func runTunnelEditDialog(owner walk.Form, tunnel *service.Tunnel, clone bool) *c dlg.syntaxEdit.BlockUntunneledTrafficStateChanged().Attach(dlg.onBlockUntunneledTrafficStateChanged) dlg.syntaxEdit.SetText(dlg.config.ToWgQuick()) + if clone { + dlg.config.Name = "" + } + if tunnel != nil && !clone { dlg.nameEdit.SetFocus() //TODO: This works around a walk issue with scrolling in weird ways <https://github.com/lxn/walk/issues/505>. We should fix this in walk instead of here. @@ -263,18 +262,20 @@ func (dlg *EditDialog) onSaveButtonClicked() { walk.MsgBox(dlg, "Invalid name", fmt.Sprintf("Tunnel name ‘%s’ is invalid.", newName), walk.MsgBoxIconWarning) return } - - existingTunnelList, err := service.IPCClientTunnels() - if err != nil { - walk.MsgBox(dlg, "Unable to list existing tunnels", err.Error(), walk.MsgBoxIconError) - return - } newNameLower := strings.ToLower(newName) - for _, tunnel := range existingTunnelList { - if strings.ToLower(tunnel.Name) == newNameLower { - walk.MsgBox(dlg, "Tunnel already exists", fmt.Sprintf("Another tunnel already exists with the name ‘%s’.", newName), walk.MsgBoxIconWarning) + + if newNameLower != strings.ToLower(dlg.config.Name) { + existingTunnelList, err := service.IPCClientTunnels() + if err != nil { + walk.MsgBox(dlg, "Unable to list existing tunnels", err.Error(), walk.MsgBoxIconError) return } + for _, tunnel := range existingTunnelList { + if strings.ToLower(tunnel.Name) == newNameLower { + walk.MsgBox(dlg, "Tunnel already exists", fmt.Sprintf("Another tunnel already exists with the name ‘%s’.", newName), walk.MsgBoxIconWarning) + return + } + } } cfg, err := conf.FromWgQuick(dlg.syntaxEdit.Text(), newName) |