2020-08-25 22:55:05 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-08-28 22:33:03 +00:00
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/gdamore/tcell"
|
|
|
|
"github.com/rivo/tview"
|
2020-08-25 22:55:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-08-28 22:33:03 +00:00
|
|
|
// fim placeholder so we can operate on it when a signal is received
|
|
|
|
var fim *exec.Cmd = nil
|
|
|
|
|
|
|
|
// Setup signal listening
|
|
|
|
sigs := make(chan os.Signal)
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
defer func() { close(sigs) }()
|
|
|
|
|
|
|
|
// Goroutine to handle os signals (nuke fim so we can get to config ui)
|
|
|
|
go func() {
|
2020-08-29 00:02:38 +00:00
|
|
|
for range sigs {
|
2020-08-28 22:33:03 +00:00
|
|
|
if fim != nil { // Just in case someone lays on ctrl-c or similar during startup
|
|
|
|
if err := fim.Process.Kill(); err != nil {
|
2020-08-29 00:02:38 +00:00
|
|
|
log.Fatalf("failed to kill process: %s", err)
|
2020-08-28 22:33:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2020-08-25 22:55:05 +00:00
|
|
|
|
2020-08-28 22:33:03 +00:00
|
|
|
// Forever run slideshow / show ui as the main program executed on a PiFrame
|
2020-08-25 22:55:05 +00:00
|
|
|
for {
|
2020-08-28 22:33:03 +00:00
|
|
|
// Run slideshow
|
2020-08-28 22:40:33 +00:00
|
|
|
fim = exec.Command("/usr/local/bin/pf-fim.sh")
|
2020-08-28 22:33:03 +00:00
|
|
|
if err := fim.Run(); err != nil {
|
|
|
|
// Unwrap the error a bit so we can find out if a signal killed fim or something else
|
|
|
|
// An exit code of -1 means the program didn't exit in time or was terminated by a signal (per the docs)
|
|
|
|
if exitError, ok := err.(*exec.ExitError); ok && exitError.ExitCode() != -1 {
|
2020-08-29 00:02:38 +00:00
|
|
|
log.Fatalf("Error : %s", err)
|
2020-08-28 22:33:03 +00:00
|
|
|
}
|
2020-08-26 00:18:29 +00:00
|
|
|
}
|
2020-08-25 22:55:05 +00:00
|
|
|
|
2020-08-28 22:33:03 +00:00
|
|
|
// Run config UI when slideshow stops
|
|
|
|
app := tview.NewApplication()
|
|
|
|
frame := tview.NewFrame(tview.NewBox().SetBackgroundColor(tcell.ColorBlack)).
|
|
|
|
SetBorders(2, 2, 2, 2, 4, 4).
|
|
|
|
AddText("PiFrame", true, tview.AlignCenter, tcell.ColorWhite).
|
|
|
|
AddText("Configuration Utility", true, tview.AlignCenter, tcell.ColorRed)
|
|
|
|
if err := app.SetRoot(frame, true).EnableMouse(true).Run(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2020-08-25 22:55:05 +00:00
|
|
|
}
|
|
|
|
}
|