1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-06-28 05:25:11 +00:00

Removed Zenity dependency

This commit is contained in:
2023-12-22 15:26:29 +01:00
parent 208db82ba7
commit ef9318576a
16 changed files with 59 additions and 195 deletions

View File

@ -166,3 +166,25 @@ func (a *App) AskConfirmation(message string) bool {
return false
}
}
func (a *App) ChooseDirectory(title string) string {
if title == "" {
title = "Choose a directory"
}
dir, err := wailsRuntime.OpenDirectoryDialog(a.ctx, wailsRuntime.OpenDialogOptions{
Title: title,
DefaultDirectory: a.Env.DownloadDirectory,
CanCreateDirectories: true,
})
if err != nil {
wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{
Title: "Error while opening directory",
Message: err.Error(),
Type: wailsRuntime.ErrorDialog,
})
}
return dir
}

View File

@ -4,12 +4,8 @@ import (
"os"
"path"
"strings"
"github.com/ncruces/zenity"
)
var showError = true
type AppLogger struct {
directory string
filename string
@ -26,24 +22,8 @@ func NewAppLogger(directory, filename string) *AppLogger {
func (l *AppLogger) Print(message string) {
os.MkdirAll(l.directory, os.ModePerm)
f, err := os.OpenFile(l.filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil && showError {
zenity.Error(err.Error(), zenity.Title("Could not open logfile!"), zenity.ErrorIcon)
showError = false
}
if _, err = f.WriteString(message); err != nil {
if showError {
zenity.Error(err.Error(), zenity.Title("Could not write to logfile!"), zenity.ErrorIcon)
showError = false
} else {
showError = true
}
} else {
showError = true
}
f, _ := os.OpenFile(l.filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
f.WriteString(message)
f.Close()
}

View File

@ -1,17 +0,0 @@
package ui
import "github.com/ncruces/zenity"
func (u *UI) OpenDirectory(title string) string {
if title == "" {
title = "Choose a directory"
}
dir, err := zenity.SelectFile(zenity.Title(title), zenity.Directory(), zenity.Modal())
if err != nil && err != zenity.ErrCanceled {
zenity.Error("Error while opening directory", zenity.ErrorIcon)
}
return dir
}

View File

@ -1,34 +0,0 @@
package ui
import (
"time"
"github.com/ncruces/zenity"
)
// @todo: this takes ~0.5 seconds. Improve?
func (u *UI) StartProgressBar(id uint, title string) {
if title == "" {
// default title
title = "Loading…"
}
p, err := zenity.Progress(zenity.Title(title), zenity.Pulsate(), zenity.Modal())
if err != nil {
return
}
u.progressBars[id] = p
}
func (u *UI) StopProgressBar(id uint) {
for try := 0; try < 10; try++ {
if p := u.progressBars[id]; p != nil {
p.Complete()
p.Close()
p = nil
return
}
println("Progress dialog not found:", id, try)
time.Sleep(100 * time.Millisecond)
}
}

View File

@ -5,18 +5,14 @@ import (
"runtime"
"github.com/gen2brain/beeep"
"github.com/ncruces/zenity"
)
type UI struct {
ctx context.Context
progressBars map[uint]zenity.ProgressDialog
}
func New() *UI {
return &UI{
progressBars: make(map[uint]zenity.ProgressDialog),
}
return &UI{}
}
func (u *UI) Startup(ctx context.Context) {