diff options
| author | Ox Cart | 2016-03-17 10:43:40 -0500 | 
|---|---|---|
| committer | Ox Cart | 2016-03-17 10:43:40 -0500 | 
| commit | 8e63b37ef27d94f6db79c4ffb941608e8f0dc2f9 (patch) | |
| tree | dc372118a147dc0a9d6b6d19d36430e9c9dcf765 /example/main.go | |
| download | systray-8e63b37ef27d94f6db79c4ffb941608e8f0dc2f9.tar.bz2 | |
Squashed commits, full commit log available in https://github.com/getlantern/lantern
Diffstat (limited to 'example/main.go')
| -rw-r--r-- | example/main.go | 61 | 
1 files changed, 61 insertions, 0 deletions
| diff --git a/example/main.go b/example/main.go new file mode 100644 index 0000000..01b9ee8 --- /dev/null +++ b/example/main.go @@ -0,0 +1,61 @@ +package main + +import ( +	"fmt" +	"github.com/getlantern/systray" +	"github.com/getlantern/systray/example/icon" +	"github.com/skratchdot/open-golang/open" +) + +func main() { +	// Should be called at the very beginning of main(). +	systray.Run(onReady) +} + +func onReady() { +	systray.SetIcon(icon.Data) +	systray.SetTitle("Awesome App") +	systray.SetTooltip("Lantern") +	mQuit := systray.AddMenuItem("Quit", "Quit the whole app") +	go func() { +		<-mQuit.ClickedCh +		systray.Quit() +		fmt.Println("Quit now...") +	}() + +	// We can manipulate the systray in other goroutines +	go func() { +		systray.SetIcon(icon.Data) +		systray.SetTitle("Awesome App") +		systray.SetTooltip("Pretty awesome棒棒嗒") +		mChange := systray.AddMenuItem("Change Me", "Change Me") +		mChecked := systray.AddMenuItem("Unchecked", "Check Me") +		mEnabled := systray.AddMenuItem("Enabled", "Enabled") +		systray.AddMenuItem("Ignored", "Ignored") +		mUrl := systray.AddMenuItem("Open Lantern.org", "my home") +		mQuit := systray.AddMenuItem("退出", "Quit the whole app") +		for { +			select { +			case <-mChange.ClickedCh: +				mChange.SetTitle("I've Changed") +			case <-mChecked.ClickedCh: +				if mChecked.Checked() { +					mChecked.Uncheck() +					mChecked.SetTitle("Unchecked") +				} else { +					mChecked.Check() +					mChecked.SetTitle("Checked") +				} +			case <-mEnabled.ClickedCh: +				mEnabled.SetTitle("Disabled") +				mEnabled.Disable() +			case <-mUrl.ClickedCh: +				open.Run("https://www.getlantern.org") +			case <-mQuit.ClickedCh: +				systray.Quit() +				fmt.Println("Quit2 now...") +				return +			} +		} +	}() +} | 
