napi-rs/examples/napi
Bo e47c13f177
fix(napi): check if the tokio runtime exists when registering the module
And recreate it if it does not exist.

In windows, electron renderer process will crash if:
1. Import some NAPI module that enable `tokio-rt` flag in renderer process.
2. Reload the page.
3. Call a function imported from that NAPI module.

Because the tokio runtime will be dropped when reloading the page, and won't create again, but currently we assume that the runtime must exist in tokio-based `within_runtime_if_available`.
This will cause some panic like this:

```
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', napi-rs\crates\napi\src\tokio_runtime.rs:72:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: Renderer process crashed: crashed, exitCode: -529697949
    at EventEmitter.<anonymous> (napi-rs\examples\napi\electron.js:33:9)
    at EventEmitter.emit (node:events:525:35)
```
2023-03-28 12:03:00 +08:00
..
__test__ fix(napi): big numbers losing precision on serde_json::Value (#1538) 2023-03-23 13:34:34 +08:00
electron-renderer fix(napi): check if the tokio runtime exists when registering the module 2023-03-28 12:03:00 +08:00
src fix(napi): big numbers losing precision on serde_json::Value (#1538) 2023-03-23 13:34:34 +08:00
tests test(napi-derive): add trybuild negative macro tests 2022-05-23 11:55:19 +08:00
.gitignore test(napi-derive): add trybuild negative macro tests 2022-05-23 11:55:19 +08:00
build.rs Introduce #[napi] procedural macro to automation development boilerplate (#696) 2021-09-23 01:29:09 +08:00
Cargo.toml fix(cli,napi-derive): re-export types from shared crate (#1531) 2023-03-21 18:12:52 +08:00
electron.js fix(napi): check if the tokio runtime exists when registering the module 2023-03-28 12:03:00 +08:00
index.d.ts fix(napi): big numbers losing precision on serde_json::Value (#1538) 2023-03-23 13:34:34 +08:00
package.json chore: upgrade npm dependencies (#1443) 2023-01-19 00:32:52 +08:00
tsconfig.json fix(napi): check if the tokio runtime exists when registering the module 2023-03-28 12:03:00 +08:00