mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-07-22 15:18:02 +00:00
Logging
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/garraflavatra/rolens/internal/utils/open_file"
|
||||
"github.com/wailsapp/wails/v2/pkg/menu"
|
||||
"github.com/wailsapp/wails/v2/pkg/menu/keys"
|
||||
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
@ -24,6 +25,7 @@ type EnvironmentInfo struct {
|
||||
|
||||
HomeDirectory string `json:"homeDirectory"`
|
||||
DataDirectory string `json:"dataDirectory"`
|
||||
LogDirectory string `json:"logDirectory"`
|
||||
}
|
||||
|
||||
type App struct {
|
||||
@ -32,16 +34,7 @@ type App struct {
|
||||
}
|
||||
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
}
|
||||
|
||||
func (a *App) Startup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
wailsEnv := wailsRuntime.Environment(a.ctx)
|
||||
|
||||
a.Env.Arch = wailsEnv.Arch
|
||||
a.Env.BuildType = wailsEnv.BuildType
|
||||
a.Env.Platform = wailsEnv.Platform
|
||||
a := &App{}
|
||||
|
||||
_, err := exec.LookPath("mongodump")
|
||||
a.Env.HasMongoDump = err == nil
|
||||
@ -57,15 +50,35 @@ func (a *App) Startup(ctx context.Context) {
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
a.Env.DataDirectory = filepath.Join(a.Env.HomeDirectory, "/AppData/Local/Rolens")
|
||||
a.Env.LogDirectory = filepath.Join(a.Env.HomeDirectory, "/AppData/Local/Rolens/Logs")
|
||||
case "darwin":
|
||||
a.Env.DataDirectory = filepath.Join(a.Env.HomeDirectory, "/Library/Application Support/Rolens")
|
||||
a.Env.LogDirectory = filepath.Join(a.Env.HomeDirectory, "/Library/Logs/Rolens")
|
||||
case "linux":
|
||||
a.Env.DataDirectory = filepath.Join(a.Env.HomeDirectory, "/.config/Rolens")
|
||||
a.Env.DataDirectory = filepath.Join(a.Env.HomeDirectory, "/.config/rolens")
|
||||
a.Env.LogDirectory = filepath.Join(a.Env.HomeDirectory, "/.config/rolens/logs")
|
||||
default:
|
||||
panic(errors.New("unsupported platform"))
|
||||
}
|
||||
|
||||
_ = os.MkdirAll(a.Env.DataDirectory, os.ModePerm)
|
||||
os.MkdirAll(a.Env.DataDirectory, os.ModePerm)
|
||||
os.MkdirAll(a.Env.LogDirectory, os.ModePerm)
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *App) Startup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
wailsRuntime.LogInfo(a.ctx, "Startup")
|
||||
|
||||
wailsEnv := wailsRuntime.Environment(a.ctx)
|
||||
a.Env.Arch = wailsEnv.Arch
|
||||
a.Env.BuildType = wailsEnv.BuildType
|
||||
a.Env.Platform = wailsEnv.Platform
|
||||
}
|
||||
|
||||
func (a *App) Shutdown(ctx context.Context) {
|
||||
wailsRuntime.LogInfo(a.ctx, "Shutdown")
|
||||
}
|
||||
|
||||
func (a *App) Environment() EnvironmentInfo {
|
||||
@ -109,6 +122,8 @@ func (a *App) Menu() *menu.Menu {
|
||||
|
||||
helpMenu := appMenu.AddSubmenu("Help")
|
||||
helpMenu.AddText("User guide", nil, func(cd *menu.CallbackData) { wailsRuntime.BrowserOpenURL(a.ctx, "") })
|
||||
helpMenu.AddSeparator()
|
||||
helpMenu.AddText("Open log directory", nil, func(cd *menu.CallbackData) { open_file.Reveal(a.Env.LogDirectory) })
|
||||
|
||||
return appMenu
|
||||
}
|
||||
@ -118,6 +133,8 @@ func (a *App) OpenDirectory(id, title string) string {
|
||||
title = "Choose a directory"
|
||||
}
|
||||
|
||||
wailsRuntime.LogInfo(a.ctx, fmt.Sprintf("Opening directory ('%v')", title))
|
||||
|
||||
dir, err := wailsRuntime.OpenDirectoryDialog(a.ctx, wailsRuntime.OpenDialogOptions{
|
||||
Title: title,
|
||||
CanCreateDirectories: true,
|
||||
@ -125,7 +142,8 @@ func (a *App) OpenDirectory(id, title string) string {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
wailsRuntime.LogWarning(a.ctx, "Encountered an error while opening directory:")
|
||||
wailsRuntime.LogWarning(a.ctx, err.Error())
|
||||
wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{
|
||||
Type: wailsRuntime.ErrorDialog,
|
||||
Title: "Encountered an error while opening directory",
|
||||
@ -133,5 +151,6 @@ func (a *App) OpenDirectory(id, title string) string {
|
||||
})
|
||||
}
|
||||
|
||||
wailsRuntime.LogInfo(a.ctx, "Chosen directory: "+dir)
|
||||
return dir
|
||||
}
|
||||
|
Reference in New Issue
Block a user