Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Splashscreen example missing key argument #1572

Closed
lewisjr opened this issue Sep 27, 2023 · 0 comments
Closed

[docs] Splashscreen example missing key argument #1572

lewisjr opened this issue Sep 27, 2023 · 0 comments

Comments

@lewisjr
Copy link

lewisjr commented Sep 27, 2023

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

@amrbashir amrbashir transferred this issue from tauri-apps/tauri Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant