Add FFmpeg utilities configuration UI and automated downloading

Introduce a new UI for configuring FFmpeg, FFprobe, and FFplay paths with file selection and error handling. Add platform-specific logic for downloading and extracting FFmpeg binaries directly within the application, improving user experience.
This commit is contained in:
2025-06-07 01:30:32 +05:00
parent b24155caf6
commit c60b9f7b0c
22 changed files with 1118 additions and 37 deletions

View File

@@ -0,0 +1,129 @@
package view
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/lang"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/widget"
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/gui/window"
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
"image/color"
"net/url"
"path/filepath"
)
func ConfiguringFFmpegUtilities(
window window.WindowContract,
currentPathFFmpeg string,
currentPathFFprobe string,
currentPathFFplay string,
save func(ffmpegPath string, ffprobePath string, ffplayPath string) error,
cancel func(),
donwloadFFmpeg fyne.CanvasObject,
) fyne.CanvasObject {
errorMessage := canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
errorMessage.TextSize = 16
errorMessage.TextStyle = fyne.TextStyle{Bold: true}
link := widget.NewHyperlink("https://ffmpeg.org/download.html", &url.URL{
Scheme: "https",
Host: "ffmpeg.org",
Path: "download.html",
})
ffmpegPath, buttonFFmpeg, buttonFFmpegMessage := configuringFFmpegUtilitiesButtonSelectFile(window, currentPathFFmpeg)
ffprobePath, buttonFFprobe, buttonFFprobeMessage := configuringFFmpegUtilitiesButtonSelectFile(window, currentPathFFprobe)
ffplayPath, buttonFFplay, buttonFFplayMessage := configuringFFmpegUtilitiesButtonSelectFile(window, currentPathFFplay)
form := &widget.Form{
Items: []*widget.FormItem{
{
Text: lang.L("titleDownloadLink"),
Widget: link,
},
{
Text: lang.L("pathToFfmpeg"),
Widget: buttonFFmpeg,
},
{
Widget: container.NewHScroll(buttonFFmpegMessage),
},
{
Text: lang.L("pathToFfprobe"),
Widget: buttonFFprobe,
},
{
Widget: container.NewHScroll(buttonFFprobeMessage),
},
{
Text: lang.L("pathToFfplay"),
Widget: buttonFFplay,
},
{
Widget: container.NewHScroll(buttonFFplayMessage),
},
{
Widget: container.NewHScroll(errorMessage),
},
},
SubmitText: lang.L("save"),
OnSubmit: func() {
err := save(*ffmpegPath, *ffprobePath, *ffplayPath)
if err != nil {
errorMessage.Text = err.Error()
}
},
}
if cancel != nil {
form.OnCancel = cancel
form.CancelText = lang.L("cancel")
}
selectFFPathTitle := lang.L("selectFFPathTitle")
return widget.NewCard(selectFFPathTitle, "", container.NewVBox(
form,
donwloadFFmpeg,
))
}
func configuringFFmpegUtilitiesButtonSelectFile(window window.WindowContract, path string) (filePath *string, button *widget.Button, buttonMessage *canvas.Text) {
filePath = &path
buttonMessage = canvas.NewText(path, color.RGBA{R: 49, G: 127, B: 114, A: 255})
buttonMessage.TextSize = 16
buttonMessage.TextStyle = fyne.TextStyle{Bold: true}
buttonTitle := lang.L("choose")
var locationURI fyne.ListableURI
if len(path) > 0 {
listableURI := storage.NewFileURI(filepath.Dir(path))
locationURI, _ = storage.ListerForURI(listableURI)
}
button = widget.NewButton(buttonTitle, func() {
window.NewFileOpen(func(r fyne.URIReadCloser, err error) {
if err != nil {
buttonMessage.Text = err.Error()
utils.SetStringErrorStyle(buttonMessage)
return
}
if r == nil {
return
}
path = r.URI().Path()
buttonMessage.Text = r.URI().Path()
utils.SetStringSuccessStyle(buttonMessage)
listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path()))
locationURI, _ = storage.ListerForURI(listableURI)
}, locationURI)
})
return filePath, button, buttonMessage
}

View File

@@ -3,15 +3,18 @@ package window
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/lang"
"fyne.io/fyne/v2/widget"
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application"
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
)
type MainWindowContract interface {
type WindowContract interface {
SetContent(content fyne.CanvasObject)
Show()
InitLayout()
NewFileOpen(callback func(fyne.URIReadCloser, error), location fyne.ListableURI) *dialog.FileDialog
}
type mainWindow struct {
@@ -20,7 +23,7 @@ type mainWindow struct {
progressBarService application.ProgressBarContract
}
func NewMainWindow(fyneWindow fyne.Window, progressBarService application.ProgressBarContract) MainWindowContract {
func NewMainWindow(fyneWindow fyne.Window, progressBarService application.ProgressBarContract) WindowContract {
fyneWindow.Resize(fyne.Size{Width: 1039, Height: 599})
fyneWindow.CenterOnScreen()
@@ -40,6 +43,16 @@ func (w *mainWindow) InitLayout() {
})
}
func (w *mainWindow) NewFileOpen(callback func(fyne.URIReadCloser, error), location fyne.ListableURI) *dialog.FileDialog {
fileDialog := dialog.NewFileOpen(callback, w.fyneWindow)
utils.FileDialogResize(fileDialog, w.fyneWindow)
fileDialog.Show()
if location != nil {
fileDialog.SetLocation(location)
}
return fileDialog
}
func (w *mainWindow) SetContent(content fyne.CanvasObject) {
fyne.Do(func() {
if w.layout == nil {