diff --git a/frontend/src/lib/stores/busy.js b/frontend/src/lib/stores/busy.js index 9f198a0..caf6655 100644 --- a/frontend/src/lib/stores/busy.js +++ b/frontend/src/lib/stores/busy.js @@ -1,13 +1,26 @@ +import { StartProgressBar, StopProgressBar } from '$wails/go/ui/UI'; import { writable } from 'svelte/store'; const { update, subscribe } = writable(0); +let timer; +let progressBarShown = false; subscribe(isBusy => { if (isBusy) { document.body.classList.add('busy'); + if (!progressBarShown) { + progressBarShown = true; + timer = setTimeout(() => StartProgressBar(''), 100); + } } else { + if (timer) { + clearTimeout(timer); + timer = undefined; + } + progressBarShown = false; document.body.classList.remove('busy'); + StopProgressBar(); } }); diff --git a/frontend/src/organisms/connection/collection/find.svelte b/frontend/src/organisms/connection/collection/find.svelte index 04f1e50..4e8e37b 100644 --- a/frontend/src/organisms/connection/collection/find.svelte +++ b/frontend/src/organisms/connection/collection/find.svelte @@ -5,6 +5,7 @@ import ObjectGrid from '$components/objectgrid.svelte'; import input from '$lib/actions/input'; import { deepClone } from '$lib/objects'; + import busy from '$lib/stores/busy'; import queries from '$lib/stores/queries'; import applicationSettings from '$lib/stores/settings'; import views from '$lib/stores/views'; @@ -41,6 +42,7 @@ $: activePage = (submittedForm.limit && submittedForm.skip && result?.results?.length) ? submittedForm.skip / submittedForm.limit : 0; async function submitQuery() { + busy.start(); activePath = []; const newResult = await FindItems(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(form)); if (newResult) { @@ -48,6 +50,7 @@ result = newResult; submittedForm = deepClone(form); } + busy.end(); resetFocus(); } diff --git a/frontend/wailsjs/go/ui/UI.d.ts b/frontend/wailsjs/go/ui/UI.d.ts index a978303..ea1a471 100755 --- a/frontend/wailsjs/go/ui/UI.d.ts +++ b/frontend/wailsjs/go/ui/UI.d.ts @@ -10,4 +10,8 @@ export function OpenDirectory(arg1:string,arg2:string):Promise; export function Reveal(arg1:string):Promise; +export function StartProgressBar(arg1:string):Promise; + export function Startup(arg1:context.Context):Promise; + +export function StopProgressBar():Promise; diff --git a/frontend/wailsjs/go/ui/UI.js b/frontend/wailsjs/go/ui/UI.js index d07e379..2396e65 100755 --- a/frontend/wailsjs/go/ui/UI.js +++ b/frontend/wailsjs/go/ui/UI.js @@ -18,6 +18,14 @@ export function Reveal(arg1) { return window['go']['ui']['UI']['Reveal'](arg1); } +export function StartProgressBar(arg1) { + return window['go']['ui']['UI']['StartProgressBar'](arg1); +} + export function Startup(arg1) { return window['go']['ui']['UI']['Startup'](arg1); } + +export function StopProgressBar() { + return window['go']['ui']['UI']['StopProgressBar'](); +} diff --git a/internal/app/collection_find.go b/internal/app/collection_find.go index 316a253..4ab1128 100644 --- a/internal/app/collection_find.go +++ b/internal/app/collection_find.go @@ -2,6 +2,7 @@ package app import ( "encoding/json" + "time" "github.com/ncruces/zenity" "github.com/wailsapp/wails/v2/pkg/runtime" @@ -23,6 +24,7 @@ type QueryResult struct { } func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) QueryResult { + time.Sleep(2 * time.Second) var out QueryResult var form Query diff --git a/internal/ui/dialogs.go b/internal/ui/dialogs.go index e4cb657..0275340 100644 --- a/internal/ui/dialogs.go +++ b/internal/ui/dialogs.go @@ -7,7 +7,7 @@ func (u *UI) OpenDirectory(id, title string) string { title = "Choose a directory" } - dir, err := zenity.SelectFile(zenity.Title(title), zenity.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) @@ -17,7 +17,7 @@ func (u *UI) OpenDirectory(id, title string) string { } func (u *UI) EnterText(title, info, defaultEntry string) string { - input, err := zenity.Entry(info, zenity.Title(title), zenity.EntryText(defaultEntry)) + input, err := zenity.Entry(info, zenity.Title(title), zenity.EntryText(defaultEntry), zenity.Modal()) if err == zenity.ErrCanceled { return "" diff --git a/internal/ui/progress.go b/internal/ui/progress.go new file mode 100644 index 0000000..83ad055 --- /dev/null +++ b/internal/ui/progress.go @@ -0,0 +1,28 @@ +package ui + +import "github.com/ncruces/zenity" + +func (u *UI) StartProgressBar(title string) { + if u.progress != nil { + // already loading + return + } + if title == "" { + // default title + title = "Loading" + } + p, err := zenity.Progress(zenity.Title(title), zenity.Pulsate(), zenity.NoCancel(), zenity.Modal()) + if err != nil { + return + } + u.progress = p +} + +func (u *UI) StopProgressBar() { + if u.progress == nil { + return + } + u.progress.Complete() + u.progress.Close() + u.progress = nil +} diff --git a/internal/ui/ui.go b/internal/ui/ui.go index 7dfde05..5cafb96 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -5,10 +5,12 @@ import ( "runtime" "github.com/gen2brain/beeep" + "github.com/ncruces/zenity" ) type UI struct { - ctx context.Context + ctx context.Context + progress zenity.ProgressDialog } func New() *UI {