handle setup errors more gracefully
This commit is contained in:
parent
1d9132de3b
commit
997e8b419f
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
* Switch to "process" provider for AWS credentials (much less hacky)
|
* Switch to "process" provider for AWS credentials (much less hacky)
|
||||||
* Session timeout (plain duration, or activity-based?)
|
* Session timeout (plain duration, or activity-based?)
|
||||||
* Fix rehide behavior when new request comes in while old one is still being resolved
|
* ~Fix rehide behavior when new request comes in while old one is still being resolved~
|
||||||
* Additional hotkey configuration (approve/deny at the very least)
|
* Additional hotkey configuration (approve/deny at the very least)
|
||||||
* Logging
|
* Logging
|
||||||
* Icon
|
* Icon
|
||||||
|
@ -75,15 +75,27 @@ pub async fn connect_db() -> Result<SqlitePool, SetupError> {
|
|||||||
async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
|
async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
|
||||||
APP.set(app.handle()).unwrap();
|
APP.set(app.handle()).unwrap();
|
||||||
|
|
||||||
let is_first_launch = config::get_or_create_db_path()?.exists();
|
// get_or_create_db_path doesn't create the actual db file, just the directory
|
||||||
|
let is_first_launch = !config::get_or_create_db_path()?.exists();
|
||||||
|
|
||||||
let pool = connect_db().await?;
|
let pool = connect_db().await?;
|
||||||
let conf = AppConfig::load(&pool).await?;
|
|
||||||
|
let conf = match AppConfig::load(&pool).await {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(SetupError::ConfigParseError(_)) => {
|
||||||
|
Err("Could not load configuration from database. Reverting to defaults.")
|
||||||
|
.error_popup("Setup error");
|
||||||
|
AppConfig::default()
|
||||||
|
},
|
||||||
|
err => err?,
|
||||||
|
};
|
||||||
|
|
||||||
let session = Session::load(&pool).await?;
|
let session = Session::load(&pool).await?;
|
||||||
let srv = Server::new(conf.listen_addr, conf.listen_port, app.handle()).await?;
|
let srv = Server::new(conf.listen_addr, conf.listen_port, app.handle()).await?;
|
||||||
|
|
||||||
config::set_auto_launch(conf.start_on_login)?;
|
config::set_auto_launch(conf.start_on_login)?;
|
||||||
config::register_hotkeys(&conf.hotkeys)?;
|
config::register_hotkeys(&conf.hotkeys).error_popup("Setup error");
|
||||||
|
|
||||||
// if session is empty, this is probably the first launch, so don't autohide
|
// if session is empty, this is probably the first launch, so don't autohide
|
||||||
if !conf.start_minimized || is_first_launch {
|
if !conf.start_minimized || is_first_launch {
|
||||||
app.get_window("main")
|
app.get_window("main")
|
||||||
|
@ -24,7 +24,7 @@ pub trait ErrorPopup {
|
|||||||
fn error_popup(self, title: &str);
|
fn error_popup(self, title: &str);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Error> ErrorPopup for Result<(), E> {
|
impl<E: std::fmt::Display> ErrorPopup for Result<(), E> {
|
||||||
fn error_popup(self, title: &str) {
|
fn error_popup(self, title: &str) {
|
||||||
if let Err(e) = self {
|
if let Err(e) = self {
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user