init
This commit is contained in:
66
main.go
Normal file
66
main.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/getlantern/systray"
|
||||
"github.com/kbinani/screenshot"
|
||||
"image/png"
|
||||
"os"
|
||||
)
|
||||
|
||||
var window *ui.Window
|
||||
|
||||
func main() {
|
||||
go func() {
|
||||
systray.Run(onReady, onExit)
|
||||
}()
|
||||
|
||||
<-make(chan struct{})
|
||||
}
|
||||
|
||||
func onReady() {
|
||||
systray.SetTitle("Awesome App")
|
||||
systray.SetTooltip("Pretty awesome超级棒")
|
||||
screenshot := systray.AddMenuItem("Screenshot", "Take a screenshot")
|
||||
config := systray.AddMenuItem("Config", "Configuration")
|
||||
quit := systray.AddMenuItem("Quit", "Quit the whole app")
|
||||
|
||||
go func() {
|
||||
<-quit.ClickedCh
|
||||
systray.Quit()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-screenshot.ClickedCh:
|
||||
takeScreenShot()
|
||||
case <-config.ClickedCh:
|
||||
go showConfig()
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func onExit() {
|
||||
fmt.Println("exit")
|
||||
}
|
||||
|
||||
func takeScreenShot() {
|
||||
n := screenshot.NumActiveDisplays()
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
bounds := screenshot.GetDisplayBounds(i)
|
||||
|
||||
img, err := screenshot.CaptureRect(bounds)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fileName := fmt.Sprintf("%d_%dx%d.png", i, bounds.Dx(), bounds.Dy())
|
||||
file, _ := os.Create(fileName)
|
||||
defer file.Close()
|
||||
png.Encode(file, img)
|
||||
|
||||
fmt.Printf("#%d : %v \"%s\"\n", i, bounds, fileName)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user