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 19:08:58 +06:00
|
|
|
var app kernel.AppContract
|
|
|
|
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()
|
|
|
|
app = kernel.NewApp(
|
|
|
|
appMetadata,
|
|
|
|
localizerService,
|
|
|
|
queue,
|
|
|
|
kernel.NewQueueLayoutObject(queue, localizerService, layoutLocalizerListener),
|
|
|
|
convertorService,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
errorView := error2.NewView(app)
|
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 19:08:58 +06:00
|
|
|
app.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 19:08:58 +06:00
|
|
|
app.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 19:08:58 +06:00
|
|
|
app.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 19:08:58 +06:00
|
|
|
app.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 19:08:58 +06:00
|
|
|
app.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 19:08:58 +06:00
|
|
|
app.RunConvertor()
|
|
|
|
defer app.AfterClosing()
|
2024-01-14 16:31:07 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
localizerView := localizer.NewView(app)
|
|
|
|
convertorView := convertor.NewView(app)
|
|
|
|
convertorHandler := handler.NewConvertorHandler(app, 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 19:08:58 +06:00
|
|
|
menuView := menu.NewView(app)
|
|
|
|
localizerListener := handler.NewLocalizerListener()
|
|
|
|
app.GetLocalizerService().AddListener(localizerListener)
|
|
|
|
mainMenu := handler.NewMenuHandler(app, convertorHandler, menuView, localizerView, localizerRepository, localizerListener)
|
2024-01-31 21:02:12 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
mainHandler := handler.NewMainHandler(app, convertorHandler, mainMenu, localizerRepository)
|
2024-01-31 21:02:12 +06:00
|
|
|
mainHandler.Start()
|
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
app.GetWindow().SetMainMenu(mainMenu.GetMainMenu())
|
|
|
|
app.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
|
|
|
|
}
|