upgrade to tauri 2.0 beta

This commit is contained in:
2024-06-01 20:17:50 -04:00
parent b165965289
commit 816bd7db00
28 changed files with 6323 additions and 1065 deletions

View File

@ -33,10 +33,9 @@ pub fn run() -> tauri::Result<()> {
tauri::Builder::default()
.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
show_main_window(app)
.error_popup("Failed to show main window");
.blocking_error_popup("Failed to show main window")
}))
.system_tray(tray::create())
.on_system_tray_event(tray::handle_event)
.plugin(tauri_plugin_global_shortcut::Builder::default().build())
.invoke_handler(tauri::generate_handler![
ipc::unlock,
ipc::respond,
@ -77,8 +76,8 @@ pub async fn connect_db() -> Result<SqlitePool, SetupError> {
async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
APP.set(app.handle()).unwrap();
APP.set(app.handle().clone()).unwrap();
tray::setup(app)?;
// 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?;
@ -96,7 +95,7 @@ async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
};
let session = Session::load(&pool).await?;
Server::start(app.handle())?;
Server::start(app.handle().clone())?;
config::set_auto_launch(conf.start_on_login)?;
if let Err(_e) = config::set_auto_launch(conf.start_on_login) {
@ -123,7 +122,7 @@ async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
app.manage(state);
// make sure we do this after managing app state, so that it doesn't panic
start_auto_locker(app.app_handle());
start_auto_locker(app.app_handle().clone());
Ok(())
}
@ -138,7 +137,7 @@ fn start_auto_locker(app: AppHandle) {
tokio::time::sleep(delay).await;
if state.should_auto_lock().await {
state.lock().await.error_popup("Failed to lock Creddy");
state.lock().await.error_popup("Failed to lock Creddy").await;
}
}
});
@ -146,27 +145,27 @@ fn start_auto_locker(app: AppHandle) {
pub fn show_main_window(app: &AppHandle) -> Result<(), WindowError> {
let w = app.get_window("main").ok_or(WindowError::NoMainWindow)?;
let w = app.get_webview_window("main").ok_or(WindowError::NoMainWindow)?;
w.show()?;
app.tray_handle()
.get_item("show_hide")
.set_title("Hide")?;
// app.tray_handle()
// .get_item("show_hide")
// .set_title("Hide")?;
Ok(())
}
pub fn hide_main_window(app: &AppHandle) -> Result<(), WindowError> {
let w = app.get_window("main").ok_or(WindowError::NoMainWindow)?;
let w = app.get_webview_window("main").ok_or(WindowError::NoMainWindow)?;
w.hide()?;
app.tray_handle()
.get_item("show_hide")
.set_title("Show")?;
// app.tray_handle()
// .get_item("show_hide")
// .set_title("Show")?;
Ok(())
}
pub fn toggle_main_window(app: &AppHandle) -> Result<(), WindowError> {
let w = app.get_window("main").ok_or(WindowError::NoMainWindow)?;
let w = app.get_webview_window("main").ok_or(WindowError::NoMainWindow)?;
if w.is_visible()? {
hide_main_window(app)
}