forked from go/golangs_learn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
package models
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/leonelquinteros/gotext"
|
|
"github.com/wailsapp/wails/v2"
|
|
"github.com/wailsapp/wails/v2/pkg/options/dialog"
|
|
)
|
|
|
|
type LoaderEventPayload struct {
|
|
Label string `json:"label"`
|
|
TemplateName string `json:"templateName"`
|
|
}
|
|
|
|
type NotificationEventPayload struct {
|
|
Label string `json:"label"`
|
|
Type string `json:"type"` // success | warning | error
|
|
}
|
|
|
|
type NgrokStateEventPayload struct {
|
|
ErrCode string `json:"errCode"`
|
|
Status string `json:"status"`
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
func ShowLoader(r *wails.Runtime, label string) {
|
|
r.Events.Emit("ytd:loader:show", LoaderEventPayload{Label: label, TemplateName: "card"})
|
|
}
|
|
|
|
func HideLoader(r *wails.Runtime) {
|
|
r.Events.Emit("ytd:loader:hide")
|
|
}
|
|
|
|
func SendNotification(r *wails.Runtime, payload NotificationEventPayload, isForeground bool) {
|
|
if isForeground {
|
|
r.Events.Emit("ytd:notification", payload)
|
|
return
|
|
}
|
|
|
|
types := map[string]dialog.DialogType{
|
|
"error": dialog.ErrorDialog,
|
|
"warning": dialog.WarningDialog,
|
|
"success": dialog.InfoDialog,
|
|
}
|
|
_, err := r.Dialog.Message(&dialog.MessageDialog{
|
|
Type: types[payload.Type],
|
|
Title: gotext.Get("An error occured"),
|
|
Message: payload.Label,
|
|
Buttons: []string{"OK"},
|
|
CancelButton: "OK",
|
|
})
|
|
if err != nil {
|
|
fmt.Println("SendNotification error", err)
|
|
return
|
|
}
|
|
}
|
|
|