Use xprintidle to stop
This commit is contained in:
parent
9bbe36d2d8
commit
1be401d519
1 changed files with 24 additions and 0 deletions
24
main.go
24
main.go
|
@ -1,11 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/faiface/beep"
|
"github.com/faiface/beep"
|
||||||
|
@ -19,6 +23,22 @@ const (
|
||||||
SampleRate = beep.SampleRate(48000)
|
SampleRate = beep.SampleRate(48000)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func xPrintIdle() (idle uint64) {
|
||||||
|
cmd := exec.Command("xprintidle")
|
||||||
|
cmd.Env = append(os.Environ(), "DISPLAY=:0")
|
||||||
|
var out bytes.Buffer
|
||||||
|
cmd.Stdout = &out
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
} else {
|
||||||
|
s := string(out.Bytes())
|
||||||
|
if idle, err = strconv.ParseUint(strings.TrimSpace(s), 10, 64); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func loadFile(path string) (s beep.Streamer, err error) {
|
func loadFile(path string) (s beep.Streamer, err error) {
|
||||||
var format beep.Format
|
var format beep.Format
|
||||||
|
|
||||||
|
@ -95,6 +115,7 @@ func main() {
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
launched := time.Now()
|
launched := time.Now()
|
||||||
|
idle := xPrintIdle()
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
select{
|
select{
|
||||||
|
@ -105,6 +126,9 @@ loop:
|
||||||
if t.Sub(launched) > 1 * time.Hour {
|
if t.Sub(launched) > 1 * time.Hour {
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
|
if xPrintIdle() < idle {
|
||||||
|
break loop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue