Replaced bbolt-based database handling with Fyne built-in preferences for storing application settings. Deleted migration logic, database initialization, and error handling related to bbolt, simplifying the codebase and reducing external dependencies.
40 lines
757 B
Go
40 lines
757 B
Go
package setting
|
|
|
|
import (
|
|
"fyne.io/fyne/v2"
|
|
)
|
|
|
|
type RepositoryContract interface {
|
|
Create(setting Setting) Setting
|
|
CreateOrUpdate(code string, value string) Setting
|
|
GetValue(code string) string
|
|
}
|
|
|
|
type Repository struct {
|
|
app fyne.App
|
|
}
|
|
|
|
func NewRepository(app fyne.App) *Repository {
|
|
return &Repository{
|
|
app: app,
|
|
}
|
|
}
|
|
|
|
func (r Repository) GetValue(code string) string {
|
|
return r.app.Preferences().String(code)
|
|
}
|
|
|
|
func (r Repository) Create(setting Setting) Setting {
|
|
r.app.Preferences().SetString(setting.Code, setting.Value)
|
|
return setting
|
|
}
|
|
|
|
func (r Repository) CreateOrUpdate(code string, value string) Setting {
|
|
var setting Setting
|
|
setting.Code = code
|
|
setting.Value = value
|
|
|
|
r.app.Preferences().SetString(code, value)
|
|
return setting
|
|
}
|