mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 13:07:58 +00:00
Zenity progress bar
This commit is contained in:
parent
44c94d0d72
commit
5dd9e0573d
@ -1,13 +1,26 @@
|
|||||||
|
import { StartProgressBar, StopProgressBar } from '$wails/go/ui/UI';
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
const { update, subscribe } = writable(0);
|
const { update, subscribe } = writable(0);
|
||||||
|
|
||||||
|
let timer;
|
||||||
|
let progressBarShown = false;
|
||||||
subscribe(isBusy => {
|
subscribe(isBusy => {
|
||||||
if (isBusy) {
|
if (isBusy) {
|
||||||
document.body.classList.add('busy');
|
document.body.classList.add('busy');
|
||||||
|
if (!progressBarShown) {
|
||||||
|
progressBarShown = true;
|
||||||
|
timer = setTimeout(() => StartProgressBar(''), 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (timer) {
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = undefined;
|
||||||
|
}
|
||||||
|
progressBarShown = false;
|
||||||
document.body.classList.remove('busy');
|
document.body.classList.remove('busy');
|
||||||
|
StopProgressBar();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
import ObjectGrid from '$components/objectgrid.svelte';
|
import ObjectGrid from '$components/objectgrid.svelte';
|
||||||
import input from '$lib/actions/input';
|
import input from '$lib/actions/input';
|
||||||
import { deepClone } from '$lib/objects';
|
import { deepClone } from '$lib/objects';
|
||||||
|
import busy from '$lib/stores/busy';
|
||||||
import queries from '$lib/stores/queries';
|
import queries from '$lib/stores/queries';
|
||||||
import applicationSettings from '$lib/stores/settings';
|
import applicationSettings from '$lib/stores/settings';
|
||||||
import views from '$lib/stores/views';
|
import views from '$lib/stores/views';
|
||||||
@ -41,6 +42,7 @@
|
|||||||
$: activePage = (submittedForm.limit && submittedForm.skip && result?.results?.length) ? submittedForm.skip / submittedForm.limit : 0;
|
$: activePage = (submittedForm.limit && submittedForm.skip && result?.results?.length) ? submittedForm.skip / submittedForm.limit : 0;
|
||||||
|
|
||||||
async function submitQuery() {
|
async function submitQuery() {
|
||||||
|
busy.start();
|
||||||
activePath = [];
|
activePath = [];
|
||||||
const newResult = await FindItems(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(form));
|
const newResult = await FindItems(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(form));
|
||||||
if (newResult) {
|
if (newResult) {
|
||||||
@ -48,6 +50,7 @@
|
|||||||
result = newResult;
|
result = newResult;
|
||||||
submittedForm = deepClone(form);
|
submittedForm = deepClone(form);
|
||||||
}
|
}
|
||||||
|
busy.end();
|
||||||
resetFocus();
|
resetFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
frontend/wailsjs/go/ui/UI.d.ts
vendored
4
frontend/wailsjs/go/ui/UI.d.ts
vendored
@ -10,4 +10,8 @@ export function OpenDirectory(arg1:string,arg2:string):Promise<string>;
|
|||||||
|
|
||||||
export function Reveal(arg1:string):Promise<void>;
|
export function Reveal(arg1:string):Promise<void>;
|
||||||
|
|
||||||
|
export function StartProgressBar(arg1:string):Promise<void>;
|
||||||
|
|
||||||
export function Startup(arg1:context.Context):Promise<void>;
|
export function Startup(arg1:context.Context):Promise<void>;
|
||||||
|
|
||||||
|
export function StopProgressBar():Promise<void>;
|
||||||
|
@ -18,6 +18,14 @@ export function Reveal(arg1) {
|
|||||||
return window['go']['ui']['UI']['Reveal'](arg1);
|
return window['go']['ui']['UI']['Reveal'](arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function StartProgressBar(arg1) {
|
||||||
|
return window['go']['ui']['UI']['StartProgressBar'](arg1);
|
||||||
|
}
|
||||||
|
|
||||||
export function Startup(arg1) {
|
export function Startup(arg1) {
|
||||||
return window['go']['ui']['UI']['Startup'](arg1);
|
return window['go']['ui']['UI']['Startup'](arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function StopProgressBar() {
|
||||||
|
return window['go']['ui']['UI']['StopProgressBar']();
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ncruces/zenity"
|
"github.com/ncruces/zenity"
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
@ -23,6 +24,7 @@ type QueryResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) QueryResult {
|
func (a *App) FindItems(hostKey, dbKey, collKey, formJson string) QueryResult {
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
var out QueryResult
|
var out QueryResult
|
||||||
var form Query
|
var form Query
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ func (u *UI) OpenDirectory(id, title string) string {
|
|||||||
title = "Choose a directory"
|
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 {
|
if err != nil && err != zenity.ErrCanceled {
|
||||||
zenity.Error("Error while opening directory", zenity.ErrorIcon)
|
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 {
|
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 {
|
if err == zenity.ErrCanceled {
|
||||||
return ""
|
return ""
|
||||||
|
28
internal/ui/progress.go
Normal file
28
internal/ui/progress.go
Normal file
@ -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
|
||||||
|
}
|
@ -5,10 +5,12 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/gen2brain/beeep"
|
"github.com/gen2brain/beeep"
|
||||||
|
"github.com/ncruces/zenity"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UI struct {
|
type UI struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
progress zenity.ProgressDialog
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *UI {
|
func New() *UI {
|
||||||
|
Loading…
Reference in New Issue
Block a user