GithubHelp home page GithubHelp logo

getlantern / systray Goto Github PK

View Code? Open in Web Editor NEW
3.2K 67.0 436.0 53.78 MB

a cross platfrom Go library to place an icon and menu in the notification area

License: Apache License 2.0

Go 77.95% Shell 0.65% C 9.64% Objective-C 10.51% Batchfile 0.70% Makefile 0.55%

systray's Introduction

systray

systray is a cross-platform Go library to place an icon and menu in the notification area.

Features

  • Supported on Windows, macOS, and Linux
  • Menu items can be checked and/or disabled
  • Most functions may be called from any goroutine

API

func main() {
	systray.Run(onReady, onExit)
}

func onReady() {
	systray.SetIcon(icon.Data)
	systray.SetTitle("Awesome App")
	systray.SetTooltip("Pretty awesome超级棒")
	mQuit := systray.AddMenuItem("Quit", "Quit the whole app")

	// Sets the icon of a menu item. Only available on Mac and Windows.
	mQuit.SetIcon(icon.Data)
}

func onExit() {
	// clean up here
}

See full API as well as CHANGELOG.

Note: this package requires cgo, so make sure you set CGO_ENABLED=1 before building.

Try the example app!

Have go v1.12+ or higher installed? Here's an example to get started on macOS:

git clone https://github.com/getlantern/systray
cd systray/example
env GO111MODULE=on go build
./example

On Windows, you should build like this:

env GO111MODULE=on go build -ldflags "-H=windowsgui"

Now look for Awesome App in your menu bar!

Awesome App screenshot

The Webview example

The code under webview_example is to demostrate how it can co-exist with other UI elements. Note that the example doesn't work on macOS versions older than 10.15 Catalina.

Platform notes

Linux

  • Building apps requires gcc as well as the gtk3 and libayatana-appindicator3 development headers to be installed. For Debian or Ubuntu, you may install these using:
sudo apt-get install gcc libgtk-3-dev libayatana-appindicator3-dev

On Linux Mint, libxapp-dev is also required.

If you need to support the older libappindicator3 library instead, you can pass the build flag legacy_appindicator when building. For example:

go build -tags=legacy_appindicator

To build webview_example, you also need to install libwebkit2gtk-4.0-dev and remove webview_example/rsrc.syso which is required on Windows.

Windows

  • To avoid opening a console at application startup, use these compile flags:
go build -ldflags -H=windowsgui

macOS

On macOS, you will need to create an application bundle to wrap the binary; simply folders with the following minimal structure and assets:

SystrayApp.app/
  Contents/
    Info.plist
    MacOS/
      go-executable
    Resources/
      SystrayApp.icns

When running as an app bundle, you may want to add one or both of the following to your Info.plist:

<!-- avoid having a blurry icon and text -->
	<key>NSHighResolutionCapable</key>
	<string>True</string>

	<!-- avoid showing the app on the Dock -->
	<key>LSUIElement</key>
	<string>1</string>

Consult the Official Apple Documentation here.

On macOS, it's possible to set the underlying NSStatusItemBehavior with systray.SetRemovalAllowed(true). When enabled, the user can cmd-drag the icon off the menu bar.

Credits

systray's People

Contributors

amkulikov avatar anacrolix avatar atavism avatar cocotyty avatar crosse avatar delthas avatar dependabot[bot] avatar fffw avatar hwh33 avatar jefvel avatar joesis avatar juja256 avatar kalikaneko avatar ksubileau avatar ldstein avatar luckcolors avatar max-b avatar meskio avatar mikeschinkel avatar myleshorton avatar oxtoacart avatar romualdr avatar simonlindholm avatar sithembiso avatar stoggi avatar swznd avatar teddywing avatar tstromberg avatar y-yagi avatar zereraz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

systray's Issues

Colour or Icon On Menu Item

I'm trying to use systray as a monitoring notifier for my local and production databases and wanted to know if it's currently possible to add icons or colour to the menu items?

Font weight/size

Is there any way to change MenuItem's font size for weight? I think it is needed.

go 1.13 : build command-line-arguments: cannot load bufio: malformed module path "bufio": missing dot in first path element

