Compare commits
No commits in common. "fc38a1b20c5ece8f54c2e9da278c75182a868e6b" and "4fa977347c69006d525c956dc6516eed05ee009e" have entirely different histories.
fc38a1b20c
...
4fa977347c
@ -17,7 +17,6 @@ type ServiceContract interface {
|
|||||||
GetFFprobeVersion() (string, error)
|
GetFFprobeVersion() (string, error)
|
||||||
ChangeFFmpegPath(path string) (bool, error)
|
ChangeFFmpegPath(path string) (bool, error)
|
||||||
ChangeFFprobePath(path string) (bool, error)
|
ChangeFFprobePath(path string) (bool, error)
|
||||||
GetRunningProcesses() map[int]*exec.Cmd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProgressContract interface {
|
type ProgressContract interface {
|
||||||
@ -30,14 +29,8 @@ type FFPathUtilities struct {
|
|||||||
FFprobe string
|
FFprobe string
|
||||||
}
|
}
|
||||||
|
|
||||||
type runningProcesses struct {
|
|
||||||
items map[int]*exec.Cmd
|
|
||||||
numberOfStarts int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
ffPathUtilities *FFPathUtilities
|
ffPathUtilities *FFPathUtilities
|
||||||
runningProcesses runningProcesses
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
@ -59,7 +52,6 @@ type ConvertData struct {
|
|||||||
func NewService(ffPathUtilities FFPathUtilities) *Service {
|
func NewService(ffPathUtilities FFPathUtilities) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
ffPathUtilities: &ffPathUtilities,
|
ffPathUtilities: &ffPathUtilities,
|
||||||
runningProcesses: runningProcesses{items: map[int]*exec.Cmd{}, numberOfStarts: 0},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,14 +77,10 @@ func (s Service) RunConvert(setting ConvertSetting, progress ProgressContract) e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
index := s.runningProcesses.numberOfStarts
|
|
||||||
s.runningProcesses.numberOfStarts++
|
|
||||||
s.runningProcesses.items[index] = cmd
|
|
||||||
|
|
||||||
errProgress := progress.Run(stdOut, stdErr)
|
errProgress := progress.Run(stdOut, stdErr)
|
||||||
|
|
||||||
err = cmd.Wait()
|
err = cmd.Wait()
|
||||||
delete(s.runningProcesses.items, index)
|
|
||||||
if errProgress != nil {
|
if errProgress != nil {
|
||||||
return errProgress
|
return errProgress
|
||||||
}
|
}
|
||||||
@ -167,7 +155,3 @@ func (s Service) ChangeFFprobePath(path string) (bool, error) {
|
|||||||
s.ffPathUtilities.FFprobe = path
|
s.ffPathUtilities.FFprobe = path
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) GetRunningProcesses() map[int]*exec.Cmd {
|
|
||||||
return s.runningProcesses.items
|
|
||||||
}
|
|
||||||
|
@ -98,6 +98,7 @@ func (v View) Main(
|
|||||||
|
|
||||||
v.w.SetContent(widget.NewCard("Конвертор видео файлов в mp4", "", container.NewVBox(form, conversionMessage, progress)))
|
v.w.SetContent(widget.NewCard("Конвертор видео файлов в mp4", "", container.NewVBox(form, conversionMessage, progress)))
|
||||||
form.Disable()
|
form.Disable()
|
||||||
|
progress.Hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v View) getButtonFileVideoForConversion(form *widget.Form, progress *widget.ProgressBar, conversionMessage *canvas.Text) (*widget.Button, *canvas.Text, *File) {
|
func (v View) getButtonFileVideoForConversion(form *widget.Form, progress *widget.ProgressBar, conversionMessage *canvas.Text) (*widget.Button, *canvas.Text, *File) {
|
||||||
|
11
src/main.go
11
src/main.go
@ -38,7 +38,7 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer appCloseWithDb(db)
|
defer appClose(db)
|
||||||
|
|
||||||
err = migration.Run(db)
|
err = migration.Run(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -66,7 +66,6 @@ func main() {
|
|||||||
convertorView := convertor.NewView(w)
|
convertorView := convertor.NewView(w)
|
||||||
settingView := setting.NewView(w)
|
settingView := setting.NewView(w)
|
||||||
convertorService := convertor.NewService(ffPathUtilities)
|
convertorService := convertor.NewService(ffPathUtilities)
|
||||||
defer appCloseWithConvert(convertorService)
|
|
||||||
mainHandler := handler.NewConvertorHandler(convertorService, convertorView, settingView, settingRepository)
|
mainHandler := handler.NewConvertorHandler(convertorService, convertorView, settingView, settingRepository)
|
||||||
|
|
||||||
mainHandler.GetConvertor()
|
mainHandler.GetConvertor()
|
||||||
@ -74,19 +73,13 @@ func main() {
|
|||||||
w.ShowAndRun()
|
w.ShowAndRun()
|
||||||
}
|
}
|
||||||
|
|
||||||
func appCloseWithDb(db *gorm.DB) {
|
func appClose(db *gorm.DB) {
|
||||||
sqlDB, err := db.DB()
|
sqlDB, err := db.DB()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_ = sqlDB.Close()
|
_ = sqlDB.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func appCloseWithConvert(convertorService convertor.ServiceContract) {
|
|
||||||
for _, cmd := range convertorService.GetRunningProcesses() {
|
|
||||||
_ = cmd.Process.Kill()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func canCreateFile(path string) bool {
|
func canCreateFile(path string) bool {
|
||||||
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
|
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user