chore: fix bugs with restarting and old files
This commit is contained in:
@@ -61,4 +61,6 @@ RestartSec=2
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
EOF
|
||||
|
||||
chown ${userland_name}:${userland_name} /home/${userland_name}/.config/systemd -R
|
||||
@@ -6,8 +6,8 @@ After=graphical.target
|
||||
Type=simple
|
||||
Environment=DISPLAY=:0
|
||||
WorkingDirectory=/opt/akartontv
|
||||
ExecStartPre=/usr/bin/sleep 5
|
||||
ExecStart=/usr/bin/libreoffice --impress --show /opt/akartontv/presentation.pptx --norestore
|
||||
ExecStartPre=/usr/bin/sleep 3
|
||||
ExecStart=/bin/sh -c 'exec /usr/bin/libreoffice --impress --show --norestore $(find /opt/akartontv/ \( -name "*.pptx" -o -name "*.odp" \))'
|
||||
ExecStop=/usr/bin/killall libreoffice
|
||||
Restart=always
|
||||
Restart=on-failure
|
||||
|
||||
@@ -4,8 +4,10 @@ After=graphical.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Environment=DISPLAY=:0
|
||||
WorkingDirectory=/opt/akartontv
|
||||
ExecStart=/usr/bin/vlc --loop /opt/akartontv/video.mp4 -I dummy --no-video-title
|
||||
ExecStartPre=/usr/bin/sleep 3
|
||||
ExecStart=/bin/sh -c 'exec /usr/bin/vlc --fullscreen --loop -I dummy --no-video-title --no-qt-fs-controller $(find /opt/akartontv/ \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \))'
|
||||
ExecStop=/usr/bin/killall vlc
|
||||
Restart=always
|
||||
Restart=on-failure
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/sftp"
|
||||
@@ -42,6 +43,15 @@ func createSSHClient(targetName string, cfg RaspiConfig) (*ssh.Client, error) {
|
||||
return ssh.Dial("tcp", connAddr, config)
|
||||
}
|
||||
|
||||
func runSSHCommand(client *ssh.Client, cmd string) ([]byte, error) {
|
||||
session, err := client.NewSession()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer session.Close()
|
||||
return session.CombinedOutput(cmd)
|
||||
}
|
||||
|
||||
func verifyCred(targetName string, cfg RaspiConfig) bool {
|
||||
sshClient, err := createSSHClient(targetName, cfg)
|
||||
|
||||
@@ -51,13 +61,18 @@ func verifyCred(targetName string, cfg RaspiConfig) bool {
|
||||
}
|
||||
defer sshClient.Close()
|
||||
|
||||
log.Println("Success!")
|
||||
log.Println("Successfully verified the credentials")
|
||||
return true
|
||||
}
|
||||
|
||||
func sftpUploadFile(targetName, localPath, remotePath string, cfg RaspiConfig) bool {
|
||||
const clearDirectory string = "rm /opt/akartontv/*"
|
||||
|
||||
sshClient, err := createSSHClient(targetName, cfg)
|
||||
|
||||
fExt := filepath.Ext(localPath)
|
||||
remotePath = remotePath + fExt
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Failed to init the SSH connection %v", err)
|
||||
return false
|
||||
@@ -78,12 +93,16 @@ func sftpUploadFile(targetName, localPath, remotePath string, cfg RaspiConfig) b
|
||||
}
|
||||
defer localFile.Close()
|
||||
|
||||
log.Println("Clearing directory")
|
||||
_, err = runSSHCommand(sshClient, clearDirectory)
|
||||
|
||||
remoteFile, err := sftpClient.Create(remotePath)
|
||||
if err != nil {
|
||||
log.Printf("Failed to open remote file handle: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
log.Println("Uploading file")
|
||||
bytesCopied, err := io.Copy(remoteFile, localFile)
|
||||
if err != nil {
|
||||
log.Printf("Failed to copy local file to the remote location: %v", err)
|
||||
@@ -96,9 +115,14 @@ func sftpUploadFile(targetName, localPath, remotePath string, cfg RaspiConfig) b
|
||||
|
||||
func restartShow(targetName string, targetMode int, cfg RaspiConfig) bool {
|
||||
const restartPresentation string = "systemctl --user restart presentation"
|
||||
const restartVideo string = "systemctl --user restart video"
|
||||
var err error
|
||||
const enablePresentation string = "systemctl --user enable presentation"
|
||||
const disablePresentation string = "systemctl --user disable --now presentation"
|
||||
|
||||
const restartVideo string = "systemctl --user restart video"
|
||||
const enableVideo string = "systemctl --user enable video"
|
||||
const disableVideo string = "systemctl --user disable --now video"
|
||||
|
||||
var err error
|
||||
sshClient, err := createSSHClient(targetName, cfg)
|
||||
|
||||
if err != nil {
|
||||
@@ -114,12 +138,17 @@ func restartShow(targetName string, targetMode int, cfg RaspiConfig) bool {
|
||||
}
|
||||
defer session.Close()
|
||||
|
||||
var output []byte
|
||||
switch targetMode {
|
||||
case 1:
|
||||
output, err = session.CombinedOutput(restartPresentation)
|
||||
log.Println("Configuring application workflow: Presentation")
|
||||
_, err = runSSHCommand(sshClient, restartPresentation)
|
||||
_, err = runSSHCommand(sshClient, disableVideo)
|
||||
_, err = runSSHCommand(sshClient, enablePresentation)
|
||||
case 2:
|
||||
output, err = session.CombinedOutput(restartVideo)
|
||||
log.Println("Configuring application workflow: Video")
|
||||
_, err = runSSHCommand(sshClient, restartVideo)
|
||||
_, err = runSSHCommand(sshClient, disablePresentation)
|
||||
_, err = runSSHCommand(sshClient, enableVideo)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -127,6 +156,6 @@ func restartShow(targetName string, targetMode int, cfg RaspiConfig) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
log.Println(string(output))
|
||||
log.Println("Done reloading program!")
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"image/color"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
@@ -246,8 +245,7 @@ func drawFileSelection(localPath *string, targetMode *int, parentWindow fyne.Win
|
||||
|
||||
// targetMode *int
|
||||
func drawFooter(app fyne.App, raspiTarget, localUploadPath *string, targetMode *int, cfg RaspiConfig) (*fyne.Container, *widget.Button, *widget.Button) {
|
||||
fExt := filepath.Ext(*localUploadPath)
|
||||
remotePresPath := "/opt/akartontv/media" + fExt
|
||||
remotePresPath := "/opt/akartontv/media"
|
||||
|
||||
// Configuration of the bottom of the application
|
||||
var uploadBtn *widget.Button
|
||||
|
||||
Reference in New Issue
Block a user