修改logo,修改配置页面的窗口
This commit is contained in:
+6
-4
@@ -20,10 +20,11 @@ import (
|
||||
|
||||
// App is the GUI application controller.
|
||||
type App struct {
|
||||
fyneApp fyne.App
|
||||
db *db.Store
|
||||
kc keychain.Store
|
||||
window fyne.Window
|
||||
fyneApp fyne.App
|
||||
db *db.Store
|
||||
kc keychain.Store
|
||||
window fyne.Window
|
||||
profileWindow fyne.Window
|
||||
|
||||
// UI widgets
|
||||
profileSelect *widget.Select
|
||||
@@ -96,6 +97,7 @@ func Run() {
|
||||
|
||||
a.window.SetCloseIntercept(func() {
|
||||
if cfg.CloseToTray {
|
||||
hideDockIcon()
|
||||
a.window.Hide()
|
||||
} else {
|
||||
a.fyneApp.Quit()
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//go:build darwin
|
||||
|
||||
package ui
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -framework Cocoa
|
||||
#include <objc/objc.h>
|
||||
#include <objc/runtime.h>
|
||||
#include <objc/message.h>
|
||||
|
||||
static void setDockIconVisible(int visible) {
|
||||
Class cls = objc_getClass("NSApplication");
|
||||
id app = ((id (*)(Class, SEL))objc_msgSend)(cls, sel_getUid("sharedApplication"));
|
||||
((void (*)(id, SEL, long))objc_msgSend)(app, sel_getUid("setActivationPolicy:"), visible ? 0 : 1);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func showDockIcon() { C.setDockIconVisible(1) }
|
||||
func hideDockIcon() { C.setDockIconVisible(0) }
|
||||
@@ -0,0 +1,6 @@
|
||||
//go:build !darwin
|
||||
|
||||
package ui
|
||||
|
||||
func showDockIcon() {}
|
||||
func hideDockIcon() {}
|
||||
+27
-10
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
@@ -46,9 +45,15 @@ func selectedCode(codes []string, idx int) string {
|
||||
return codes[idx]
|
||||
}
|
||||
|
||||
// showProfileDialog displays an add/edit dialog for a server profile.
|
||||
// If editing is nil, a new profile is created.
|
||||
// showProfileDialog opens a separate window for editing a server profile.
|
||||
// If editing is nil, a new profile is created. If a profile window is
|
||||
// already open, it is brought to the front instead of opening a second one.
|
||||
func (a *App) showProfileDialog(editing *model.ServerProfile) {
|
||||
if a.profileWindow != nil {
|
||||
a.profileWindow.RequestFocus()
|
||||
return
|
||||
}
|
||||
|
||||
isNew := editing == nil
|
||||
|
||||
nameEntry := widget.NewEntry()
|
||||
@@ -88,18 +93,30 @@ func (a *App) showProfileDialog(editing *model.ServerProfile) {
|
||||
widget.NewLabel(i18n.T("FieldMTUOverride")), mtuEntry,
|
||||
)
|
||||
|
||||
d := dialog.NewCustomConfirm(i18n.T("DlgProfileTitle"), i18n.T("BtnSave"), i18n.T("BtnCancel"), form, func(save bool) {
|
||||
if !save {
|
||||
return
|
||||
}
|
||||
profileWin := a.fyneApp.NewWindow(i18n.T("DlgProfileTitle"))
|
||||
a.profileWindow = profileWin
|
||||
|
||||
profileWin.SetOnClosed(func() {
|
||||
a.profileWindow = nil
|
||||
})
|
||||
|
||||
saveBtn := widget.NewButton(i18n.T("BtnSave"), func() {
|
||||
a.saveProfile(editing, nameEntry.Text, serverEntry.Text,
|
||||
userEntry.Text, passEntry.Text,
|
||||
selectedCode(authCodes, authSelect.SelectedIndex()),
|
||||
selectedCode(routeCodes, routeSelect.SelectedIndex()),
|
||||
cidrEntry.Text, mtuEntry.Text, isNew)
|
||||
}, a.window)
|
||||
d.Resize(fyne.NewSize(400, 500))
|
||||
d.Show()
|
||||
profileWin.Close()
|
||||
})
|
||||
saveBtn.Importance = widget.HighImportance
|
||||
|
||||
cancelBtn := widget.NewButton(i18n.T("BtnCancel"), func() {
|
||||
profileWin.Close()
|
||||
})
|
||||
|
||||
profileWin.SetContent(container.NewBorder(nil, container.NewHBox(saveBtn, cancelBtn), nil, nil, container.NewScroll(form)))
|
||||
profileWin.Resize(fyne.NewSize(460, 560))
|
||||
profileWin.Show()
|
||||
}
|
||||
|
||||
// saveProfile creates or updates a profile and stores credentials.
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
@@ -1,12 +1,16 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"lmvpn/internal/i18n"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/driver/desktop"
|
||||
)
|
||||
|
||||
//go:embed tray-icon.png
|
||||
var trayIconBytes []byte
|
||||
|
||||
// setupTray configures the system tray menu (desktop only).
|
||||
func (a *App) setupTray() {
|
||||
deskApp, ok := a.fyneApp.(desktop.App)
|
||||
@@ -44,6 +48,7 @@ func (a *App) setupTray() {
|
||||
|
||||
menu := fyne.NewMenu(i18n.T("WindowTitle"),
|
||||
fyne.NewMenuItem(i18n.T("TrayShowWindow"), func() {
|
||||
showDockIcon()
|
||||
a.window.Show()
|
||||
a.window.RequestFocus()
|
||||
}),
|
||||
@@ -62,4 +67,6 @@ func (a *App) setupTray() {
|
||||
}),
|
||||
)
|
||||
deskApp.SetSystemTrayMenu(menu)
|
||||
trayIcon := fyne.NewStaticResource("tray-icon.png", trayIconBytes)
|
||||
deskApp.SetSystemTrayIcon(trayIcon)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user