Add action for opening config file

This commit is contained in:
koho
2022-01-21 10:20:54 +08:00
parent e886331264
commit 96ee33d14d
6 changed files with 27 additions and 9 deletions

1
.gitignore vendored
View File

@ -2,4 +2,3 @@
logs
bin
*.syso
icon/*.ico

BIN
icon/open.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -9,6 +9,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST manifest.xml
11 ICON icon/app.ico
21 ICON icon/dot.ico
22 ICON icon/open.ico
VS_VERSION_INFO VERSIONINFO \
FILEVERSION FRPMGR_VERSION_ARRAY \

View File

@ -103,7 +103,7 @@ func (t *AboutPage) View() TabPage {
Alignment: AlignHNearVCenter,
Text: `<a id="home" href="https://github.com/koho/frpmgr">https://github.com/koho/frpmgr</a>`,
OnLinkActivated: func(link *walk.LinkLabelLink) {
t.openURL(link.URL())
openPath(link.URL())
},
},
VSpacer{Size: 6},
@ -112,7 +112,7 @@ func (t *AboutPage) View() TabPage {
Alignment: AlignHNearVCenter,
Text: `<a id="frp" href="https://github.com/fatedier/frp">https://github.com/fatedier/frp</a>`,
OnLinkActivated: func(link *walk.LinkLabelLink) {
t.openURL(link.URL())
openPath(link.URL())
},
},
},
@ -132,7 +132,7 @@ func (t *AboutPage) View() TabPage {
Label{AssignTo: &t.newVersionTag},
Label{AssignTo: &t.newVersionDate},
PushButton{AssignTo: &t.newVersionDownloadBtn, Text: "下载", OnClicked: func() {
t.openURL(t.newVersionDownloadBtn.Name())
openPath(t.newVersionDownloadBtn.Name())
}},
HSpacer{},
},
@ -144,11 +144,11 @@ func (t *AboutPage) View() TabPage {
}
}
func (t *AboutPage) openURL(url string) {
if url == "" {
func openPath(path string) {
if path == "" {
return
}
openCmd := exec.Command("cmd", "/c", "start", url)
openCmd := exec.Command("cmd", "/c", "start", path)
openCmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
openCmd.Start()
}

View File

@ -9,6 +9,7 @@ import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"golang.org/x/sys/windows"
"path/filepath"
"time"
)
@ -225,7 +226,7 @@ func (t *ConfSectionView) View() Widget {
Action{
AssignTo: &t.webAction,
Text: "Web",
Image: loadSysIcon("shell32", 14, 16),
Image: loadSysIcon("shell32", 13, 16),
OnTriggered: func() {
t.onQuickAddSection(NewSimpleSectionDialog("Web", "web", []string{"tcp"}, 80))
},
@ -248,6 +249,18 @@ func (t *ConfSectionView) View() Widget {
Enabled: Bind("section.Selected"),
OnTriggered: t.onDeleteSection,
},
Action{
Image: loadResourceIcon(22, 16),
Text: "打开配置文件",
OnTriggered: func() {
if !t.mustSelectConf() {
return
}
if path, err := filepath.Abs(t.model.conf.Path); err == nil {
openPath(path)
}
},
},
},
},
TableView{

View File

@ -42,7 +42,7 @@ func iconForState(state config.ServiceState, size int) (icon *walk.Icon) {
case config.StateStarted:
icon = loadSysIcon("imageres", 101, size)
case config.StateStopped:
icon, _ = walk.NewIconFromResourceIdWithSize(21, walk.Size{size, size})
icon = loadResourceIcon(21, size)
default:
icon = loadSysIcon("shell32", 238, size)
}
@ -71,3 +71,8 @@ func loadNewVersionIcon(size int) (icon *walk.Icon) {
}
return
}
func loadResourceIcon(id int, size int) (icon *walk.Icon) {
icon, _ = walk.NewIconFromResourceIdWithSize(id, walk.Size{size, size})
return
}