go version go1.13beta1 darwin/amd64

go: finding github.com/getlantern/systray latest
go: finding github.com/skratchdot/open-golang latest
go: finding github.com/getlantern/golog latest
go: finding github.com/getlantern/ops latest
go: finding github.com/getlantern/errors latest
go: finding github.com/getlantern/hidden latest
go: finding github.com/oxtoacart/bpool latest
go: finding github.com/getlantern/hex latest
go: finding github.com/getlantern/context latest
build command-line-arguments: cannot load bufio: malformed module path "bufio": missing dot in first path element

OSX Mojave warnings...

Upgraded my laptop to Mojave and I am getting the following warnings:

vendor/github.com/getlantern/systray

systray_darwin.m:67:15: warning: 'setImage:' is deprecated: first deprecated in macOS 10.14 - Use the receiver's button.image instead [-Wdeprecated-declarations]
/System/Library/Frameworks/AppKit.framework/Headers/NSStatusItem.h:85:39: note: property 'image' is declared deprecated here
/System/Library/Frameworks/AppKit.framework/Headers/NSStatusItem.h:85:39: note: 'setImage:' has been explicitly marked deprecated here
systray_darwin.m:71:15: warning: 'setTitle:' is deprecated: first deprecated in macOS 10.14 - Use the receiver's button.title instead [-Wdeprecated-declarations]
/System/Library/Frameworks/AppKit.framework/Headers/NSStatusItem.h:83:38: note: property 'title' is declared deprecated here
/System/Library/Frameworks/AppKit.framework/Headers/NSStatusItem.h:83:38: note: 'setTitle:' has been explicitly marked deprecated here
systray_darwin.m:75:15: warning: 'setToolTip:' is deprecated: first deprecated in macOS 10.14 - Use the receiver's button.toolTip instead [-Wdeprecated-declarations]
/System/Library/Frameworks/AppKit.framework/Headers/NSStatusItem.h:89:38: note: property 'toolTip' is declared deprecated here
/System/Library/Frameworks/AppKit.framework/Headers/NSStatusItem.h:89:38: note: 'setToolTip:' has been explicitly marked deprecated here
systray_darwin.m:105:24: warning: 'NSOnState' is deprecated: first deprecated in macOS 10.14 [-Wdeprecated-declarations]
/System/Library/Frameworks/AppKit.framework/Headers/NSCell.h:80:34: note: 'NSOnState' has been explicitly marked deprecated here
systray_darwin.m:107:24: warning: 'NSOffState' is deprecated: first deprecated in macOS 10.14 [-Wdeprecated-declarations]
/System/Library/Frameworks/AppKit.framework/Headers/NSCell.h:79:34: note: 'NSOffState' has been explicitly marked deprecated here

Suggest to add key event.

Such as:

func main() {
	// Should be called at the very beginning of main().
	systray.Run(onReady, onExit)
}

func onReady() {
	systray.SetIcon(icon.Data)
	systray.SetTitle("Awesome App")
	systray.SetTooltip("Pretty awesome !")
	mQuit := systray.AddMenuItem("F12 Quit", "Quit the whole app")

        // add key event then press F12 can run the action

}

func onExit() {
	// clean up here
}

Linux warning

legolord208@legolord208-X550LD ~/Coding/Go/src/github.com/getlantern $ go get github.com/getlantern/systray/
# github.com/getlantern/systray
systray/systray_linux.c: In function ‘nativeLoop’:
systray/systray_linux.c:37:2: warning: ‘return’ with no value, in function returning non-void
  return;
  ^

Still works, so... nothing big. Just letting you know. Probably change it to return 0 or something ¯\_(ツ)_/¯

Hide Windows Console?

When running the executable from Windows the Console window is still show. I see there is a ShowWindow call that should hide the window but it is not doing the trick. I've tried this in Win10 and Win7. Is there a simple solution to this problem? Or is this known and expected?

Can't build on Mac OS X after upgrading to Xcode 8

I had written a go program which was using systray just fine until I update xcode to version 8 which comes with a new set of developer tools. Now I can run of build my tool using systray anymore.
Does any one got any tips what I need to debug or how I can fix the issue?

