mirror of
https://github.com/netbirdio/systray.git
synced 2026-05-22 17:08:41 -07:00
Switched Windows to use lxn/walk
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="Lantern" type="win32"/>
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True</dpiAware>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
</assembly>
|
||||
+1
-2
@@ -17,11 +17,10 @@ func main() {
|
||||
fmt.Println("Finished onExit")
|
||||
}
|
||||
// Should be called at the very beginning of main().
|
||||
systray.Run(onReady, onExit)
|
||||
systray.RunWithAppWindow("Lantern", 1024, 768, onReady, onExit)
|
||||
}
|
||||
|
||||
func onReady() {
|
||||
systray.EnableAppWindow("Lantern", 1024, 768)
|
||||
systray.SetIcon(icon.Data)
|
||||
systray.SetTitle("Awesome App")
|
||||
systray.SetTooltip("Lantern")
|
||||
|
||||
Binary file not shown.
@@ -4,5 +4,10 @@ go 1.12
|
||||
|
||||
require (
|
||||
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7
|
||||
github.com/getlantern/uuid v1.2.0
|
||||
github.com/lxn/walk v0.0.0-20190919092010-4386a6d42094
|
||||
github.com/lxn/win v0.0.0-20190919090605-24c5960b03d8 // indirect
|
||||
github.com/skratchdot/open-golang v0.0.0-20190402232053-79abb63cd66e
|
||||
golang.org/x/sys v0.0.0-20190919044723-0c1ff786ef13 // indirect
|
||||
gopkg.in/Knetic/govaluate.v3 v3.0.0 // indirect
|
||||
)
|
||||
|
||||
@@ -11,8 +11,14 @@ github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 h1:XYzSdCbkzOC0F
|
||||
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55/go.mod h1:6mmzY2kW1TOOrVy+r41Za2MxXM+hhqTtY3oBKd2AgFA=
|
||||
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f h1:wrYrQttPS8FHIRSlsrcuKazukx/xqO/PpLZzZXsF+EA=
|
||||
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA=
|
||||
github.com/getlantern/uuid v1.2.0 h1:pGrGaCV7XEaG6lvjWkwf8Y92BjB/9yFmkKsNFpRQ7rc=
|
||||
github.com/getlantern/uuid v1.2.0/go.mod h1:uX10hOzZUUDR+oYNSIks+RcozOEiwTNC/K2rw9SUi1k=
|
||||
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/lxn/walk v0.0.0-20190919092010-4386a6d42094 h1:axV9dR1/LfxQTFTpzjiBzQV9tFarx+Evs2ONi/ceq2U=
|
||||
github.com/lxn/walk v0.0.0-20190919092010-4386a6d42094/go.mod h1:E23UucZGqpuUANJooIbHWCufXvOcT6E7Stq81gU+CSQ=
|
||||
github.com/lxn/win v0.0.0-20190919090605-24c5960b03d8 h1:RVMGIuuNgrpGB7I79f6xfhGCkpN47IaEGh8VTM0p7Xc=
|
||||
github.com/lxn/win v0.0.0-20190919090605-24c5960b03d8/go.mod h1:ouWl4wViUNh8tPSIwxTVMuS014WakR1hqvBc2I0bMoA=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
@@ -20,3 +26,8 @@ github.com/skratchdot/open-golang v0.0.0-20190402232053-79abb63cd66e h1:VAzdS5Nw
|
||||
github.com/skratchdot/open-golang v0.0.0-20190402232053-79abb63cd66e/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190919044723-0c1ff786ef13 h1:/zi0zzlPHWXYXrO1LjNRByFu8sdGgCkj2JLDdBIB84k=
|
||||
golang.org/x/sys v0.0.0-20190919044723-0c1ff786ef13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
gopkg.in/Knetic/govaluate.v3 v3.0.0 h1:18mUyIt4ZlRlFZAAfVetz4/rzlJs9yhN+U02F4u1AOc=
|
||||
gopkg.in/Knetic/govaluate.v3 v3.0.0/go.mod h1:csKLBORsPbafmSCGTEh3U7Ozmsuq8ZSIlKk1bcqph0E=
|
||||
|
||||
+7
-3
@@ -50,10 +50,14 @@ var (
|
||||
)
|
||||
|
||||
// Run initializes GUI and starts the event loop, then invokes the onReady
|
||||
// callback.
|
||||
// It blocks until systray.Quit() is called.
|
||||
// callback. It blocks until systray.Quit() is called.
|
||||
// Should be called at the very beginning of main() to lock at main thread.
|
||||
func Run(onReady func(), onExit func()) {
|
||||
RunWithAppWindow("", 0, 0, onReady, onExit)
|
||||
}
|
||||
|
||||
// RunWithAppWindow is like Run but also enables an application window with the given title.
|
||||
func RunWithAppWindow(title string, width int, height int, onReady func(), onExit func()) {
|
||||
runtime.LockOSThread()
|
||||
atomic.StoreInt64(&hasStarted, 1)
|
||||
|
||||
@@ -78,7 +82,7 @@ func Run(onReady func(), onExit func()) {
|
||||
}
|
||||
systrayExit = onExit
|
||||
|
||||
nativeLoop()
|
||||
nativeLoop(title, width, height)
|
||||
}
|
||||
|
||||
// Quit the systray
|
||||
|
||||
+11
-11
@@ -24,6 +24,17 @@ func quit() {
|
||||
C.quit()
|
||||
}
|
||||
|
||||
// EnableAppWindow enables a single application window for this app.
|
||||
func EnableAppWindow(title string, width int, height int) {
|
||||
C.configureAppWindow(C.CString(title), C.int(width), C.int(height))
|
||||
}
|
||||
|
||||
// ShowAppWindow shows the given URL in the application window. Only works if
|
||||
// configureAppWindow has been called first.
|
||||
func ShowAppWindow(url string) {
|
||||
C.showAppWindow(C.CString(url))
|
||||
}
|
||||
|
||||
// SetIcon sets the systray icon.
|
||||
// iconBytes should be the content of .ico for windows and .ico/.jpg/.png
|
||||
// for other platforms.
|
||||
@@ -43,17 +54,6 @@ func SetTooltip(tooltip string) {
|
||||
C.setTooltip(C.CString(tooltip))
|
||||
}
|
||||
|
||||
// EnableAppWindow enables a single application window for this app.
|
||||
func EnableAppWindow(title string, width int, height int) {
|
||||
C.configureAppWindow(C.CString(title), C.int(width), C.int(height))
|
||||
}
|
||||
|
||||
// ShowAppWindow shows the given URL in the application window. Only works if
|
||||
// configureAppWindow has been called first.
|
||||
func ShowAppWindow(url string) {
|
||||
C.showAppWindow(C.CString(url))
|
||||
}
|
||||
|
||||
func addOrUpdateMenuItem(item *MenuItem) {
|
||||
var disabled C.short
|
||||
if item.disabled {
|
||||
|
||||
+120
-661
File diff suppressed because it is too large
Load Diff
@@ -1,132 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package systray
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
const iconFilePath = "example/icon/iconwin.ico"
|
||||
|
||||
func TestBaseWindowsTray(t *testing.T) {
|
||||
systrayReady = func() {}
|
||||
systrayExit = func() {}
|
||||
|
||||
runtime.LockOSThread()
|
||||
|
||||
if err := wt.initInstance(); err != nil {
|
||||
t.Fatalf("initInstance failed: %s", err)
|
||||
}
|
||||
|
||||
if err := wt.createMenu(); err != nil {
|
||||
t.Fatalf("createMenu failed: %s", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
pDestroyWindow.Call(uintptr(wt.window))
|
||||
wt.wcex.unregister()
|
||||
}()
|
||||
|
||||
if err := wt.setIcon(iconFilePath); err != nil {
|
||||
t.Errorf("SetIcon failed: %s", err)
|
||||
}
|
||||
|
||||
if err := wt.setTooltip("Cyrillic tooltip тест:)"); err != nil {
|
||||
t.Errorf("SetIcon failed: %s", err)
|
||||
}
|
||||
|
||||
var id int32 = 0
|
||||
err := wt.addOrUpdateMenuItem(atomic.AddInt32(&id, 1), "Simple enabled", false, false)
|
||||
if err != nil {
|
||||
t.Errorf("mergeMenuItem failed: %s", err)
|
||||
}
|
||||
err = wt.addOrUpdateMenuItem(atomic.AddInt32(&id, 1), "Simple disabled", true, false)
|
||||
if err != nil {
|
||||
t.Errorf("mergeMenuItem failed: %s", err)
|
||||
}
|
||||
err = wt.addSeparatorMenuItem(atomic.AddInt32(&id, 1))
|
||||
if err != nil {
|
||||
t.Errorf("addSeparatorMenuItem failed: %s", err)
|
||||
}
|
||||
err = wt.addOrUpdateMenuItem(atomic.AddInt32(&id, 1), "Simple checked enabled", false, true)
|
||||
if err != nil {
|
||||
t.Errorf("mergeMenuItem failed: %s", err)
|
||||
}
|
||||
err = wt.addOrUpdateMenuItem(atomic.AddInt32(&id, 1), "Simple checked disabled", true, true)
|
||||
if err != nil {
|
||||
t.Errorf("mergeMenuItem failed: %s", err)
|
||||
}
|
||||
|
||||
err = wt.hideMenuItem(1)
|
||||
if err != nil {
|
||||
t.Errorf("hideMenuItem failed: %s", err)
|
||||
}
|
||||
|
||||
err = wt.hideMenuItem(100)
|
||||
if err == nil {
|
||||
t.Error("hideMenuItem failed: must return error on invalid item id")
|
||||
}
|
||||
|
||||
err = wt.addOrUpdateMenuItem(2, "Simple disabled update", true, false)
|
||||
if err != nil {
|
||||
t.Errorf("mergeMenuItem failed: %s", err)
|
||||
}
|
||||
|
||||
time.AfterFunc(1*time.Second, quit)
|
||||
|
||||
m := struct {
|
||||
WindowHandle windows.Handle
|
||||
Message uint32
|
||||
Wparam uintptr
|
||||
Lparam uintptr
|
||||
Time uint32
|
||||
Pt point
|
||||
}{}
|
||||
for {
|
||||
ret, _, err := pGetMessage.Call(uintptr(unsafe.Pointer(&m)), 0, 0, 0)
|
||||
res := int32(ret)
|
||||
if res == -1 {
|
||||
t.Errorf("win32 GetMessage failed: %v", err)
|
||||
return
|
||||
} else if res == 0 {
|
||||
break
|
||||
}
|
||||
pTranslateMessage.Call(uintptr(unsafe.Pointer(&m)))
|
||||
pDispatchMessage.Call(uintptr(unsafe.Pointer(&m)))
|
||||
}
|
||||
}
|
||||
|
||||
func TestWindowsRun(t *testing.T) {
|
||||
onReady := func() {
|
||||
b, err := ioutil.ReadFile(iconFilePath)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't load icon file: %v", err)
|
||||
}
|
||||
SetIcon(b)
|
||||
SetTitle("Test title с кириллицей")
|
||||
|
||||
bSomeBtn := AddMenuItem("Йа кнопко", "")
|
||||
bSomeBtn.Check()
|
||||
AddSeparator()
|
||||
bQuit := AddMenuItem("Quit", "Quit the whole app")
|
||||
go func() {
|
||||
<-bQuit.ClickedCh
|
||||
t.Log("Quit reqested")
|
||||
Quit()
|
||||
}()
|
||||
time.AfterFunc(1*time.Second, Quit)
|
||||
}
|
||||
|
||||
onExit := func() {
|
||||
t.Log("Exit success")
|
||||
}
|
||||
|
||||
Run(onReady, onExit)
|
||||
}
|
||||
Reference in New Issue
Block a user