display setup errors

This commit is contained in:
Joseph Montanaro 2023-04-30 10:52:46 -07:00
parent 913148a75a
commit 871dedf0a3
5 changed files with 41 additions and 14 deletions

View File

@ -17,7 +17,7 @@ tauri-build = { version = "1.0.4", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.5", features = ["api-all", "system-tray"] }
tauri = { version = "1.0.5", features = ["api-all", "dialog", "system-tray"] }
sodiumoxide = "0.2.7"
tokio = { version = ">=1.19", features = ["full"] }
sqlx = { version = "0.6.2", features = ["sqlite", "runtime-tokio-rustls"] }

View File

@ -90,6 +90,7 @@ pub fn set_auto_launch(is_configured: bool) -> Result<(), SetupError> {
pub fn get_or_create_db_path() -> Result<PathBuf, DataDirError> {
// debug_assertions doesn't always mean we are running in dev
if cfg!(debug_assertions) && std::env::var("HOME").is_ok() {
return Ok(PathBuf::from("./creddy.db"));
}

View File

@ -3,7 +3,9 @@
windows_subsystem = "windows"
)]
use std::error::Error;
use std::sync::mpsc::channel;
use once_cell::sync::OnceCell;
use sqlx::{
SqlitePool,
sqlite::SqlitePoolOptions,
@ -15,7 +17,10 @@ use tauri::{
Manager,
async_runtime as rt,
};
use once_cell::sync::OnceCell;
use tauri::api::dialog::{
MessageDialogBuilder,
MessageDialogKind,
};
mod config;
mod errors;
@ -61,7 +66,7 @@ async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
}
fn main() {
fn run() -> tauri::Result<()> {
tauri::Builder::default()
.system_tray(tray::create())
.on_system_tray_event(tray::handle_event)
@ -74,8 +79,7 @@ fn main() {
ipc::save_config,
])
.setup(|app| rt::block_on(setup(app)))
.build(tauri::generate_context!())
.expect("error while running tauri application")
.build(tauri::generate_context!())?
.run(|app, run_event| match run_event {
tauri::RunEvent::WindowEvent { label, event, .. } => match event {
tauri::WindowEvent::CloseRequested { api, .. } => {
@ -85,7 +89,23 @@ fn main() {
_ => ()
}
_ => ()
})
});
Ok(())
}
fn main() {
if let Err(e) = run() {
let (tx, rx) = channel();
MessageDialogBuilder::new(
"Creddy failed to start",
format!("{e}")
)
.kind(MessageDialogKind::Error)
.show(move |_| tx.send(true).unwrap());
rx.recv().unwrap();
}
}

View File

@ -29,10 +29,7 @@
if (alt && !event.altKey) return;
if (shift && !event.shiftKey) return;
if (event.code === hotkey) {
click();
}
else if (hotkey === 'Enter' && event.code === 'NumpadEnter') {
if (event.key === hotkey) {
click();
}
}
@ -41,6 +38,6 @@
<svelte:window on:keydown={handleHotkey} />
<a href="#" on:click="{click}" class={classes}>
<a href="/{target}" on:click|preventDefault="{click}" class={classes}>
<slot></slot>
</a>

View File

@ -1,5 +1,6 @@
<script>
import { invoke } from '@tauri-apps/api/tauri';
import { type } from '@tauri-apps/api/os';
import { appState } from '../lib/state.js';
import Nav from '../ui/Nav.svelte';
@ -21,6 +22,9 @@
$appState.config = await invoke('get_config');
}
}
let osType = '';
type().then(t => osType = t);
</script>
@ -52,7 +56,12 @@
</svelte:fragment>
</NumericSetting>
<NumericSetting title="Listen port" bind:value={$appState.config.listen_port} min=1 on:update={save}>
<NumericSetting
title="Listen port"
bind:value={$appState.config.listen_port}
min={osType === 'Windows_NT' ? 1 : 0}
on:update={save}
>
<svelte:fragment slot="description">
Listen for credentials requests on this port.
(Should be used with <code>$AWS_CONTAINER_CREDENTIALS_FULL_URI</code>)