From adf9bc9c278a066f56c40548a90a463527672d46 Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Tue, 23 Jan 2024 21:33:01 +0600 Subject: [PATCH] Code refactoring. Added files with functions for various OS (//go:build windows, //go:build !windows). --- src/convertor/view.go | 3 +++ src/handler/convertor.go | 8 +------- src/handler/convertor_anyos.go | 10 ++++++++++ src/handler/convertor_windows.go | 8 ++++++++ src/helper/helper.go | 13 +++++++------ src/helper/path_separator.go | 8 ++++++++ src/helper/path_separator_window.go | 8 ++++++++ src/setting/view.go | 2 ++ 8 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 src/handler/convertor_anyos.go create mode 100644 src/handler/convertor_windows.go create mode 100644 src/helper/path_separator.go create mode 100644 src/helper/path_separator_window.go diff --git a/src/convertor/view.go b/src/convertor/view.go index db26786..6df9a50 100644 --- a/src/convertor/view.go +++ b/src/convertor/view.go @@ -2,6 +2,7 @@ package convertor import ( "errors" + "ffmpegGui/helper" "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" @@ -131,6 +132,7 @@ func (v View) getButtonFileVideoForConversion(form *widget.Form, progress *widge progress.Refresh() conversionMessage.Text = "" }, v.w) + helper.FileDialogResize(fileDialog, v.w) fileDialog.Show() }) @@ -162,6 +164,7 @@ func (v View) getButtonForSelectingDirectoryForSaving() (button *widget.Button, buttonMessage.Text = r.Path() setStringSuccessStyle(buttonMessage) }, v.w) + helper.FileDialogResize(fileDialog, v.w) fileDialog.Show() }) diff --git a/src/handler/convertor.go b/src/handler/convertor.go index 8d3d5f5..e1de919 100644 --- a/src/handler/convertor.go +++ b/src/handler/convertor.go @@ -9,7 +9,6 @@ import ( "fyne.io/fyne/v2/widget" "io" "regexp" - "runtime" "strconv" "strings" ) @@ -69,12 +68,7 @@ func (h ConvertorHandler) checkingFFPathUtilities() bool { return true } - var pathsToFF []convertor.FFPathUtilities - if runtime.GOOS == "windows" { - pathsToFF = []convertor.FFPathUtilities{{"ffmpeg\\bin\\ffmpeg.exe", "ffmpeg\\bin\\ffprobe.exe"}} - } else { - pathsToFF = []convertor.FFPathUtilities{{"ffmpeg/bin/ffmpeg", "ffmpeg/bin/ffprobe"}, {"ffmpeg", "ffprobe"}} - } + pathsToFF := getPathsToFF() for _, item := range pathsToFF { ffmpegChecking, _ := h.convertorService.ChangeFFmpegPath(item.FFmpeg) if ffmpegChecking == false { diff --git a/src/handler/convertor_anyos.go b/src/handler/convertor_anyos.go new file mode 100644 index 0000000..66d5fb6 --- /dev/null +++ b/src/handler/convertor_anyos.go @@ -0,0 +1,10 @@ +//go:build !windows +// +build !windows + +package handler + +import "ffmpegGui/convertor" + +func getPathsToFF() []convertor.FFPathUtilities { + return []convertor.FFPathUtilities{{"ffmpeg/bin/ffmpeg", "ffmpeg/bin/ffprobe"}, {"ffmpeg", "ffprobe"}} +} diff --git a/src/handler/convertor_windows.go b/src/handler/convertor_windows.go new file mode 100644 index 0000000..2def3f1 --- /dev/null +++ b/src/handler/convertor_windows.go @@ -0,0 +1,8 @@ +//go:build windows +// +build windows + +package handler + +func getPathsToFF() []convertor.FFPathUtilities { + return []convertor.FFPathUtilities{{"ffmpeg\\bin\\ffmpeg.exe", "ffmpeg\\bin\\ffprobe.exe"}} +} diff --git a/src/helper/helper.go b/src/helper/helper.go index b98d666..682704c 100644 --- a/src/helper/helper.go +++ b/src/helper/helper.go @@ -1,10 +1,11 @@ package helper -import "runtime" +import ( + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/dialog" +) -func PathSeparator() string { - if runtime.GOOS == "windows" { - return "\\" - } - return "/" +func FileDialogResize(fileDialog *dialog.FileDialog, w fyne.Window) { + contentSize := w.Content().Size() + fileDialog.Resize(fyne.Size{Width: contentSize.Width - 50, Height: contentSize.Height - 50}) } diff --git a/src/helper/path_separator.go b/src/helper/path_separator.go new file mode 100644 index 0000000..905b935 --- /dev/null +++ b/src/helper/path_separator.go @@ -0,0 +1,8 @@ +//go:build !windows +// +build !windows + +package helper + +func PathSeparator() string { + return "/" +} diff --git a/src/helper/path_separator_window.go b/src/helper/path_separator_window.go new file mode 100644 index 0000000..433e550 --- /dev/null +++ b/src/helper/path_separator_window.go @@ -0,0 +1,8 @@ +//go:build windows +// +build windows + +package helper + +func PathSeparator() string { + return "\\" +} diff --git a/src/setting/view.go b/src/setting/view.go index 7a85e0d..7e67dcf 100644 --- a/src/setting/view.go +++ b/src/setting/view.go @@ -1,6 +1,7 @@ package setting import ( + "ffmpegGui/helper" "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" @@ -81,6 +82,7 @@ func (v View) getButtonSelectFile() (filePath *string, button *widget.Button, bu buttonMessage.Text = r.URI().Path() setStringSuccessStyle(buttonMessage) }, v.w) + helper.FileDialogResize(fileDialog, v.w) fileDialog.Show() })