Add localized error handling for database timeout

Introduced a new localized error message "errorDatabaseTimeout" in multiple languages (English, Kazakh, Russian) and updated the `PanicError` method to handle database timeout errors more gracefully. This improves user feedback by providing context-specific error messages.
This commit is contained in:
Leonid Nikitin 2025-05-18 19:32:57 +05:00
parent 9d46db43c2
commit a831d56d93
Signed by: kor-elf
GPG Key ID: DAB5355A11C22541
4 changed files with 34 additions and 3 deletions

View File

@ -1,11 +1,14 @@
package error
import (
"errors"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/lang"
"fyne.io/fyne/v2/widget"
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
"github.com/nicksnyder/go-i18n/v2/i18n"
"go.etcd.io/bbolt"
)
type ViewContract interface {
@ -14,23 +17,37 @@ type ViewContract interface {
type View struct {
app kernel.AppContract
isSetLanguage bool
}
func NewView(app kernel.AppContract) *View {
return &View{
app: app,
isSetLanguage: true,
}
}
func (v View) PanicError(err error) {
if v.isSetLanguage {
v.isSetLanguage = false
_ = v.app.GetLocalizerService().SetCurrentLanguageByCode(lang.SystemLocale().LanguageString())
}
messageHead := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
MessageID: "error",
})
messagetText := err.Error()
if errors.Is(err, bbolt.ErrTimeout) {
messagetText = v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
MessageID: "errorDatabaseTimeout",
})
}
v.app.GetWindow().SetContent(container.NewBorder(
container.NewVBox(
widget.NewLabel(messageHead),
widget.NewLabel(err.Error()),
widget.NewLabel(messagetText),
),
nil,
nil,
@ -42,6 +59,11 @@ func (v View) PanicError(err error) {
}
func (v View) PanicErrorWriteDirectoryData() {
if v.isSetLanguage {
v.isSetLanguage = false
_ = v.app.GetLocalizerService().SetCurrentLanguageByCode(lang.SystemLocale().LanguageString())
}
message := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
MessageID: "errorDatabase",
})

View File

@ -222,6 +222,10 @@ other = "Couldn't convert video"
hash = "sha1-531abc3f0d12727e542df6e5a22de91098380fc1"
other = "could not create file 'database' in folder 'data'"
[errorDatabaseTimeout]
hash = "sha1-f8153516ac2442d19be4b6daccce839d204ff09f"
other = "Could not open configuration file.\nMake sure another copy of the program is not running!"
[errorDragAndDrop1File]
hash = "sha1-a8edb5cbd622f3ce4ec07a2377e22ec5fad4491b"
other = "You can only drag and drop 1 file."

View File

@ -222,6 +222,10 @@ other = "Бейнені түрлендіру мүмкін болмады"
hash = "sha1-531abc3f0d12727e542df6e5a22de91098380fc1"
other = "'data' қалтасында 'database' файлын жасау мүмкін болмады"
[errorDatabaseTimeout]
hash = "sha1-f8153516ac2442d19be4b6daccce839d204ff09f"
other = "Конфигурация файлын аша алмады.\nБағдарламаның басқа көшірмесі іске қосылмағанына көз жеткізіңіз!"
[errorDragAndDrop1File]
hash = "sha1-a8edb5cbd622f3ce4ec07a2377e22ec5fad4491b"
other = "Тек 1 файлды сүйреп апаруға болады"

View File

@ -54,6 +54,7 @@ encoder_xbm = "XBM (X BitMap) image"
error = "Произошла ошибка!"
errorConverter = "не смогли отконвертировать видео"
errorDatabase = "не смогли создать файл 'database' в папке 'data'"
errorDatabaseTimeout = "Не смогли открыть файл конфигурации.\nУбедитесь, что другая копия программы не запущена!"
errorDragAndDrop1File = "Можно перетащить только 1 файл"
errorFFmpeg = "это не FFmpeg"
errorFFmpegVersion = "Не смогли определить версию FFmpeg"