init
This commit is contained in:
commit
543804b23f
|
@ -0,0 +1,4 @@
|
||||||
|
.idea
|
||||||
|
.env.local
|
||||||
|
bin/*
|
||||||
|
additional_envs.sh
|
|
@ -0,0 +1,94 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"os/signal"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||||
|
defer stop()
|
||||||
|
|
||||||
|
cmd := exec.CommandContext(ctx, "dbus-monitor", "--session", "type='signal',interface='org.gnome.ScreenSaver'")
|
||||||
|
cmdReader, err := cmd.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("cmd.StdoutPipe:", err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = cmdReader.Close()
|
||||||
|
}()
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
_ = cmd.Run()
|
||||||
|
}()
|
||||||
|
|
||||||
|
var isScreenSaverActive uint32
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
ticker := time.NewTicker(5 * time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
scanner := bufio.NewScanner(cmdReader)
|
||||||
|
for scanner.Scan() {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
if !strings.Contains(scanner.Text(), "member=ActiveChanged") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !scanner.Scan() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.Contains(scanner.Text(), "boolean true") {
|
||||||
|
atomic.StoreUint32(&isScreenSaverActive, 1)
|
||||||
|
} else {
|
||||||
|
atomic.StoreUint32(&isScreenSaverActive, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
ticker := time.NewTicker(5 * time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
|
if atomic.LoadUint32(&isScreenSaverActive) == 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
_ = sendNotification(ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
log.Println("DONE")
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendNotification(ctx context.Context) error {
|
||||||
|
return exec.CommandContext(ctx, "notify-send", "title", "description").Run()
|
||||||
|
}
|
Loading…
Reference in New Issue