Implemented progress bar integration with `ProgressBarContract` for real-time conversion tracking and status updates. Added queue management functionality to process files sequentially with error and completion handling. Extended `ConvertorContract` and `FFmpegContract` to support tracking of running processes and conversion progress.
138 lines
3.6 KiB
Go
138 lines
3.6 KiB
Go
package application
|
|
|
|
import (
|
|
"fyne.io/fyne/v2"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/convertor"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/setting"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg"
|
|
"time"
|
|
)
|
|
|
|
type AppContract interface {
|
|
FyneApp() fyne.App
|
|
GetSetting() setting.SettingContract
|
|
GetProgressBarService() convertor.ProgressBarContract
|
|
GetFFmpegService() ffmpeg.UtilitiesContract
|
|
GetConvertorService() convertor.ConvertorContract
|
|
GetItemsToConvert() convertor.ItemsToConvertContract
|
|
GetQueueService() convertor.QueueListContract
|
|
Run()
|
|
AfterClosing()
|
|
RunConvertor()
|
|
}
|
|
|
|
type application struct {
|
|
fyneApp fyne.App
|
|
setting setting.SettingContract
|
|
progressBarService convertor.ProgressBarContract
|
|
ffmpegService ffmpeg.UtilitiesContract
|
|
itemsToConvert convertor.ItemsToConvertContract
|
|
queueService convertor.QueueListContract
|
|
convertorService convertor.ConvertorContract
|
|
}
|
|
|
|
func NewApp(
|
|
fyneApp fyne.App,
|
|
setting setting.SettingContract,
|
|
progressBarService convertor.ProgressBarContract,
|
|
ffmpegService ffmpeg.UtilitiesContract,
|
|
itemsToConvert convertor.ItemsToConvertContract,
|
|
queueService convertor.QueueListContract,
|
|
convertorService convertor.ConvertorContract,
|
|
) AppContract {
|
|
return &application{
|
|
fyneApp: fyneApp,
|
|
setting: setting,
|
|
progressBarService: progressBarService,
|
|
ffmpegService: ffmpegService,
|
|
itemsToConvert: itemsToConvert,
|
|
queueService: queueService,
|
|
convertorService: convertorService,
|
|
}
|
|
}
|
|
|
|
func (a *application) FyneApp() fyne.App {
|
|
return a.fyneApp
|
|
}
|
|
|
|
func (a *application) GetSetting() setting.SettingContract {
|
|
return a.setting
|
|
}
|
|
|
|
func (a *application) GetProgressBarService() convertor.ProgressBarContract {
|
|
return a.progressBarService
|
|
}
|
|
|
|
func (a *application) GetFFmpegService() ffmpeg.UtilitiesContract {
|
|
return a.ffmpegService
|
|
}
|
|
|
|
func (a *application) GetItemsToConvert() convertor.ItemsToConvertContract {
|
|
return a.itemsToConvert
|
|
}
|
|
|
|
func (a *application) GetQueueService() convertor.QueueListContract {
|
|
return a.queueService
|
|
}
|
|
|
|
func (a *application) GetConvertorService() convertor.ConvertorContract {
|
|
return a.convertorService
|
|
}
|
|
|
|
func (a *application) Run() {
|
|
a.fyneApp.Run()
|
|
}
|
|
|
|
func (a *application) RunConvertor() {
|
|
go func() {
|
|
for {
|
|
time.Sleep(time.Millisecond * 3000)
|
|
queueId, queue := a.queueService.Next()
|
|
if queue == nil {
|
|
continue
|
|
}
|
|
|
|
queue.Status = convertor.StatusType(convertor.InProgress)
|
|
a.queueService.EventChangeQueue(queueId, queue)
|
|
|
|
if a.progressBarService.GetContainer().Hidden {
|
|
a.progressBarService.GetContainer().Show()
|
|
}
|
|
|
|
totalDuration := float64(0)
|
|
ffprobe, err := a.ffmpegService.GetFFprobe()
|
|
if err == nil {
|
|
totalDuration, err = ffprobe.GetTotalDuration(&queue.Setting.FileInput)
|
|
if err != nil {
|
|
totalDuration = float64(0)
|
|
}
|
|
}
|
|
|
|
progress := a.progressBarService.GetProgressbar(
|
|
totalDuration,
|
|
queue.Setting.FileInput.Path,
|
|
)
|
|
|
|
err = a.convertorService.RunConvert(*queue.Setting, progress)
|
|
if err != nil {
|
|
queue.Status = convertor.StatusType(convertor.Error)
|
|
queue.Error = err
|
|
a.queueService.EventChangeQueue(queueId, queue)
|
|
a.progressBarService.ProcessEndedWithError(err.Error())
|
|
|
|
continue
|
|
}
|
|
|
|
queue.Status = convertor.StatusType(convertor.Completed)
|
|
a.queueService.EventChangeQueue(queueId, queue)
|
|
a.progressBarService.ProcessEndedWithSuccess(&queue.Setting.FileOut)
|
|
}
|
|
}()
|
|
}
|
|
|
|
func (a *application) AfterClosing() {
|
|
for _, cmd := range a.convertorService.GetRunningProcesses() {
|
|
_ = cmd.Process.Kill()
|
|
}
|
|
}
|