1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 13:07:58 +00:00

Merge branch 'dialogs_to_frontend'

This commit is contained in:
Romein van Buren 2023-06-23 15:22:10 +02:00
commit 2ecc664e48
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
6 changed files with 57 additions and 22 deletions

View File

@ -0,0 +1,38 @@
<script>
import Modal from '$components/modal.svelte';
import { createEventDispatcher, onMount, tick } from 'svelte';
export let title = '';
export let description = '';
export let value = '';
const dispatch = createEventDispatcher();
let input;
function submit() {
dispatch('submit', { value });
}
function close() {
dispatch('close');
}
onMount(() => tick().then(() => input.select()));
</script>
<Modal {title} on:close width="350px">
{#if description}
<p>{description}</p>
{/if}
<form on:submit|preventDefault={submit}>
<label class="field">
<input type="text" bind:value bind:this={input} spellcheck="false" />
</label>
</form>
<svelte:fragment slot="footer">
<button on:click={submit} class="btn">OK</button>
<button on:click={close} class="btn secondary">Cancel</button>
</svelte:fragment>
</Modal>

View File

@ -1,3 +1,5 @@
import InputDialog from '../dialogs/input.svelte';
function newDialog(dialogComponent, data = {}) {
const outlet = document.createElement('div');
outlet.className = 'dialogoutlet';
@ -15,6 +17,17 @@ function newDialog(dialogComponent, data = {}) {
return instance;
}
const dialogs = { new: newDialog };
function enterText(title = '', description = '', value = '') {
const instance = newDialog(InputDialog, { title, description, value });
return new Promise(resolve => {
instance.$on('submit', event => {
instance.$close();
resolve(event.detail.value);
});
});
}
const dialogs = { new: newDialog, enterText };
export default dialogs;

2
frontend/wailsjs/go/ui/UI.d.ts generated vendored
View File

@ -4,8 +4,6 @@ import {context} from '../models';
export function Beep():Promise<void>;
export function EnterText(arg1:string,arg2:string,arg3:string):Promise<string>;
export function OpenDirectory(arg1:string):Promise<string>;
export function Reveal(arg1:string):Promise<void>;

View File

@ -6,10 +6,6 @@ export function Beep() {
return window['go']['ui']['UI']['Beep']();
}
export function EnterText(arg1, arg2, arg3) {
return window['go']['ui']['UI']['EnterText'](arg1, arg2, arg3);
}
export function OpenDirectory(arg1) {
return window['go']['ui']['UI']['OpenDirectory'](arg1);
}

View File

@ -15,16 +15,3 @@ func (u *UI) OpenDirectory(title string) string {
return dir
}
func (u *UI) EnterText(title, info, defaultEntry string) string {
input, err := zenity.Entry(info, zenity.Title(title), zenity.EntryText(defaultEntry), zenity.Modal())
if err == zenity.ErrCanceled {
return ""
} else if err != nil {
zenity.Error(err.Error(), zenity.Title("Encountered an error!"), zenity.ErrorIcon)
return ""
} else {
return input
}
}

View File

@ -7,7 +7,6 @@ import (
"github.com/garraflavatra/rolens/internal"
"github.com/garraflavatra/rolens/internal/app"
uictrl "github.com/garraflavatra/rolens/internal/ui"
"github.com/ncruces/zenity"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/options"
@ -48,7 +47,11 @@ func main() {
defer func() {
if p := recover(); p != nil {
runtime.LogFatalf(ctx, "Application panicked: %v", p)
zenity.Error("A fatal error occured.")
runtime.MessageDialog(ctx, runtime.MessageDialogOptions{
Type: runtime.ErrorDialog,
Title: "A fatal error occured!",
Message: "Please try to restart the application, or consult the logs for more details.",
})
}
}()