|
| 1 | +/* |
| 2 | + * This file is part of arduino-create-agent. |
| 3 | + * |
| 4 | + * arduino-create-agent is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | + * |
| 18 | + * As a special exception, you may use this file as part of a free software |
| 19 | + * library without restriction. Specifically, if other files instantiate |
| 20 | + * templates or use macros or inline functions from this file, or you compile |
| 21 | + * this file and link it with other files to produce an executable, this |
| 22 | + * file does not by itself cause the resulting executable to be covered by |
| 23 | + * the GNU General Public License. This exception does not however |
| 24 | + * invalidate any other reasons why the executable file might be covered by |
| 25 | + * the GNU General Public License. |
| 26 | + * |
| 27 | + * Copyright 2017 BCMI LABS SA (http://www.arduino.cc/) |
| 28 | + */ |
| 29 | +package main |
| 30 | + |
| 31 | +import ( |
| 32 | + "runtime" |
| 33 | + |
| 34 | + "github.com/arduino/arduino-create-agent/icon" |
| 35 | + "github.com/getlantern/systray" |
| 36 | + "github.com/skratchdot/open-golang/open" |
| 37 | +) |
| 38 | + |
| 39 | +func setupSystray(hybernate bool, version, revision string, shutdown func()) { |
| 40 | + runtime.LockOSThread() |
| 41 | + if !hybernate { |
| 42 | + systray.Run(setupSystrayReal(version, revision, shutdown)) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +func setupSystrayReal(version, revision string, shutdown func()) func() { |
| 47 | + return func() { |
| 48 | + systray.SetIcon(icon.GetIcon()) |
| 49 | + mURL := systray.AddMenuItem("Go to Arduino Create", "Arduino Create") |
| 50 | + mDebug := systray.AddMenuItem("Open debug console", "Debug console") |
| 51 | + menuVer := systray.AddMenuItem("Agent version "+version+"-"+revision, "") |
| 52 | + mPause := systray.AddMenuItem("Pause Plugin", "") |
| 53 | + |
| 54 | + menuVer.Disable() |
| 55 | + |
| 56 | + // Listen for events |
| 57 | + go func() { |
| 58 | + for { |
| 59 | + select { |
| 60 | + case <-mPause.ClickedCh: |
| 61 | + shutdown() |
| 62 | + // TODO: Restart ? |
| 63 | + case <-mDebug.ClickedCh: |
| 64 | + open.Start("http://localhost:9000") |
| 65 | + case <-mURL.ClickedCh: |
| 66 | + open.Start("https://create.arduino.cc") |
| 67 | + } |
| 68 | + } |
| 69 | + }() |
| 70 | + } |
| 71 | +} |
0 commit comments