mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-06-28 05:25:11 +00:00
Zenity dialogs
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/garraflavatra/rolens/internal/open_file"
|
||||
"github.com/gen2brain/beeep"
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/menu"
|
||||
"github.com/wailsapp/wails/v2/pkg/menu/keys"
|
||||
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
@ -87,31 +88,16 @@ func (a *App) Environment() EnvironmentInfo {
|
||||
}
|
||||
|
||||
func (a *App) PurgeLogDirectory() {
|
||||
sure, _ := wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{
|
||||
Title: "Confirm",
|
||||
Message: "Are you sure you want to remove all logfiles?",
|
||||
Buttons: []string{"Yes", "No"},
|
||||
DefaultButton: "Yes",
|
||||
CancelButton: "No",
|
||||
Type: wailsRuntime.WarningDialog,
|
||||
})
|
||||
|
||||
if sure != "Yes" {
|
||||
err := zenity.Question("Are you sure you want to remove all logfiles?", zenity.Title("Confirm"), zenity.WarningIcon)
|
||||
if err == zenity.ErrCanceled {
|
||||
return
|
||||
}
|
||||
|
||||
err := os.RemoveAll(a.Env.LogDirectory)
|
||||
err = os.RemoveAll(a.Env.LogDirectory)
|
||||
if err == nil {
|
||||
wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{
|
||||
Title: "Successfully purged log directory.",
|
||||
Type: wailsRuntime.InfoDialog,
|
||||
})
|
||||
zenity.Info("Successfully purged log directory.", zenity.InfoIcon)
|
||||
} else {
|
||||
wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{
|
||||
Title: "Encountered an error while purging log directory.",
|
||||
Message: err.Error(),
|
||||
Type: wailsRuntime.WarningDialog,
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Encountered an error while purging log directory."), zenity.WarningIcon)
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,14 +151,9 @@ func (a *App) OpenDirectory(id, title string) string {
|
||||
}
|
||||
|
||||
wailsRuntime.LogInfo(a.ctx, fmt.Sprintf("Opening directory ('%v')", title))
|
||||
dir, err := zenity.SelectFile(zenity.Title(title), zenity.Directory())
|
||||
|
||||
dir, err := wailsRuntime.OpenDirectoryDialog(a.ctx, wailsRuntime.OpenDialogOptions{
|
||||
Title: title,
|
||||
CanCreateDirectories: true,
|
||||
TreatPackagesAsDirectories: false,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if err != nil && err != zenity.ErrCanceled {
|
||||
wailsRuntime.LogWarning(a.ctx, "Encountered an error while opening directory:")
|
||||
wailsRuntime.LogWarning(a.ctx, err.Error())
|
||||
wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{
|
||||
@ -186,6 +167,20 @@ func (a *App) OpenDirectory(id, title string) string {
|
||||
return dir
|
||||
}
|
||||
|
||||
func (a *App) EnterText(title, info string) string {
|
||||
println("wertyuijhgfd")
|
||||
input, err := zenity.Entry(info, zenity.Title(title))
|
||||
|
||||
if err == zenity.ErrCanceled {
|
||||
return ""
|
||||
} else if err != nil {
|
||||
zenity.Info(err.Error(), zenity.Title("Encountered an error!"), zenity.ErrorIcon)
|
||||
return ""
|
||||
} else {
|
||||
return input
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) Beep() {
|
||||
if runtime.GOOS == "windows" {
|
||||
return
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
@ -46,11 +47,7 @@ func (a *App) Settings() Settings {
|
||||
if err != nil {
|
||||
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!",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info("Could not retrieve application settings, using defaults!", zenity.Title("Information"), zenity.WarningIcon)
|
||||
}
|
||||
return s
|
||||
}
|
||||
@ -62,11 +59,7 @@ func (a *App) UpdateSettings(jsonData string) Settings {
|
||||
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",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Malformed JSON"), zenity.ErrorIcon)
|
||||
return s
|
||||
}
|
||||
|
||||
@ -74,11 +67,7 @@ func (a *App) UpdateSettings(jsonData string) Settings {
|
||||
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",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Malformed JSON"), zenity.ErrorIcon)
|
||||
return s
|
||||
}
|
||||
|
||||
@ -87,11 +76,7 @@ func (a *App) UpdateSettings(jsonData string) Settings {
|
||||
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",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not update host list"), zenity.ErrorIcon)
|
||||
}
|
||||
|
||||
return s
|
||||
|
@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
@ -18,11 +19,7 @@ func (a *App) OpenCollection(hostKey, dbKey, collKey string) (result bson.M) {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not retrieve collection stats for "+collKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Could not retrieve collection stats for " + collKey,
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not get stats"), zenity.ErrorIcon)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -45,11 +42,7 @@ func (a *App) RenameCollection(hostKey, dbKey, collKey, newCollKey string) bool
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not rename collection "+collKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Could not rename " + collKey,
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while renaming collection"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
@ -58,15 +51,8 @@ func (a *App) RenameCollection(hostKey, dbKey, collKey, newCollKey string) bool
|
||||
}
|
||||
|
||||
func (a *App) TruncateCollection(hostKey, dbKey, collKey string) bool {
|
||||
sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Confirm",
|
||||
Message: "Are you sure you want to remove all items from " + collKey + "?",
|
||||
Buttons: []string{"Yes", "No"},
|
||||
DefaultButton: "Yes",
|
||||
CancelButton: "No",
|
||||
Type: runtime.WarningDialog,
|
||||
})
|
||||
if sure != "Yes" {
|
||||
err := zenity.Question("Are you sure you want to remove all items from "+collKey+"?", zenity.Title("Confirm"), zenity.WarningIcon)
|
||||
if err == zenity.ErrCanceled {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -79,11 +65,7 @@ func (a *App) TruncateCollection(hostKey, dbKey, collKey string) bool {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not truncate collection "+collKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Could not truncate " + collKey,
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while truncating collection"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
@ -92,15 +74,8 @@ func (a *App) TruncateCollection(hostKey, dbKey, collKey string) bool {
|
||||
}
|
||||
|
||||
func (a *App) DropCollection(hostKey, dbKey, collKey string) bool {
|
||||
sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Confirm",
|
||||
Message: "Are you sure you want to drop " + collKey + "?",
|
||||
Buttons: []string{"Yes", "No"},
|
||||
DefaultButton: "Yes",
|
||||
CancelButton: "No",
|
||||
Type: runtime.WarningDialog,
|
||||
})
|
||||
if sure != "Yes" {
|
||||
err := zenity.Question("Are you sure you want to drop "+collKey+"?", zenity.Title("Confirm"), zenity.WarningIcon)
|
||||
if err == zenity.ErrCanceled {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -113,11 +88,7 @@ func (a *App) DropCollection(hostKey, dbKey, collKey string) bool {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not drop collection "+collKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Could not drop " + collKey,
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while dropping collection"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
@ -15,11 +16,7 @@ func (a *App) Aggregate(hostKey, dbKey, collKey, pipelineJson, settingsJson stri
|
||||
if err := json.Unmarshal([]byte(settingsJson), &settings); err != nil {
|
||||
runtime.LogError(a.ctx, "Could not parse aggregation settings:")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Couldn't parse aggregation settings",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Couldn't parse aggregation settings"), zenity.ErrorIcon)
|
||||
return
|
||||
}
|
||||
|
||||
@ -27,11 +24,7 @@ func (a *App) Aggregate(hostKey, dbKey, collKey, pipelineJson, settingsJson stri
|
||||
if err := bson.UnmarshalExtJSON([]byte(pipelineJson), true, &pipeline); err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not parse aggregation pipeline:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Couldn't parse aggregation pipeline",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Couldn't parse aggregation pipeline"), zenity.ErrorIcon)
|
||||
return
|
||||
}
|
||||
|
||||
@ -46,11 +39,7 @@ func (a *App) Aggregate(hostKey, dbKey, collKey, pipelineJson, settingsJson stri
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not get aggregation cursor:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Couldn't get aggregation cursor",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Couldn't get aggregation cursor"), zenity.ErrorIcon)
|
||||
return
|
||||
}
|
||||
|
||||
@ -58,11 +47,7 @@ func (a *App) Aggregate(hostKey, dbKey, collKey, pipelineJson, settingsJson stri
|
||||
if err := cursor.All(ctx, &results); err != nil {
|
||||
runtime.LogInfo(a.ctx, "Error while running aggregation pipeline:")
|
||||
runtime.LogInfo(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Error while running aggregation pipeline",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while running aggregation pipeline"), zenity.ErrorIcon)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
mongoOptions "go.mongodb.org/mongo-driver/mongo/options"
|
||||
@ -29,11 +30,7 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) QueryResult {
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Could not parse find form:")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Couldn't parse form",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not parse form"), zenity.ErrorIcon)
|
||||
return out
|
||||
}
|
||||
|
||||
@ -51,11 +48,7 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) QueryResult {
|
||||
if err != nil {
|
||||
runtime.LogInfo(a.ctx, "Invalid find query:")
|
||||
runtime.LogInfo(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Invalid query",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Invalid query"), zenity.ErrorIcon)
|
||||
return out
|
||||
}
|
||||
|
||||
@ -63,11 +56,7 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) QueryResult {
|
||||
if err != nil {
|
||||
runtime.LogInfo(a.ctx, "Invalid find projection:")
|
||||
runtime.LogInfo(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Invalid projection",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Invalid projection"), zenity.ErrorIcon)
|
||||
return out
|
||||
}
|
||||
|
||||
@ -75,11 +64,7 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) QueryResult {
|
||||
if err != nil {
|
||||
runtime.LogInfo(a.ctx, "Invalid find sort:")
|
||||
runtime.LogInfo(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Invalid sort",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Invalid sort"), zenity.ErrorIcon)
|
||||
return out
|
||||
}
|
||||
|
||||
@ -94,11 +79,7 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) QueryResult {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Encountered an error while counting documents:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while counting documents",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while counting docs"), zenity.ErrorIcon)
|
||||
return out
|
||||
}
|
||||
|
||||
@ -106,11 +87,7 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) QueryResult {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Encountered an error while performing query:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while performing query",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while querying"), zenity.ErrorIcon)
|
||||
return out
|
||||
}
|
||||
|
||||
@ -121,11 +98,7 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) QueryResult {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Encountered an error while performing query:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while performing query",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while querying"), zenity.ErrorIcon)
|
||||
return out
|
||||
}
|
||||
|
||||
@ -136,11 +109,7 @@ func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) QueryResult {
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Failed to marshal find BSON:")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Failed to marshal BSON",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Failed to marshal JSON"), zenity.ErrorIcon)
|
||||
return out
|
||||
}
|
||||
out.Results = append(out.Results, string(marshalled))
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
@ -63,10 +64,7 @@ func (a *App) SaveQuery(jsonData string) string {
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Add query: malformed form")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Malformed JSON",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Malformed JSON"), zenity.ErrorIcon)
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -74,10 +72,7 @@ func (a *App) SaveQuery(jsonData string) string {
|
||||
queries[query.Name] = query
|
||||
err = updateQueryFile(a, queries)
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not update query list",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not update query list"), zenity.ErrorIcon)
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -88,10 +83,7 @@ func (a *App) RemoveQuery(queryName string) {
|
||||
queries := a.SavedQueries()
|
||||
delete(queries, queryName)
|
||||
if err := updateQueryFile(a, queries); err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not update query list",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not update query list"), zenity.ErrorIcon)
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,19 +93,13 @@ func (a *App) UpdateQueries(jsonData string) bool {
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Update queries: malformed form")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Malformed JSON",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Malformed JSON"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
err = updateQueryFile(a, queries)
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not save queries",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not save queries"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
@ -21,11 +22,7 @@ func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Encountered an error while creating index cursor:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while creating index cursor",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while creating cursor"), zenity.ErrorIcon)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -34,11 +31,7 @@ func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Encountered an error while executing index cursor:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while executing index cursor",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while running cursor"), zenity.ErrorIcon)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -70,11 +63,7 @@ func (a *App) CreateIndex(hostKey, dbKey, collKey, jsonData string) string {
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Could not parse index JSON:")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Couldn't parse JSON",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not parse JSON"), zenity.ErrorIcon)
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -104,11 +93,7 @@ func (a *App) CreateIndex(hostKey, dbKey, collKey, jsonData string) string {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Encountered an error while creating index:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Error while creating index",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while creating index"), zenity.ErrorIcon)
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -126,11 +111,7 @@ func (a *App) DropIndex(hostKey, dbKey, collKey, indexName string) bool {
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Encountered an error while creating index drop cursor:")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while creating index cursor",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while creating drop cursor"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
@ -19,11 +20,7 @@ func (a *App) InsertItems(hostKey, dbKey, collKey, jsonData string) interface{}
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Could not parse insert JSON:")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Couldn't parse JSON",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not parse JSON"), zenity.ErrorIcon)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -37,11 +34,7 @@ func (a *App) InsertItems(hostKey, dbKey, collKey, jsonData string) interface{}
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Encountered an error while performing insert:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while performing query",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while performing insert"), zenity.ErrorIcon)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
@ -14,15 +15,8 @@ func (a *App) RemoveItems(hostKey, dbKey, collKey, jsonData string, many bool) i
|
||||
jsonData = strings.TrimSpace(jsonData)
|
||||
|
||||
if len(jsonData) == 0 {
|
||||
sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Confirm",
|
||||
Message: "Are you sure you want to drop all items in " + collKey + "?",
|
||||
Buttons: []string{"Yes", "No"},
|
||||
DefaultButton: "Yes",
|
||||
CancelButton: "No",
|
||||
Type: runtime.WarningDialog,
|
||||
})
|
||||
if sure != "Yes" {
|
||||
err := zenity.Question("Are you sure you want to drop all items in "+collKey+"?", zenity.Title("Confirm"), zenity.WarningIcon)
|
||||
if err == zenity.ErrCanceled {
|
||||
return 0
|
||||
}
|
||||
} else {
|
||||
@ -30,11 +24,7 @@ func (a *App) RemoveItems(hostKey, dbKey, collKey, jsonData string, many bool) i
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Could not parse remove query:")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Couldn't parse JSON",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not parse JSON"), zenity.ErrorIcon)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
@ -57,11 +47,7 @@ func (a *App) RemoveItems(hostKey, dbKey, collKey, jsonData string, many bool) i
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Encountered an error while performing remove:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while removing items",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while performing remove"), zenity.ErrorIcon)
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -82,11 +68,8 @@ func (a *App) RemoveItemById(hostKey, dbKey, collKey, itemId string) bool {
|
||||
if err != nil && err != mongo.ErrNoDocuments {
|
||||
runtime.LogWarning(a.ctx, "Encountered an error while performing remove by id:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while removing item" + itemId,
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while performing remove"), zenity.ErrorIcon)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@ -25,11 +26,7 @@ func (a *App) UpdateItems(hostKey, dbKey, collKey string, formJson string) int64
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Could not parse update form:")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Couldn't parse form",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not parse form"), zenity.ErrorIcon)
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -47,11 +44,7 @@ func (a *App) UpdateItems(hostKey, dbKey, collKey string, formJson string) int64
|
||||
runtime.LogWarning(a.ctx, "Invalid update query:")
|
||||
runtime.LogWarning(a.ctx, form.Query)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Invalid update query",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Invalid update query"), zenity.ErrorIcon)
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -64,11 +57,7 @@ func (a *App) UpdateItems(hostKey, dbKey, collKey string, formJson string) int64
|
||||
runtime.LogWarning(a.ctx, "Invalid update parameter value:")
|
||||
runtime.LogWarning(a.ctx, param.Value)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Invalid update query",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Invalid update query"), zenity.ErrorIcon)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
@ -85,11 +74,7 @@ func (a *App) UpdateItems(hostKey, dbKey, collKey string, formJson string) int64
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Encountered an error while performing update:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Encountered an error while updating items",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while performing update"), zenity.ErrorIcon)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
@ -14,21 +15,14 @@ import (
|
||||
func (a *App) connectToHost(hostKey string) (*mongo.Client, context.Context, func(), error) {
|
||||
hosts, err := a.Hosts()
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not retrieve hosts",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while getting hosts"), zenity.ErrorIcon)
|
||||
return nil, nil, nil, errors.New("could not retrieve hosts")
|
||||
}
|
||||
|
||||
h := hosts[hostKey]
|
||||
if len(h.URI) == 0 {
|
||||
runtime.LogInfo(a.ctx, "Invalid URI (len == 0) for host "+hostKey)
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Invalid uri",
|
||||
Message: "You haven't specified a valid uri for the selected host.",
|
||||
})
|
||||
zenity.Info("You haven't specified a valid uri for the selected host.", zenity.Title("Invalid query"), zenity.ErrorIcon)
|
||||
return nil, nil, nil, errors.New("invalid uri")
|
||||
}
|
||||
|
||||
@ -37,11 +31,7 @@ func (a *App) connectToHost(hostKey string) (*mongo.Client, context.Context, fun
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not connect to host "+hostKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Could not connect to " + h.Name,
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while connecting to "+h.Name), zenity.ErrorIcon)
|
||||
return nil, nil, nil, errors.New("could not establish a connection with " + h.Name)
|
||||
}
|
||||
|
||||
@ -62,11 +52,7 @@ func (a *App) OpenConnection(hostKey string) (databases []string) {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not retrieve database names for host "+hostKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Could not retrieve database list",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while getting databases"), zenity.ErrorIcon)
|
||||
return nil
|
||||
}
|
||||
defer close()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
@ -15,11 +16,7 @@ func (a *App) OpenDatabase(hostKey, dbKey string) (collections []string) {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not retrieve collection list for db "+dbKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Could not retrieve collection list for " + dbKey,
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while getting collections"), zenity.ErrorIcon)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -28,15 +25,8 @@ func (a *App) OpenDatabase(hostKey, dbKey string) (collections []string) {
|
||||
}
|
||||
|
||||
func (a *App) DropDatabase(hostKey, dbKey string) bool {
|
||||
sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Confirm",
|
||||
Message: "Are you sure you want to drop " + dbKey + "?",
|
||||
Buttons: []string{"Yes", "No"},
|
||||
DefaultButton: "Yes",
|
||||
CancelButton: "No",
|
||||
Type: runtime.WarningDialog,
|
||||
})
|
||||
if sure != "Yes" {
|
||||
err := zenity.Question("Are you sure you want to drop "+dbKey+"?", zenity.Title("Confirm"), zenity.WarningIcon)
|
||||
if err == zenity.ErrCanceled {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -49,11 +39,7 @@ func (a *App) DropDatabase(hostKey, dbKey string) bool {
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not drop db "+dbKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Could not drop " + dbKey,
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while dropping database"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
@ -32,21 +33,13 @@ func (a *App) PerformExport(jsonData string) bool {
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Could not unmarshal export form")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Could not unmarshal JSON",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not parse JSON"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
hosts, err := a.Hosts()
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Could not retrieve hosts",
|
||||
Message: err.Error(),
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while getting hosts"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
host := hosts[info.HostKey]
|
||||
@ -58,10 +51,7 @@ func (a *App) PerformExport(jsonData string) bool {
|
||||
|
||||
case FileTypeDump:
|
||||
if !a.Env.HasMongoDump {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "You need to install mongodump to perform a dump.",
|
||||
})
|
||||
zenity.Info("You need to install mongodump to perform a dump.", zenity.Title("Additional software required"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
@ -92,11 +82,7 @@ func (a *App) PerformExport(jsonData string) bool {
|
||||
}
|
||||
|
||||
default:
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.ErrorDialog,
|
||||
Title: "Unrecognised export file type",
|
||||
Message: string(info.FileType),
|
||||
})
|
||||
zenity.Info(fmt.Sprintf("File type '%v' is not known.", info.FileType), zenity.Title("Unrecognised file type"), zenity.ErrorIcon)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
@ -56,10 +57,7 @@ func (a *App) Hosts() (map[string]Host, error) {
|
||||
func (a *App) AddHost(jsonData string) error {
|
||||
hosts, err := a.Hosts()
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not retrieve hosts",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while retrieving hosts"), zenity.ErrorIcon)
|
||||
return errors.New("could not retrieve existing host list")
|
||||
}
|
||||
|
||||
@ -68,10 +66,7 @@ func (a *App) AddHost(jsonData string) error {
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Add host: malformed form")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Malformed JSON",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not parse JSON"), zenity.ErrorIcon)
|
||||
return errors.New("invalid JSON")
|
||||
}
|
||||
|
||||
@ -79,20 +74,14 @@ func (a *App) AddHost(jsonData string) error {
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Add host: failed to generate a UUID")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Failed to generate a UUID",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while generating UUID"), zenity.ErrorIcon)
|
||||
return errors.New("could not generate a UUID")
|
||||
}
|
||||
|
||||
hosts[id.String()] = newHost
|
||||
err = updateHostsFile(a, hosts)
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not update host list",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while updating host list"), zenity.ErrorIcon)
|
||||
return errors.New("could not update host list")
|
||||
}
|
||||
|
||||
@ -102,10 +91,7 @@ func (a *App) AddHost(jsonData string) error {
|
||||
func (a *App) UpdateHost(hostKey string, jsonData string) error {
|
||||
hosts, err := a.Hosts()
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not retrieve hosts",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while getting hosts"), zenity.ErrorIcon)
|
||||
return errors.New("could not retrieve existing host list")
|
||||
}
|
||||
|
||||
@ -114,20 +100,14 @@ func (a *App) UpdateHost(hostKey string, jsonData string) error {
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, "Could not parse update host JSON")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Malformed JSON",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not parse JSON"), zenity.ErrorIcon)
|
||||
return errors.New("invalid JSON")
|
||||
}
|
||||
|
||||
hosts[hostKey] = host
|
||||
err = updateHostsFile(a, hosts)
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not update host list",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while updating hosts"), zenity.ErrorIcon)
|
||||
return errors.New("could not update host list")
|
||||
}
|
||||
|
||||
@ -137,22 +117,12 @@ func (a *App) UpdateHost(hostKey string, jsonData string) error {
|
||||
func (a *App) RemoveHost(key string) error {
|
||||
hosts, err := a.Hosts()
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not retrieve hosts",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while retrieving hosts"), zenity.ErrorIcon)
|
||||
return errors.New("could not retrieve existing host list")
|
||||
}
|
||||
|
||||
sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Confirm",
|
||||
Message: "Are you sure you want to remove " + hosts[key].Name + "?",
|
||||
Buttons: []string{"Yes", "No"},
|
||||
DefaultButton: "Yes",
|
||||
CancelButton: "No",
|
||||
Type: runtime.WarningDialog,
|
||||
})
|
||||
if sure != "Yes" {
|
||||
err = zenity.Question("Are you sure you want to remove "+hosts[key].Name+"?", zenity.Title("Confirm"), zenity.WarningIcon)
|
||||
if err == zenity.ErrCanceled {
|
||||
return errors.New("operation aborted")
|
||||
}
|
||||
|
||||
@ -160,10 +130,7 @@ func (a *App) RemoveHost(key string) error {
|
||||
err = updateHostsFile(a, hosts)
|
||||
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not update host list",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while updating hosts"), zenity.ErrorIcon)
|
||||
return errors.New("could not update host list")
|
||||
}
|
||||
return nil
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
@ -100,19 +101,13 @@ func (a *App) UpdateViewStore(jsonData string) error {
|
||||
var viewStore ViewStore
|
||||
err := json.Unmarshal([]byte(jsonData), &viewStore)
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Malformed JSON",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Could not parse JSON"), zenity.ErrorIcon)
|
||||
return errors.New("invalid JSON")
|
||||
}
|
||||
|
||||
err = updateViewStore(a, viewStore)
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not update view store",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while updating view store"), zenity.ErrorIcon)
|
||||
return errors.New("could not update view store")
|
||||
}
|
||||
|
||||
@ -122,22 +117,12 @@ func (a *App) UpdateViewStore(jsonData string) error {
|
||||
func (a *App) RemoveView(viewKey string) error {
|
||||
views, err := a.Views()
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not retrieve views",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while getting views"), zenity.ErrorIcon)
|
||||
return errors.New("could not retrieve existing view store")
|
||||
}
|
||||
|
||||
sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Confirm",
|
||||
Message: "Are you sure you want to remove " + views[viewKey].Name + "?",
|
||||
Buttons: []string{"Yes", "No"},
|
||||
DefaultButton: "Yes",
|
||||
CancelButton: "No",
|
||||
Type: runtime.WarningDialog,
|
||||
})
|
||||
if sure != "Yes" {
|
||||
err = zenity.Question("Are you sure you want to remove "+views[viewKey].Name+"?", zenity.Title("Confirm"), zenity.WarningIcon)
|
||||
if err == zenity.ErrCanceled {
|
||||
return errors.New("operation aborted")
|
||||
}
|
||||
|
||||
@ -145,10 +130,7 @@ func (a *App) RemoveView(viewKey string) error {
|
||||
err = updateViewStore(a, views)
|
||||
|
||||
if err != nil {
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Type: runtime.InfoDialog,
|
||||
Title: "Could not update view store",
|
||||
})
|
||||
zenity.Info(err.Error(), zenity.Title("Error while updating view store"), zenity.ErrorIcon)
|
||||
return errors.New("could not update view store")
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user