#In Tauri V2, how can I get a my resource path before tauri::Builder?

4 messages · Page 1 of 1 (latest)

near ibex
#

In Tauri V2, to get a resource path you can use app.path().resolve("migration", BaseDirectory::Resource), the problem I have is I need to use the path before I have a reference to app. So how can I get the path?

Something like this:


#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {

    
    let app_handle = ???????
            
    let resource_path = app_handle.path().resolve("migration", BaseDirectory::Resource)
         .expect("Failed to resolve resource path");

    let migrations = load_migrations(resource_path);

            
    tauri::Builder::default()
        .setup(|app| {

            #[cfg(debug_assertions)] // only include this code on debug builds
            {
                let window = app.get_webview_window("main").unwrap();
                window.open_devtools();
            }
            Ok(())
        })
        .plugin(tauri_plugin_fs::init())
        .plugin(tauri_plugin_dialog::init())
        .plugin(tauri_plugin_clipboard_manager::init())
        .plugin(
            tauri_plugin_sql::Builder::default()
                .add_migrations("sqlite:test.db", migrations)
                .build(),
        )
        .plugin(tauri_plugin_opener::init())
        .invoke_handler(tauri::generate_handler![create_pdf])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

The migrations variable gets used in

.plugin(
            tauri_plugin_sql::Builder::default()
                .add_migrations("sqlite:test.db", migrations)
                .build(),
        )
velvet robin
#

put everything inside setup, then init the sql plugin using app.plugin

near ibex
#

I had tried that, but I get:

no method named plugin found for mutable reference &mut tauri::App in the current scope

velvet robin
#

the method is on the AppHandle.
try app.handle().plugin()

check the link for more details