1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-07-22 15:18:02 +00:00
This commit is contained in:
2023-02-11 21:57:52 +01:00
parent ff3766ad85
commit 126b42d570
19 changed files with 168 additions and 84 deletions

View File

@ -2,7 +2,6 @@ package app
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
@ -34,7 +33,8 @@ func (a *App) Settings() Settings {
if err != nil {
// It's ok if the file cannot be opened, for example if it is not accessible.
// Therefore no error is returned.
fmt.Println(err.Error())
runtime.LogInfo(a.ctx, "Cannot open settings.json:")
runtime.LogInfo(a.ctx, err.Error())
return s
}
@ -44,7 +44,8 @@ func (a *App) Settings() Settings {
err = json.Unmarshal(jsonData, &s)
if err != nil {
fmt.Println(err.Error())
runtime.LogWarning(a.ctx, "Cannot unmarshal settings.json:")
runtime.LogWarning(a.ctx, err.Error())
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.ErrorDialog,
Title: "Could not retrieve application settings, using defaults!",
@ -59,6 +60,8 @@ func (a *App) UpdateSettings(jsonData string) Settings {
s := a.Settings()
err := json.Unmarshal([]byte(jsonData), &s)
if err != nil {
runtime.LogError(a.ctx, "Malformed JSON for settings file:")
runtime.LogError(a.ctx, err.Error())
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.InfoDialog,
Title: "Malformed JSON",
@ -69,6 +72,8 @@ func (a *App) UpdateSettings(jsonData string) Settings {
newJson, err := json.MarshalIndent(s, "", "\t")
if err != nil {
runtime.LogError(a.ctx, "Could not marshal settings into JSON:")
runtime.LogError(a.ctx, err.Error())
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.InfoDialog,
Title: "Could not marshal settings into JSON",
@ -80,6 +85,8 @@ func (a *App) UpdateSettings(jsonData string) Settings {
filePath := path.Join(a.Env.DataDirectory, "settings.json")
err = ioutil.WriteFile(filePath, newJson, os.ModePerm)
if err != nil {
runtime.LogError(a.ctx, "Could not update host list:")
runtime.LogError(a.ctx, err.Error())
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.InfoDialog,
Title: "Could not update host list",