I got the following stacktrace:

2016-09-17 17:25:32.634 main[2925:156856] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1259/Misc.subproj/NSUndoManager.m:359
2016-09-17 17:25:32.635 main[2925:156856] +[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.
2016-09-17 17:25:32.635 main[2925:156856] (
    0   CoreFoundation                      0x00007fff8802f4f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff8958373c objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff880341ca +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x00007fff90fef856 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
    4   Foundation                          0x00007fff90f74af1 +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 170
    5   AppKit                              0x00007fff9319ae22 -[NSApplication run] + 844
    6   main                                0x0000000004356d30 nativeLoop + 128
    7   main                                0x00000000043566fa _cgo_8c6479959095_Cfunc_nativeLoop + 26
    8   main                                0x000000000405de80 runtime.asmcgocall + 112
)
2016-09-17 17:25:32.636 main[2925:156856] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1259/Misc.subproj/NSUndoManager.m:359
2016-09-17 17:25:32.636 main[2925:156856] An uncaught exception was raised
2016-09-17 17:25:32.636 main[2925:156856] +[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.
2016-09-17 17:25:32.636 main[2925:156856] (
    0   CoreFoundation                      0x00007fff8802f4f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff8958373c objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff880341ca +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x00007fff90fef856 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
    4   Foundation                          0x00007fff90f74af1 +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 170
    5   AppKit                              0x00007fff9319aebe -[NSApplication run] + 1000
    6   main                                0x0000000004356d30 nativeLoop + 128
    7   main                                0x00000000043566fa _cgo_8c6479959095_Cfunc_nativeLoop + 26
    8   main                                0x000000000405de80 runtime.asmcgocall + 112
)
2016-09-17 17:25:32.636 main[2925:156856] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff8802f4f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff8958373c objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff880341ca +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x00007fff90fef856 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
    4   Foundation                          0x00007fff90f74af1 +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 170
    5   AppKit                              0x00007fff9319aebe -[NSApplication run] + 1000
    6   main                                0x0000000004356d30 nativeLoop + 128
    7   main                                0x00000000043566fa _cgo_8c6479959095_Cfunc_nativeLoop + 26
    8   main                                0x000000000405de80 runtime.asmcgocall + 112
)
libc++abi.dylib: terminating with uncaught exception of type NSException
SIGABRT: abort
PC=0x7fff97404f06 m=4
signal arrived during cgo execution

goroutine 21 [syscall, locked to thread]:
runtime.cgocall(0x43566e0, 0xc82004fe38, 0xc800000000)
    /usr/local/Cellar/go/1.6/libexec/src/runtime/cgocall.go:123 +0x11b fp=0xc82004fe10 sp=0xc82004fde0
github.com/niels-s/alfa-drive/vendor/github.com/getlantern/systray._Cfunc_nativeLoop(0x0)
    github.com/niels-s/alfa-drive/vendor/github.com/getlantern/systray/_obj/_cgo_gotypes.go:76 +0x45 fp=0xc82004fe38 sp=0xc82004fe10
github.com/niels-s/alfa-drive/vendor/github.com/getlantern/systray.nativeLoop()
    /Users/niels/workspace/go/src/github.com/niels-s/alfa-drive/vendor/github.com/getlantern/systray/systray_nonwindows.go:19 +0x18 fp=0xc82004fe48 sp=0xc82004fe38
github.com/niels-s/alfa-drive/vendor/github.com/getlantern/systray.Run(0x45954f8)
    /Users/niels/workspace/go/src/github.com/niels-s/alfa-drive/vendor/github.com/getlantern/systray/systray.go:56 +0xa0 fp=0xc82004fe70 sp=0xc82004fe48
github.com/niels-s/alfa-drive/ui.RunSystrayMenu(0xc8200f2160, 0x45954e8, 0x45954e0)
    /Users/niels/workspace/go/src/github.com/niels-s/alfa-drive/ui/gui.go:20 +0x4c fp=0xc82004fe88 sp=0xc82004fe70
main.(*program).run(0x472dbe0)
    /Users/niels/workspace/go/src/github.com/niels-s/alfa-drive/main.go:77 +0x525 fp=0xc82004ff98 sp=0xc82004fe88
runtime.goexit()
    /usr/local/Cellar/go/1.6/libexec/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc82004ffa0 sp=0xc82004ff98
created by main.(*program).Start
    /Users/niels/workspace/go/src/github.com/niels-s/alfa-drive/main.go:47 +0x41

goroutine 25 [chan receive]:
github.com/niels-s/alfa-drive/vendor/github.com/getlantern/systray.Run.func1(0x45954f8)
    /Users/niels/workspace/go/src/github.com/niels-s/alfa-drive/vendor/github.com/getlantern/systray/systray.go:52 +0x38
created by github.com/niels-s/alfa-drive/vendor/github.com/getlantern/systray.Run
    /Users/niels/workspace/go/src/github.com/niels-s/alfa-drive/vendor/github.com/getlantern/systray/systray.go:54 +0x9b

rax    0x0
rbx    0x6
rcx    0x700000185518
rdx    0x0
rdi    0xf03
rsi    0x6
rbp    0x700000185540
rsp    0x700000185518
r8     0x3
r9     0x7fff8e92ee4c
r10    0x8000000
r11    0x206
r12    0x7000001856a0
r13    0x601c020
r14    0x700000187000
r15    0x700000185580
rip    0x7fff97404f06
rflags 0x206
cs     0x7
fs     0x0
gs     0x0
exit status 2

systray.SetTitle("Awesome App") doesn't work

Doesn't show text "Awesome App". OS WIN10 x64

GOROOT=E:\Go #gosetup
GOPATH=C:\Users\adept\go #gosetup
E:\Go\bin\go.exe build -i -ldflags -H=windowsgui -o E:\Projects\TestCompile\go_build_TestTimeGo_.exe . #gosetup
"E:\Program Files\JetBrains\GoLand 2018.3.5\bin\runnerw64.exe" E:\Projects\TestCompile\go_build_TestTimeGo_.exe -i -ldflags -H=windowsgui #gosetup
runnerw.exe: AttachConsole failed with error 6: The handle is invalid.

Dynamic icon support

Is it possible to make a dynamic tray icon which will be painted during runtime?

Doesn't work with go modules

I imported systray into a blank application using go 1.11 modules.

I get the error

go: finding github.com/getlantern/systray latest
build bitbucket.org/e-liminality/testguistuff: cannot find module for path github.com/getlantern/systray

I'm not sure if this is an issue with systray or with go modules. I found a few of these issues that were caused by go modules bugs but they were all fixed.

Icon size

Hi, I tried to use a .ico with size of 64x64 and it worked on windows but not on Linux (tried Ubuntu 16.04 and Manjaro with Deepin DDE). But changing icon size to 32x32 worked at all environments!

I guess it would worth add this information to README 😃

Detect if there is a system tray

Since gnome 3.26 there is no tray in gnome. AFAIK, currently an application using this library doesn't get any kind of warning or error, the systray menu will just don't exist but the application will run normaly.

It will be nice to have a function on systray to check if the tray exists, to be able to display an error manually and recommend installing topicons or something.

Main thread

Hi!

I want run systray in separate thread, something like this:

go systray.Run(onReady, onExit)
fmt.Println("test1")
time.Sleep(10000 * time.Millisecond)
fmt.Println("test2")

All run as expected on Windows, but crash on MacOS:

bash-3.2$ go build && ./example
test1
2019-06-15 20:51:58.662 example[60748:2170198] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /BuildRoot/Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1575.12/Foundation/Misc.subproj/NSUndoManager.m:361
2019-06-15 20:51:58.663 example[60748:2170198] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff52e0ecfd __exceptionPreprocess + 256
	1   libobjc.A.dylib                     0x00007fff7d4b5a17 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff52e29a1a +[NSException raise:format:arguments:] + 98
	3   Foundation                          0x00007fff550c8c85 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
	4   Foundation                          0x00007fff54ffbcfa +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 473
	5   AppKit                              0x00007fff503d6915 -[NSApplication run] + 916
	6   example                             0x00000000042632e0 nativeLoop + 128
	7   example                             0x00000000042627ea _cgo_67d7e7d56c36_Cfunc_nativeLoop + 26
	8   example                             0x0000000004058aa0 runtime.asmcgocall + 112
)
libc++abi.dylib: terminating with uncaught exception of type NSException
SIGABRT: abort
PC=0x7fff7edbe2c6 m=6 sigcode=0
signal arrived during cgo execution

