2024-01-14 16:31:07 +06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-18 01:39:20 +06:00
|
|
|
"errors"
|
2024-01-14 16:31:07 +06:00
|
|
|
"fyne.io/fyne/v2"
|
2024-02-12 22:21:47 +06:00
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor"
|
|
|
|
error2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/error"
|
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/handler"
|
2024-02-17 19:08:58 +06:00
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
2024-02-12 22:21:47 +06:00
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/menu"
|
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/migration"
|
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/setting"
|
2024-01-18 01:39:20 +06:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
2024-01-28 22:01:16 +06:00
|
|
|
"golang.org/x/text/language"
|
2024-01-18 01:39:20 +06:00
|
|
|
"gorm.io/driver/sqlite"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"os"
|
2024-01-14 16:31:07 +06:00
|
|
|
)
|
|
|
|
|
2024-02-17 20:06:09 +06:00
|
|
|
var application kernel.AppContract
|
2024-02-17 19:08:58 +06:00
|
|
|
var ffPathUtilities *kernel.FFPathUtilities
|
2024-01-14 16:31:07 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
func init() {
|
|
|
|
iconResource, _ := fyne.LoadResourceFromPath("icon.png")
|
|
|
|
appMetadata := &fyne.AppMetadata{
|
|
|
|
ID: "net.kor-elf.projects.gui-for-ffmpeg",
|
|
|
|
Name: "GUI for FFmpeg",
|
|
|
|
Version: "0.4.0",
|
|
|
|
Icon: iconResource,
|
2024-01-23 21:33:30 +06:00
|
|
|
}
|
2024-01-14 16:31:07 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
localizerService, err := kernel.NewLocalizer("languages", language.Russian)
|
2024-01-28 22:01:16 +06:00
|
|
|
if err != nil {
|
2024-02-17 19:08:58 +06:00
|
|
|
kernel.PanicErrorLang(err, appMetadata)
|
2024-01-28 22:01:16 +06:00
|
|
|
}
|
2024-01-14 16:31:07 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
ffPathUtilities = &kernel.FFPathUtilities{FFmpeg: "", FFprobe: ""}
|
|
|
|
convertorService := kernel.NewService(ffPathUtilities)
|
|
|
|
layoutLocalizerListener := kernel.NewLayoutLocalizerListener()
|
|
|
|
localizerService.AddListener(layoutLocalizerListener)
|
|
|
|
|
|
|
|
queue := kernel.NewQueueList()
|
2024-02-17 20:06:09 +06:00
|
|
|
application = kernel.NewApp(
|
2024-02-17 19:08:58 +06:00
|
|
|
appMetadata,
|
|
|
|
localizerService,
|
|
|
|
queue,
|
|
|
|
kernel.NewQueueLayoutObject(queue, localizerService, layoutLocalizerListener),
|
|
|
|
convertorService,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2024-02-17 20:06:09 +06:00
|
|
|
errorView := error2.NewView(application)
|
2024-01-18 01:39:20 +06:00
|
|
|
if canCreateFile("data/database") != true {
|
2024-01-28 22:01:16 +06:00
|
|
|
errorView.PanicErrorWriteDirectoryData()
|
2024-02-17 20:06:09 +06:00
|
|
|
application.GetWindow().ShowAndRun()
|
2024-01-18 01:39:20 +06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
db, err := gorm.Open(sqlite.Open("data/database"), &gorm.Config{})
|
|
|
|
if err != nil {
|
|
|
|
errorView.PanicError(err)
|
2024-02-17 20:06:09 +06:00
|
|
|
application.GetWindow().ShowAndRun()
|
2024-01-18 01:39:20 +06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-20 14:58:16 +06:00
|
|
|
defer appCloseWithDb(db)
|
2024-01-18 01:39:20 +06:00
|
|
|
|
|
|
|
err = migration.Run(db)
|
|
|
|
if err != nil {
|
|
|
|
errorView.PanicError(err)
|
2024-02-17 20:06:09 +06:00
|
|
|
application.GetWindow().ShowAndRun()
|
2024-01-18 01:39:20 +06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
settingRepository := setting.NewRepository(db)
|
2024-02-01 00:23:28 +06:00
|
|
|
convertorRepository := convertor.NewRepository(settingRepository)
|
|
|
|
pathFFmpeg, err := convertorRepository.GetPathFfmpeg()
|
2024-01-18 01:39:20 +06:00
|
|
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
|
|
|
errorView.PanicError(err)
|
2024-02-17 20:06:09 +06:00
|
|
|
application.GetWindow().ShowAndRun()
|
2024-01-18 01:39:20 +06:00
|
|
|
return
|
|
|
|
}
|
2024-02-17 19:08:58 +06:00
|
|
|
ffPathUtilities.FFmpeg = pathFFmpeg
|
|
|
|
|
2024-02-01 00:23:28 +06:00
|
|
|
pathFFprobe, err := convertorRepository.GetPathFfprobe()
|
2024-01-18 01:39:20 +06:00
|
|
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
|
|
|
errorView.PanicError(err)
|
2024-02-17 20:06:09 +06:00
|
|
|
application.GetWindow().ShowAndRun()
|
2024-01-18 01:39:20 +06:00
|
|
|
return
|
|
|
|
}
|
2024-02-17 19:08:58 +06:00
|
|
|
ffPathUtilities.FFprobe = pathFFprobe
|
2024-01-18 01:39:20 +06:00
|
|
|
|
2024-02-17 20:06:09 +06:00
|
|
|
application.RunConvertor()
|
|
|
|
defer application.AfterClosing()
|
2024-01-14 16:31:07 +06:00
|
|
|
|
2024-02-17 20:06:09 +06:00
|
|
|
localizerView := localizer.NewView(application)
|
|
|
|
convertorView := convertor.NewView(application)
|
|
|
|
convertorHandler := handler.NewConvertorHandler(application, convertorView, convertorRepository)
|
2024-01-14 16:31:07 +06:00
|
|
|
|
2024-01-31 21:02:12 +06:00
|
|
|
localizerRepository := localizer.NewRepository(settingRepository)
|
2024-02-17 20:06:09 +06:00
|
|
|
menuView := menu.NewView(application)
|
2024-02-17 19:08:58 +06:00
|
|
|
localizerListener := handler.NewLocalizerListener()
|
2024-02-17 20:06:09 +06:00
|
|
|
application.GetLocalizerService().AddListener(localizerListener)
|
|
|
|
mainMenu := handler.NewMenuHandler(application, convertorHandler, menuView, localizerView, localizerRepository, localizerListener)
|
2024-01-31 21:02:12 +06:00
|
|
|
|
2024-02-17 20:06:09 +06:00
|
|
|
mainHandler := handler.NewMainHandler(application, convertorHandler, mainMenu, localizerRepository)
|
2024-01-31 21:02:12 +06:00
|
|
|
mainHandler.Start()
|
|
|
|
|
2024-02-17 20:06:09 +06:00
|
|
|
application.GetWindow().SetMainMenu(mainMenu.GetMainMenu())
|
|
|
|
application.GetWindow().ShowAndRun()
|
2024-01-14 16:31:07 +06:00
|
|
|
}
|
2024-01-18 01:39:20 +06:00
|
|
|
|
2024-01-20 14:58:16 +06:00
|
|
|
func appCloseWithDb(db *gorm.DB) {
|
2024-01-18 01:39:20 +06:00
|
|
|
sqlDB, err := db.DB()
|
|
|
|
if err == nil {
|
|
|
|
_ = sqlDB.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func canCreateFile(path string) bool {
|
|
|
|
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
_ = file.Close()
|
|
|
|
return true
|
|
|
|
}
|