Skip to content

Commit aebddcf

Browse files
committed
Added default time again, and setup build for tray app
1 parent 7f7de9a commit aebddcf

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ https://twitter.com/
2323
```
2424

2525
and Grif will Ping the hosts that begin with icmp:// and test for a valid http response from the hosts with HTTP or HTTPS. Grif can also validate SSL if desired (this feature is being tested).
26+
27+
28+
## Building Grif
29+
30+
In the main directory of this project run
31+
32+
```
33+
go build -ldflags -H=windowsgui -o build/grif.exe
34+
```
35+
36+
The files in the repo are already generated and in place to ensure the exe is built fully, with icon, manifest, etc.

grif.go

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ import (
1717
"github.com/faiface/beep/speaker"
1818
"github.com/gen2brain/beeep"
1919
"github.com/sparrc/go-ping"
20+
"github.com/getlantern/systray"
2021
)
2122

2223
// Length in seconds between each cycle of checks
23-
var wait time.Duration = 60
24+
var wait time.Duration = 3
2425
var checking = false
2526

2627
func main() {
@@ -31,13 +32,18 @@ func main() {
3132
fmt.Println("Administrator command prompt achieved")
3233
}
3334
checkAndCreateHostsFile()
34-
fmt.Print("Enter number of seconds to wait between checking all hosts: ")
35-
var i int
36-
_, err := fmt.Scanf("%d", &i)
37-
if err != nil {
38-
log.Fatal(err)
39-
}
40-
wait = time.Duration(i)
35+
36+
// Code to ask amount of delay
37+
//
38+
//fmt.Print("Enter number of seconds to wait between checking all hosts: ")
39+
//var i int
40+
//_, err := fmt.Scanf("%d", &i)
41+
//if err != nil {
42+
// log.Fatal(err)
43+
//}
44+
//wait = time.Duration(i)
45+
46+
systray.Run(onReady, onExit)
4147
for range time.Tick(wait * time.Second) {
4248
if !checking {
4349
go checkHosts()
@@ -47,6 +53,34 @@ func main() {
4753
}
4854
}
4955

56+
func onReady() {
57+
systray.SetIcon(getIcon("assets/grif.ico"))
58+
systray.SetTitle("Grif")
59+
systray.SetTooltip("Grif is running")
60+
mQuit := systray.AddMenuItem("Quit", "Quits Grif")
61+
go func() {
62+
for {
63+
select {
64+
case <-mQuit.ClickedCh:
65+
systray.Quit()
66+
return
67+
}
68+
}
69+
}()
70+
}
71+
72+
func onExit() {
73+
// Cleaning stuff here.
74+
}
75+
76+
func getIcon(s string) []byte {
77+
b, err := ioutil.ReadFile(s)
78+
if err != nil {
79+
fmt.Print(err)
80+
}
81+
return b
82+
}
83+
5084
func checkHosts() {
5185
checking = true
5286
fmt.Println("Checking hosts...")

0 commit comments

Comments
 (0)