specta-rs / tauri-specta

Completely typesafe Tauri commands
MIT License
394 stars 41 forks source link

Crash when maximizing window in command #75

Closed franciscoBSalgueiro closed 7 months ago

franciscoBSalgueiro commented 9 months ago

I've tried to make a minimal example from the issue I was facing. The main problem is with the function close_splashscreen. The code below makes the app freeze and crash on startup.

Changing fn close_splashscreen to async close_splashscreen fixes it. Not using specta, and instead just calling normal tauri commands also fixes it, so I believe this is a tauri-specta specific issue.

(tauri.conf.json)
...
    "windows": [
      {
        "title": "test-maximize",
        "maximized": false
      }
    ],
...
import { useEffect } from "react";
import { commands } from "./bindings";

function App() {
  useEffect(() => {
    commands.closeSplashscreen();
  }, []);

  return <h1>Test</h1>;
}

export default App;
use tauri::{Manager, Window};

#[tauri::command]
#[specta::specta]
fn close_splashscreen(window: Window) -> Result<(), String> {
    window
        .get_window("main")
        .expect("no window labeled 'main' found")
        .maximize()
        .unwrap();
    Ok(())
}

fn main() {
    let specta_builder = {
        let specta_builder = tauri_specta::ts::builder()
            .commands(tauri_specta::collect_commands!(close_splashscreen,));

        #[cfg(debug_assertions)]
        let specta_builder = specta_builder.path("../src/bindings.ts");
        specta_builder.into_plugin()
    };

    tauri::Builder::default()
        .plugin(specta_builder)
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Versions

tauri = { version = "1.5", features = ["shell-open"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri-specta = { version = "=2.0.0-rc.4", features = ["javascript", "typescript"] }
specta = "=2.0.0-rc.7"
Brendonovich commented 9 months ago

That's odd, will have to look into it. In the meantime can you take the code that's not working and put it into a dedicated repo we can run?

franciscoBSalgueiro commented 9 months ago

https://github.com/franciscoBSalgueiro/tauri-specta-maximize

There's two different branches with the fixes for not using async and not using specta.

oscartbeaumont commented 7 months ago

What OS are you on?

I'm on macOS and i'm unable to reproduce the crash with the main branch of your repo.

oscartbeaumont commented 7 months ago

It might also be worth upgrading to the main branch of Tauri Specta which uses Tauri =2.0.0-beta.16. You should be able to follow the installation guide here to workaround which version of everything you require.

franciscoBSalgueiro commented 7 months ago

This was tested on Windows.

I tried the new v2 and it works without crashing now! (That guide isn't updated though, into_plugin doesn't exist. I had to look at the new examples to get it to work.)

oscartbeaumont commented 7 months ago

That's great and thanks for letting me know the examples are broken, will fix them up now.