It is now possible to add multiple files before sending them to the processing queue.
128 lines
3.1 KiB
Go
128 lines
3.1 KiB
Go
package kernel
|
|
|
|
import (
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/app"
|
|
"time"
|
|
)
|
|
|
|
type AppContract interface {
|
|
GetAppFyne() fyne.App
|
|
GetWindow() WindowContract
|
|
GetQueue() QueueListContract
|
|
GetLocalizerService() LocalizerContract
|
|
GetConvertorService() ConvertorContract
|
|
GetFFplayService() FFplayContract
|
|
AfterClosing()
|
|
RunConvertor()
|
|
}
|
|
|
|
type App struct {
|
|
AppFyne fyne.App
|
|
Window WindowContract
|
|
Queue QueueListContract
|
|
|
|
localizerService LocalizerContract
|
|
convertorService ConvertorContract
|
|
blockProgressbarService BlockProgressbarContract
|
|
ffplayService FFplayContract
|
|
}
|
|
|
|
func NewApp(
|
|
metadata *fyne.AppMetadata,
|
|
localizerService LocalizerContract,
|
|
queue QueueListContract,
|
|
ffplayService FFplayContract,
|
|
convertorService ConvertorContract,
|
|
) *App {
|
|
app.SetMetadata(*metadata)
|
|
a := app.New()
|
|
|
|
statusesText := GetBlockProgressbarStatusesText(localizerService)
|
|
blockProgressbarService := NewBlockProgressbar(statusesText, ffplayService)
|
|
rightTabsService := NewRightTabs(localizerService)
|
|
queueLayoutObject := NewQueueLayoutObject(queue, localizerService, ffplayService, rightTabsService, blockProgressbarService.GetContainer())
|
|
|
|
return &App{
|
|
AppFyne: a,
|
|
Window: newWindow(a.NewWindow("GUI for FFmpeg"), NewLayout(queueLayoutObject, localizerService, rightTabsService)),
|
|
Queue: queue,
|
|
|
|
localizerService: localizerService,
|
|
convertorService: convertorService,
|
|
blockProgressbarService: blockProgressbarService,
|
|
ffplayService: ffplayService,
|
|
}
|
|
}
|
|
|
|
func (a App) GetAppFyne() fyne.App {
|
|
return a.AppFyne
|
|
}
|
|
|
|
func (a App) GetQueue() QueueListContract {
|
|
return a.Queue
|
|
}
|
|
|
|
func (a App) GetWindow() WindowContract {
|
|
return a.Window
|
|
}
|
|
|
|
func (a App) GetLocalizerService() LocalizerContract {
|
|
return a.localizerService
|
|
}
|
|
|
|
func (a App) GetConvertorService() ConvertorContract {
|
|
return a.convertorService
|
|
}
|
|
|
|
func (a App) GetFFplayService() FFplayContract {
|
|
return a.ffplayService
|
|
}
|
|
|
|
func (a App) AfterClosing() {
|
|
for _, cmd := range a.convertorService.GetRunningProcesses() {
|
|
_ = cmd.Process.Kill()
|
|
}
|
|
}
|
|
|
|
func (a App) RunConvertor() {
|
|
go func() {
|
|
for {
|
|
time.Sleep(time.Millisecond * 3000)
|
|
queueId, queue := a.Queue.Next()
|
|
if queue == nil {
|
|
continue
|
|
}
|
|
queue.Status = StatusType(InProgress)
|
|
a.Window.GetLayout().ChangeQueueStatus(queueId, queue)
|
|
if a.blockProgressbarService.GetContainer().Hidden {
|
|
a.blockProgressbarService.GetContainer().Show()
|
|
}
|
|
|
|
totalDuration, err := a.convertorService.GetTotalDuration(&queue.Setting.VideoFileInput)
|
|
if err != nil {
|
|
totalDuration = 0
|
|
}
|
|
|
|
progress := a.blockProgressbarService.GetProgressbar(
|
|
totalDuration,
|
|
queue.Setting.VideoFileInput.Path,
|
|
a.localizerService,
|
|
)
|
|
|
|
err = a.convertorService.RunConvert(*queue.Setting, progress)
|
|
if err != nil {
|
|
queue.Status = StatusType(Error)
|
|
queue.Error = err
|
|
a.Window.GetLayout().ChangeQueueStatus(queueId, queue)
|
|
a.blockProgressbarService.ProcessEndedWithError(err.Error())
|
|
|
|
continue
|
|
}
|
|
queue.Status = StatusType(Completed)
|
|
a.Window.GetLayout().ChangeQueueStatus(queueId, queue)
|
|
a.blockProgressbarService.ProcessEndedWithSuccess(queue.Setting.VideoFileOut.Path)
|
|
}
|
|
}()
|
|
}
|