[docs] Splashscreen example missing key argument
lewisjr opened this issue · comments
I wanted to get my splashcreen and main app window as seperate windows running, and do a few custom checks and setups at the Rust level as well as only show the main window once the DOM has loaded. As per the v1 docs this is very possible. However, the example does not work out the box. The example on the docs is:
use tauri::Manager;
// Create the command:
// This command must be async so that it doesn't run on the main thread.
#[tauri::command]
async fn close_splashscreen() {
// Close splashscreen
window.get_window("splashscreen").expect("no window labeled 'splashscreen' found").close().unwrap()
// Show main window
window.get_window("main").expect("no window labeled 'main' found").show().unwrap();
}
This logic almost works but is missing the window
arg. Without it I got the following errors:
**Rust Analyser in VS Code**
cannot find value `window` in this scope
not found in this scope
**Terminal**
error[E0425]: cannot find value `window` in this scope
--> src\utils.rs:10:5
|
10 | window
| ^^^^^^ not found in this scope
error[E0425]: cannot find value `window` in this scope
--> src\utils.rs:16:5
|
16 | window
| ^^^^^^ not found in this scope
warning: unused import: `tauri::Manager`
--> src\utils.rs:1:5
|
1 | use tauri::Manager;
| ^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
For more information about this error, try `rustc --explain E0425`.
To find the solution, I had to do a couple of searches to find this issue on GitHub, which after poking around led me to this commit.
Long story short, the solution that worked for me after reading the commit was to add the window
arg:
use tauri::Manager;
/// Close the splash screen and open the main window
#[tauri::command]
pub fn init_main(window: tauri::Window) {
// Close splashscreen
window.get_window("splash").expect("no window labeled 'splash' found").close().unwrap();
// Show main app window
window.get_window("main").expect("no window labeled 'main' found").show().unwrap();
}
System Info
tauri version: 1.4
os: windows
windows version: 10.0.19045