diff --git a/install.sh b/install.sh index 1811cc1..721f5b6 100644 --- a/install.sh +++ b/install.sh @@ -119,14 +119,21 @@ case "\$3" in if [[ "\$2" == "presentation" ]]; then echo "Finding and moving media..." - media_file=\$(find /opt/raspscreen/media -path /opt/raspscreen/media/current -prune -o \( -name "*.pptx" -o -name "*.odp" \) -type f -print) + media_file=\$(find /opt/raspscreen/media \ + -path /opt/raspscreen/media/current -prune -o \ + -type f \( -iname "*.pptx" -o -iname "*.odp" \) \ + -printf '%T@ %p\n' | sort -n | tail -1 | cut -d' ' -f2-) + + media_file_ext="\${media_file##*.}" echo "New media file: \$media_file" - old_file=\$(find /opt/raspscreen/media/current \( -name "*.pptx" -o -name "*.odp" \)) + old_file=\$(find /opt/raspscreen/media/current -type f \( -iname "*.pptx" -o -iname "*.odp" \)) echo "Old file: \$old_file" + echo "Copying new media into staging area..." cp "\$media_file" /opt/raspscreen/media/current - current_media=\$(find /opt/raspscreen/media/current \( -name "*.pptx" -o -name "*.odp" \)) + + current_media=\$(find /opt/raspscreen/media/current -name "*.\$media_file_ext") echo "Prepared media: \$current_media" if [[ -z "\$current_media" ]]; then @@ -139,15 +146,22 @@ case "\$3" in /usr/bin/libreoffice --impress --show --norestore "\$current_media" fi elif [[ "\$2" == "video" ]]; then - echo "Finding and moving media..." - media_file=\$(find /opt/raspscreen/media -path /opt/raspscreen/media/current -prune -o \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \) -print) + echo "Finding media..." + media_file=\$(find /opt/raspscreen/media \ + -path /opt/raspscreen/media/current -prune -o \ + -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.webm" \) \ + -printf '%T@ %p\n' | sort -n | tail -1 | cut -d' ' -f2-) + + media_file_ext="\${media_file##*.}" echo "New media file: \$media_file" - old_file=\$(find /opt/raspscreen/media/current \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \)) + old_file=\$(find /opt/raspscreen/media/current -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.webm" \)) echo "Old file: \$old_file" + echo "Copying new media into staging area..." cp "\$media_file" /opt/raspscreen/media/current - current_media=\$(find /opt/raspscreen/media/current \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \)) + + current_media=\$(find /opt/raspscreen/media/current -name "*.\$media_file_ext") echo "Prepared media: \$current_media" if [[ -z "\$current_media" ]]; then diff --git a/manage.sh b/manage.sh index 506e93b..f0d4a61 100755 --- a/manage.sh +++ b/manage.sh @@ -50,14 +50,21 @@ case "$3" in if [[ "$2" == "presentation" ]]; then echo "Finding and moving media..." - media_file=$(find /opt/raspscreen/media -path /opt/raspscreen/media/current -prune -o \( -name "*.pptx" -o -name "*.odp" \) -type f -print) + media_file=$(find /opt/raspscreen/media \ + -path /opt/raspscreen/media/current -prune -o \ + -type f \( -iname "*.pptx" -o -iname "*.odp" \) \ + -printf '%T@ %p\n' | sort -n | tail -1 | cut -d' ' -f2-) + + media_file_ext="${media_file##*.}" echo "New media file: $media_file" - old_file=$(find /opt/raspscreen/media/current \( -name "*.pptx" -o -name "*.odp" \)) + old_file=$(find /opt/raspscreen/media/current -type f \( -iname "*.pptx" -o -iname "*.odp" \)) echo "Old file: $old_file" + echo "Copying new media into staging area..." cp "$media_file" /opt/raspscreen/media/current - current_media=$(find /opt/raspscreen/media/current \( -name "*.pptx" -o -name "*.odp" \)) + + current_media=$(find /opt/raspscreen/media/current -name "*.$media_file_ext") echo "Prepared media: $current_media" if [[ -z "$current_media" ]]; then @@ -70,15 +77,22 @@ case "$3" in /usr/bin/libreoffice --impress --show --norestore "$current_media" fi elif [[ "$2" == "video" ]]; then - echo "Finding and moving media..." - media_file=$(find /opt/raspscreen/media -path /opt/raspscreen/media/current -prune -o \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \) -print) + echo "Finding media..." + media_file=$(find /opt/raspscreen/media \ + -path /opt/raspscreen/media/current -prune -o \ + -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.webm" \) \ + -printf '%T@ %p\n' | sort -n | tail -1 | cut -d' ' -f2-) + + media_file_ext="${media_file##*.}" echo "New media file: $media_file" - old_file=$(find /opt/raspscreen/media/current \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \)) + old_file=$(find /opt/raspscreen/media/current -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.webm" \)) echo "Old file: $old_file" + echo "Copying new media into staging area..." cp "$media_file" /opt/raspscreen/media/current - current_media=$(find /opt/raspscreen/media/current \( -name "*.mp4" -o -name "*.mkv" -o -name "*.mov" -o -name "*.webm" \)) + + current_media=$(find /opt/raspscreen/media/current -name "*.$media_file_ext") echo "Prepared media: $current_media" if [[ -z "$current_media" ]]; then diff --git a/src/draw.go b/src/draw.go index 5346655..e4df58c 100644 --- a/src/draw.go +++ b/src/draw.go @@ -78,7 +78,7 @@ func drawSeparator(preNewLine, postNewLine bool) *fyne.Container { return separContainer } -func drawModeRow(targetMode *int) *fyne.Container { +func drawModeRow(pathLabel *widget.Label, localPath *string, targetMode *int) *fyne.Container { actionText := widget.NewLabel("Select Mode") // targetMode is defined as: // 0 undefined / not used @@ -90,6 +90,10 @@ func drawModeRow(targetMode *int) *fyne.Container { *targetMode = 1 presModeBtn.Importance = widget.HighImportance videoModeBtn.Importance = widget.LowImportance + + pathLabel.SetText("No File Selected Yet...") + *localPath = "" + log.Println("Set mode to presentation", *targetMode) refreshButtons(presModeBtn, videoModeBtn) }) @@ -102,6 +106,10 @@ func drawModeRow(targetMode *int) *fyne.Container { *targetMode = 2 presModeBtn.Importance = widget.LowImportance videoModeBtn.Importance = widget.HighImportance + + pathLabel.SetText("No File Selected Yet...") + *localPath = "" + log.Println("Set mode to video", *targetMode) refreshButtons(presModeBtn, videoModeBtn) }) @@ -161,11 +169,9 @@ func drawTargetSection(raspiNames []string, raspiTarget *string, uploadBtn, relo credOK = verifyCred(*raspiTarget, cfg) if credOK { - // Must update UI on main thread + flashColor(verifyBtn, FlashSuccess) // flashcolor should handle RunOnMain internally fyne.CurrentApp().Driver().DoFromGoroutine(func() { - flashColor(verifyBtn, FlashSuccess) // flashcolor should handle RunOnMain internally uploadBtn.Enable() - reloadBtn.Enable() }, false) } else { @@ -187,15 +193,12 @@ func drawTargetSection(raspiNames []string, raspiTarget *string, uploadBtn, relo return wholeCol } -func drawFileSelection(localPath *string, targetMode *int, parentWindow fyne.Window) *fyne.Container { +func drawFileSelection(localPath *string, targetMode *int, parentWindow fyne.Window) (*fyne.Container, *widget.Label) { actionText := widget.NewLabel("Select File") pathLabel := widget.NewLabel("No File Selected Yet...") var uploadBtn *widget.Button uploadBtn = widget.NewButton("Click to Select File", func() { - // Stupid dialog error on 'headless' servers... - log.Println("Ignore the next error. ~Refer: https://github.com/fyne-io/fyne/issues/4110") - // Use NewFileOpen to get the dialog object uploadSelecDiag := dialog.NewFileOpen(func(r fyne.URIReadCloser, err error) { if r != nil { @@ -239,7 +242,7 @@ func drawFileSelection(localPath *string, targetMode *int, parentWindow fyne.Win fileSelecRow, ) - return fileSelecCol + return fileSelecCol, pathLabel } // targetMode *int @@ -260,7 +263,9 @@ func drawFooter(app fyne.App, raspiTarget, localUploadPath *string, targetMode * if ok { flashColor(uploadBtn, FlashSuccess) - reloadBtn.Enable() + fyne.CurrentApp().Driver().DoFromGoroutine(func() { + reloadBtn.Enable() + }, false) } else { flashColor(uploadBtn, FlashError) } diff --git a/src/main.go b/src/main.go index 66bb194..5b86989 100644 --- a/src/main.go +++ b/src/main.go @@ -69,9 +69,9 @@ func main() { // Call the draw functions -> ./src/draw.go footerRow, uploadBtn, reloadBtn := drawFooter(app, &raspiTarget, &localUploadPath, &targetMode, cfg) - modeBtnRow := drawModeRow(&targetMode) + fileSelectRow, pathLabel := drawFileSelection(&localUploadPath, &targetMode, w) + modeBtnRow := drawModeRow(pathLabel, &localUploadPath, &targetMode) selectionRow := drawTargetSection(raspiNames, &raspiTarget, uploadBtn, reloadBtn, cfg) - fileSelectRow := drawFileSelection(&localUploadPath, &targetMode, w) center := container.NewVBox( modeBtnRow,