Этот коммит содержится в:
Igor V Belousov 2017-06-16 21:15:12 +03:00
родитель 81570ae347
Коммит b7622da583

49
main.go
Просмотреть файл

@ -25,6 +25,12 @@ func get_ip() (string, error) {
return ip, err return ip, err
} }
func err_fatal(err error) {
if err != nil {
log.Fatal(err)
}
}
var old_ip string var old_ip string
func main() { func main() {
@ -33,37 +39,24 @@ func main() {
defer single_proc.Unlock() defer single_proc.Unlock()
mw, err := walk.NewMainWindow() mw, err := walk.NewMainWindow()
if err != nil { err_fatal(err)
log.Fatal(err)
}
icon, err := walk.NewIconFromResourceId(9) icon, err := walk.NewIconFromResourceId(9)
if err != nil { err_fatal(err)
log.Fatal(err)
}
ni, err := walk.NewNotifyIcon() ni, err := walk.NewNotifyIcon()
if err != nil { err_fatal(err)
log.Fatal(err)
}
defer ni.Dispose() defer ni.Dispose()
if err := ni.SetIcon(icon); err != nil { err_fatal(ni.SetIcon(icon))
log.Fatal(err)
}
exitAction := walk.NewAction() exitAction := walk.NewAction()
if err := exitAction.SetText("E&xit"); err != nil { err_fatal(exitAction.SetText("E&xit"))
log.Fatal(err)
}
exitAction.Triggered().Attach(func() { walk.App().Exit(0) })
if err := ni.ContextMenu().Actions().Add(exitAction); err != nil {
log.Fatal(err)
}
if err := ni.SetVisible(true); err != nil { exitAction.Triggered().Attach(func() { walk.App().Exit(0) })
log.Fatal(err) err_fatal(ni.ContextMenu().Actions().Add(exitAction))
}
err_fatal(ni.SetVisible(true))
go func() { go func() {
first_loop := true first_loop := true
@ -72,12 +65,10 @@ func main() {
if ip_err == nil { if ip_err == nil {
first_loop = false first_loop = false
old_ip = ip old_ip = ip
if err := ni.ShowCustom( err_fatal(ni.ShowCustom(
"IP Checker", "IP Checker",
" Current IP is "+old_ip); err != nil { " Current IP is "+old_ip))
log.Fatal(err)
}
go func() { go func() {
for { for {
@ -85,12 +76,10 @@ func main() {
ip, ip_err := get_ip() ip, ip_err := get_ip()
if ip_err == nil { if ip_err == nil {
if old_ip != ip { if old_ip != ip {
if err := ni.ShowCustom( err_fatal(ni.ShowCustom(
"IP Checker", "IP Checker",
" Old IP - "+old_ip+" New IP - "+ip); err != nil { " Old IP - "+old_ip+" New IP - "+ip))
log.Fatal(err)
}
old_ip = ip old_ip = ip
} }
} }