goroutine 18 [syscall, locked to thread]:
runtime.cgocall(0x42627d0, 0xc000030798, 0xc000076301)
	/usr/local/go/src/runtime/cgocall.go:128 +0x5b fp=0xc000030768 sp=0xc000030730 pc=0x4004f9b
github.com/getlantern/systray._Cfunc_nativeLoop(0x0)
	_cgo_gotypes.go:107 +0x49 fp=0xc000030798 sp=0xc000030768 pc=0x4260dd9
github.com/getlantern/systray.nativeLoop(...)
	/Users/nightman/go/src/github.com/getlantern/systray/systray_nonwindows.go:19
github.com/getlantern/systray.Run(0x430ed48, 0x430ed30)
	/Users/nightman/go/src/github.com/getlantern/systray/systray.go:81 +0x7f fp=0xc0000307d0 sp=0xc000030798 pc=0x426071f
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc0000307d8 sp=0xc0000307d0 pc=0x4059301
created by main.main
	/Users/nightman/Downloads/1/systray-master/example/main.go:21 +0x51

goroutine 1 [sleep]:
runtime.goparkunlock(...)
	/usr/local/go/src/runtime/proc.go:307
time.Sleep(0x2540be400)
	/usr/local/go/src/runtime/time.go:105 +0x159
