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

[Windows] AppBuilder Setup function never called after updating to Tauri v0.8 #879

Closed
simon-wh opened this issue Jul 21, 2020 · 6 comments
Closed

Comments

@simon-wh
Copy link

Describe the bug
After updating to latest Tauri when running on Windows the Setup function is never called. I do not experience it on Linux, potentially indicating the issue being platform-specific.

When upgrading to the new version I removed the edge entry in my tauri.conf.json, renamed whitelist to allowlist and changed my handle calls to as_mut

I'm not able to get much debugging information from it, boiling it down I've got a single println! as the first line of the setup function which is never outputted.

Platform and Versions (please complete the following information):
[tauri]: running info

Operating System - Windows_NT(10.0.18362) - win32/x64
Microsoft Edge - 44.18362.1.0_neutral__8wekyb3d8bbwe

Node.js environment
Node.js - 10.19.0
tauri.js - 0.10.0

Rust environment
rustc - 1.46.0-nightly
cargo - 1.46.0-nightly
tauri-bundler - 0.9.0

Global packages
NPM - 6.13.4
yarn - 1.22.0

App directory structure
/.git
/build
/node_modules
/public
/src
/src-tauri
/wooting-analog-midi

App
tauri.rs - 0.8.0
mode - embedded-server
build-type - bundle
CSP - default-src blob: data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'
distDir - ../build
devPath - http://localhost:3000

@chippers
Copy link
Member

chippers commented Jul 21, 2020

looks like {cmd: "__initialized"} is never sent to the handler. sending that cmd changed from 0.7.5 => 0.8.0 from using Commands::Init in endpoints.rs to WebviewBuilder::init with some javascript injected. Seems like the javascript inside the init in the builder is not running when under windows. Seems to work fine under linux. I'm not familiar with webview enough to look into it more.

Workaround: run this during your javascript application startup

if (window.__TAURI_INVOKE_HANDLER__) {
  window.__TAURI_INVOKE_HANDLER__({cmd: "__initialized"});
} else {
  console.error("unable to call window.__TAURI_INVOKE_HANDLER__ to initialize tauri");
}

@lucasfernog
Copy link
Member

Seems like the webview's init hook isn't working on the first app load. If I go to the devtools console and run window.location.reload(), everything works fine.

It's weird because if I try to change the webview URL to https://google.com, the init hook works fine.

@simon-wh
Copy link
Author

simon-wh commented Jul 22, 2020

Thanks for the workaround @chippers, Although it doesn't fully resolve things in my case. If I run window.location.reload() like you suggest @lucasfernog everything behaves as I would expect. However, using the workaround, setup is called, but my event emitters from Rust -> JS appear to be broken. I get these errors:
image
Where the eval code it references being the js code for executing the Rust -> JS event

I'm guessing with the workaround the JS side of Tauri isn't being fully initialized

@chippers
Copy link
Member

chippers commented Jul 22, 2020

@simon-wh Yeah, looking at the code that isn't being run, it includes event initialization and plugin initialization. Here's a bit more involved workaround that works using the full reload.

JS code:

if (window.__TAURI_INVOKE_HANDLER__) {
  window.__TAURI_INVOKE_HANDLER__({cmd: "__workaround"});
} else {
  console.error("unable to call window.__TAURI_INVOKE_HANDLER__ to initialize tauri");
}

Rust code:

let mut workaround = true;
AppBuilder::new()
    .setup(setup)
    .invoke_handler(move |w, arg| {
        if workaround && arg == r#"{"cmd":"__workaround"}"# {
            workaround = false;
            w.eval("window.location.reload()");
        }
        Ok(())
    })
    .build()
    .run();

If you already have an invoke handler, all you need to add is the workaround boolean + the check to reload

@lucasfernog
Copy link
Member

This is a binding issue and we're fixing it. Gonna be available on the next release.

@lucasfernog
Copy link
Member

Closed by webview/webview_rust#35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants