mirror of
https://github.com/amnezia-vpn/amneziawg-windows-client.git
synced 2026-05-17 08:15:44 +03:00
* replace wg.exe with awg.exe * update docs, update admin reg key * rename awg modules * build awg from source * remove unused params * improve work with tools * safe rebranding: change upgrade code, windows class and name * safe rebranding: wg -> awg * update dependencies, fixed showing transfered KBs * Revert "remove application update feature" This reverts commit9670f4298e. * Revert "remove application update feature #2" This reverts commitb0c96a9fd6. * updatepage and tray change WireGuard to AmneziaWG * move crypto from indirect to direct --------- Signed-off-by: Roman Zakharchuk <romikb@mail.ru>
134 lines
2.9 KiB
Go
Executable File
134 lines
2.9 KiB
Go
Executable File
/* SPDX-License-Identifier: MIT
|
|
*
|
|
* Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved.
|
|
*/
|
|
|
|
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"runtime/debug"
|
|
"time"
|
|
|
|
"github.com/lxn/walk"
|
|
"github.com/lxn/win"
|
|
"golang.org/x/sys/windows"
|
|
|
|
"github.com/amnezia-vpn/amneziawg-windows-client/l18n"
|
|
"github.com/amnezia-vpn/amneziawg-windows-client/manager"
|
|
"github.com/amnezia-vpn/amneziawg-windows-client/version"
|
|
)
|
|
|
|
var (
|
|
noTrayAvailable = false
|
|
shouldQuitManagerWhenExiting = false
|
|
startTime = time.Now()
|
|
IsAdmin = false // A global, because this really is global for the process
|
|
)
|
|
|
|
func RunUI() {
|
|
runtime.LockOSThread()
|
|
windows.SetProcessPriorityBoost(windows.CurrentProcess(), false)
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
showErrorCustom(nil, "Panic", fmt.Sprint(err, "\n\n", string(debug.Stack())))
|
|
panic(err)
|
|
}
|
|
}()
|
|
|
|
var (
|
|
err error
|
|
mtw *ManageTunnelsWindow
|
|
tray *Tray
|
|
)
|
|
|
|
for mtw == nil {
|
|
mtw, err = NewManageTunnelsWindow()
|
|
if err != nil {
|
|
time.Sleep(time.Millisecond * 400)
|
|
}
|
|
}
|
|
|
|
for tray == nil {
|
|
tray, err = NewTray(mtw)
|
|
if err != nil {
|
|
if version.OsIsCore() {
|
|
noTrayAvailable = true
|
|
break
|
|
}
|
|
time.Sleep(time.Millisecond * 400)
|
|
}
|
|
}
|
|
|
|
manager.IPCClientRegisterManagerStopping(func() {
|
|
mtw.Synchronize(func() {
|
|
walk.App().Exit(0)
|
|
})
|
|
})
|
|
|
|
onUpdateNotification := func(updateState manager.UpdateState) {
|
|
if updateState == manager.UpdateStateUnknown {
|
|
return
|
|
}
|
|
mtw.Synchronize(func() {
|
|
switch updateState {
|
|
case manager.UpdateStateFoundUpdate:
|
|
mtw.UpdateFound()
|
|
if tray != nil && IsAdmin {
|
|
tray.UpdateFound()
|
|
}
|
|
case manager.UpdateStateUpdatesDisabledUnofficialBuild:
|
|
mtw.SetTitle(l18n.Sprintf("%s (unsigned build, no updates)", mtw.Title()))
|
|
}
|
|
})
|
|
}
|
|
manager.IPCClientRegisterUpdateFound(onUpdateNotification)
|
|
go func() {
|
|
updateState, err := manager.IPCClientUpdateState()
|
|
if err == nil {
|
|
onUpdateNotification(updateState)
|
|
}
|
|
}()
|
|
|
|
if tray == nil {
|
|
win.ShowWindow(mtw.Handle(), win.SW_MINIMIZE)
|
|
}
|
|
|
|
mtw.Run()
|
|
if tray != nil {
|
|
tray.Dispose()
|
|
}
|
|
mtw.Dispose()
|
|
|
|
if shouldQuitManagerWhenExiting {
|
|
_, err := manager.IPCClientQuit(true)
|
|
if err != nil {
|
|
showErrorCustom(nil, l18n.Sprintf("Error Exiting AmneziaWG"), l18n.Sprintf("Unable to exit service due to: %v. You may want to stop AmneziaWG from the service manager.", err))
|
|
}
|
|
}
|
|
}
|
|
|
|
func onQuit() {
|
|
shouldQuitManagerWhenExiting = true
|
|
walk.App().Exit(0)
|
|
}
|
|
|
|
func showError(err error, owner walk.Form) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
|
|
showErrorCustom(owner, l18n.Sprintf("Error"), err.Error())
|
|
|
|
return true
|
|
}
|
|
|
|
func showErrorCustom(owner walk.Form, title, message string) {
|
|
walk.MsgBox(owner, title, message, walk.MsgBoxIconError)
|
|
}
|
|
|
|
func showWarningCustom(owner walk.Form, title, message string) {
|
|
walk.MsgBox(owner, title, message, walk.MsgBoxIconWarning)
|
|
}
|