main.main()
	/Users/nightman/Downloads/1/systray-master/example/main.go:23 +0xbd

goroutine 34 [chan receive]:
github.com/getlantern/systray.Run.func2(0xc00011c000, 0x430ed48)
	/Users/nightman/go/src/github.com/getlantern/systray/systray.go:66 +0x34
created by github.com/getlantern/systray.Run
	/Users/nightman/go/src/github.com/getlantern/systray/systray.go:65 +0xf1

rax    0x0
rbx    0x70000ac4b000
rcx    0x70000ac49488
rdx    0x0
rdi    0xb03
rsi    0x6
rbp    0x70000ac494c0
rsp    0x70000ac49488
r8     0x70000ac49350
r9     0x70000ac49520
r10    0x0
r11    0x206
r12    0xb03
r13    0x3000000008
r14    0x6
r15    0x2d
rip    0x7fff7edbe2c6
rflags 0x206
cs     0x7
fs     0x0
gs     0x0

Can you help?

not working in Fedora 25

In Fedora 25 (Gnome3) the tray icon does not show up. I have installed topicons extension, and other tray icons are shown (slack for example).

I don't know if it is gnome3 or wayland related.

If the system tray could not be created, return an error instead of terminating the process.

When a Go program calls systray.Run() in a headless environment, creating the system tray fails.

Expected behavior:
If creating the system tray fails, the call to systray.Run() should return an error.

Actual behavior:
The call to systray.Run() terminates the process if it failed to create the system tray.

This would still be okay, if there would be a call like systray.IsHeadless() which could be used to check upfront whether running the system tray is actually possible.

Workarounds:

  • Provide a --headless command line option to the program that uses the system tray.
  • Use the following function, which isn't perfect but will do the job on a lot of platforms:
func IsHeadless() bool {
    _, display := os.LookupEnv("DISPLAY")
    return runtime.GOOS != "windows" && !display
}

Colour or Icon On Menu Item

I'm trying to use systray as a monitoring notifier for my local and production databases and wanted to know if it's currently possible to add icons or colour to the menu items?

On click tray event ?

Currently, left-clicking on the tray icon simply opens the menu on Windows, and do nothing on Linux.
Is it possible to trigger sometime on icon left-click ?

Quit() doesn't exit on linux

A simple example:

package main

import (
        "fmt"

        "github.com/getlantern/systray"
)

func main() {
        systray.Run(onReady, onExit)
}

func onReady() {
        systray.Quit()
}

func onExit() {
        fmt.Println("exiting now")
}

It hangs for ever and never prints exiting now.

Feature request: support retina display for OS X

Systray only uses the same icon for both normal and retina display which makes systray icon looks not smooth for retina display.
To support retina display icon, it may need to update some OC codes. As I am not a OC programmer, hope someone will implement it.

Feature Request: Menu Separators

I'm looking into getting this project compiling locally, having trouble with VS2008. I would love menu separator support though.

Warning on running program

(yourprogramnamehere:987): Gdk-CRITICAL **: gdk_window_thaw_toplevel_updates: assertion 'window->update_and_descendants_freeze_count > 0' failed

Icon problem that overloads the disk

Hello,
have you ever had problems with the dynamically changing icons that fills the temp folder and the disk on windows and linux? thank you for reply.

Run(...)/nativeloop blocks forever on all platforms

None of the platform specific implementations obey this description since they all block forever:

// Run initializes GUI and starts the event loop, then invokes the onReady
// 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()) {}

I'm not sure if some or all of these just moves the race condition I'm trying to avoid (program exists before teardown of native GUI finishes) but It works much better now... I'm in a bit of a hurry so I will recheck these solutions at a later point.

possible gtk solution

Adding this call to the do_quit function:

    gtk_main_quit();

possible objc solution

Adding this call to the quit function:

  [NSApp terminate:self];

possible windows solution

Something like this for windows, maybe, I just did it as fast as I could and I don't speak winapi at all.

#define WM_DONE (WM_USER + 2)


int nativeLoop(void) {
    HINSTANCE hInstance = GetModuleHandle(NULL);
    TCHAR* szWindowClass = TEXT("SystrayClass");
    MSG msg;
    MyRegisterClass(hInstance, szWindowClass);
    hWnd = InitInstance(hInstance, FALSE, szWindowClass); // Don't show window
    if (!hWnd) {
        return EXIT_FAILURE;
    }
    if (!createMenu() || !addNotifyIcon()) {
        return EXIT_FAILURE;
    }
    systray_ready(0);

    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        if (msg.message == WM_DONE) {
          return EXIT_SUCCESS;
        };
        DispatchMessage(&msg);
    }
    return EXIT_SUCCESS;
}

void quit() {
    Shell_NotifyIcon(NIM_DELETE, &nid);
    PostMessage (hWnd, WM_DONE, 0,  0);

}

Right mouse button click

Hi,

Is it possible to show the menu only if the user click with the right mouse button?

Thanks,
Felipe

Error compiling from Linux for Darwin

# github.com/vcraescu/holy-internet/vendor/github.com/getlantern/systray
vendor/github.com/getlantern/systray/systray.go:81:2: undefined: nativeLoop
vendor/github.com/getlantern/systray/systray.go:87:3: undefined: quit
vendor/github.com/getlantern/systray/systray.go:105:2: undefined: addSeparator
vendor/github.com/getlantern/systray/systray.go:139:2: undefined: hideMenuItem
vendor/github.com/getlantern/systray/systray.go:144:2: undefined: showMenuItem
vendor/github.com/getlantern/systray/systray.go:169:2: undefined: addOrUpdateMenuItem

Any idea?

Thanks!

How do I compile to output 386 Binary file on amd64 arch Linux(ubuntu14)

such as your example,
I do this on the command line:

export GOARCH=386
go build

However,display on command line:

# github.com/getlantern/systray
/root/go/src/github.com/getlantern/systray/systray.go:81:2: undefined: nativeLoop
/root/go/src/github.com/getlantern/systray/systray.go:87:3: undefined: quit
/root/go/src/github.com/getlantern/systray/systray.go:105:2: undefined: addSeparator
/root/go/src/github.com/getlantern/systray/systray.go:139:2: undefined: hideMenuItem
/root/go/src/github.com/getlantern/systray/systray.go:144:2: undefined: showMenuItem
/root/go/src/github.com/getlantern/systray/systray.go:169:2: undefined: addOrUpdateMenuItem

[windows] if several menu items are hidden, showing them gets the absolute index

this might be a corner case, but it's actually a case we're using that's buggy on windows:

  1. Have several adjacent menu items hidden right from the beginning.
  2. when one of them is shown, the position in which the item is aded (being absolute) can be below menu items that were added afterwards.

I'm unsure about what strategy will be better to cope with this. I was thinking about adding a public method to optionally force a menuID.

here's a snippet that demonstrates this:

package main

import (
        "fmt"
        "io/ioutil"
        "time"

        "github.com/getlantern/systray"
        "github.com/getlantern/systray/example/icon"
)

func main() {
        onExit := func() {
                fmt.Println("Starting onExit")
                now := time.Now()
                ioutil.WriteFile(fmt.Sprintf(`on_exit_%d.txt`, now.UnixNano()), []byte(now.String()), 0644)
                fmt.Println("Finished onExit")
        }
        systray.Run(onReady, onExit)
}

func onReady() {
        systray.SetIcon(icon.Data)
        systray.SetTitle("Awesome App")
        systray.SetTooltip("Lantern")
        mQuitOrig := systray.AddMenuItem("Quit", "Quit the whole app")


        mHidden1 := systray.AddMenuItem("Hide1", "Hide 1")
        mHidden1.Hide()
        mHidden2 := systray.AddMenuItem("Hide2", "Hide 2")
        mHidden2.Hide()
        mHidden3 := systray.AddMenuItem("Hide3", "Hide 3")
        mHidden3.Hide()

        mDummy := systray.AddMenuItem("hide button should be above me", "dummy button")
        mDummy.SetTooltip("dummy button")


        go func() {
                <-mQuitOrig.ClickedCh
                fmt.Println("Requesting quit")
                systray.Quit()
                fmt.Println("Finished quitting")
        }()

        go func() {
                systray.SetIcon(icon.Data)
                systray.SetTitle("Awesome App")
                systray.AddSeparator()

                mShowHide := systray.AddMenuItem("Show", "Show/Hide a few menu items")
                shown := false
                for {
                        select {
                        case <-mShowHide.ClickedCh:
                                if shown {
                                        mShowHide.SetTitle("Show")
                                        mShowHide.SetTooltip("Show previously hidden menu items")
                                        mHidden3.Hide()
                                        shown = false
                                } else {
                                        mShowHide.SetTitle("Hide")
                                        mShowHide.SetTooltip("Hide a few menu items")
                                        mHidden3.Show()
                                        shown = true
                                }
                        }
                }
        }()
}

Can systray.Run be run as a separate process using exec.Command or syscall.ForkExec

I want to run the system tray as a stand alone process that does its own thing, but it needs to be run form a different program.
example:

$ systemtray    #binary built from the example code
#This will run the system tray but will block the terminal,
#I need this command to be run on a different process/thread so that the terminal is freed, and it keeps running in the background

Cannot build for OSX from Linux

I have a little app to which I have added this; it builds fine for Linux and Windows, but on attempting to compile for Darwin I get this:

Can't build package github.com/getlantern/systray because it contains Objective-C files (systray_darwin.m) but it's not using cgo nor SWIG

I'm pretty sure that last part is not true. Is this something previously seen?

Multiple Icons

Currently we only have one setIcon method. It could be great if we could make multiple tray icons or is it already possible?

Clean up dlls after on systray.Quit()

Hello.
I wanted to ask if it would be possible to delte the dlls in appdata when you run systray.Quit()
i had this code in the systray.Quit function before but it didn't work because for some reason the files were still in use.

    err := os.RemoveAll(dllDir)
    if err != nil {
        log.Debugf("Unable to delete temporary dll directory %v: %v", err)
    }

Testing and jumpy rendering

Hi!

First of all thanks for this package! Having this functionality for all three platforms is awesome! Some background: I adopted and later forked a small jsonrpc-like utility that uses this library after it was introduced into one of the dependencies of ssb in the form of a npm module (now forked-systray).

I noticed some inconsistencies in the API that is exposed through the json interface and so began to add some tests to the helper go binary. They use xvfb, i3 and xdotool to facilitate clicking. The code can be found here: ssbc/systrayhelper#3 I also added code that uses ffmpeg to dump the test session. Here is the current setup in action:
https://giphy.com/gifs/82ukpSHCHSlzOEJbRl/html5 It basically inits from test.json and then goes on and clicks on entries. When these get clicked the test runner changes title and properties like enabled, etc.
I was wondering if this kind of test-setup would be of interest for this package by itself. I'd be totally willing to contribute it back if so.

Now for the bad news:

  • Sometimes when the title text get's longer or shorter, the width of the whole menu changes and jumps around. This can be seen in the giphy link after check new title is clicked. The whole menu is moved off to the left. I added clicking three times on the menu to work around this but it's not something I like to tell my users.
  • A similar effect can be seen when AddMenuItem is called after initialization. The append entry appears to be in a scrolling list when the menu activates for the first time after the change.
  • Lastly it seems like Show and Hide don't have an effect on Linux? Could that be?

Additionally I'd like to help with #60 and #49 but would prefer to have some tests before and wanted some feedback on the above first.

failing to hide menu items

I find many situations where hiding a menu item doesn't work. I'm testing it debian (using gtk+ 3.22.26), but I could reproduce the same problem in ubuntu 17.10.

The minimum example I found that doesn't work for me is:

package main

import (
	"github.com/getlantern/systray"
)

func main() {
	systray.Run(onReady, func() {})
}

func onReady() {
	m := systray.AddMenuItem("foo", "")
	m.Hide()
	systray.AddMenuItem("bar", "")
}

Weirdly if I remove the 'bar' AddMenuItem it works and hides foo.

Pop-up or Notify?

Is it possible for a timer or other event to trigger a notification. Looking for something that would bounce the icon, change the icon, or otherwise notify the user something has changed.

Systray application panics on linux after screen lock

Hello, I have got some issue with my server-like application built with systray package. The application often hangs with SEGFAULT after ubuntu does screen lock.
Ubuntu: 18.10 amd64, default Gnome desktop
Golang: 1.10

Here is a piece of panic message:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xfe00 pc=0x7eff6c9db254]

runtime stack:
runtime.throw(0x99c338, 0x2a)
/usr/lib/go-1.10/src/runtime/panic.go:616 +0x81
runtime.sigpanic()
/usr/lib/go-1.10/src/runtime/signal_unix.go:372 +0x28e

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x8746c0, 0xc420069bd0, 0x42b5d8)
/usr/lib/go-1.10/src/runtime/cgocall.go:128 +0x64 fp=0xc420069ba0 sp=0xc420069b68 pc=0x41c2d4
github.com/getlantern/systray._Cfunc_nativeLoop(0xc400000000)
_cgo_gotypes.go:117 +0x49 fp=0xc420069bd0 sp=0xc420069ba0 pc=0x82b0e9
github.com/getlantern/systray.nativeLoop()
/home/grubian/go/src/github.com/getlantern/systray/systray_nonwindows.go:19 +0x22 fp=0xc420069be8 sp=0xc420069bd0 pc=0x82b6a2
github.com/getlantern/systray.Run(0xc4200990e0, 0x9a8db0)
/home/grubian/go/src/github.com/getlantern/systray/systray.go:81 +0x77 fp=0xc420069c20 sp=0xc420069be8 pc=0x82a677
main.main.func1(0xc4200f2580)

Maybe I have got some issues with my GTK environment or something else, but if this is a real issue affecting many users it should be fixed.

Example or info how to run Systray as a service in Windows

Hi there,

I'm looking around to see if I can find a solution to run my go binary as a service in windows. I've tried a couple things already:

  1. I've tried using this go lib to setup a service but unfortunately this won't work nicely together with Systray since we need to start the ui in main: github.com/kardianos/service
  2. Another approach I've tried is NSSM. While is was able to register a simple dummy go app printing a message every 5 seconds. NSSM doesn't play nice with Systray.

I'm hoping some of you can share you experiences on how you run you app's as a service on Windows in combination with Systray.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.