mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-05 10:13:00 +02:00
feat(cli): expose a function to kill dev child
This commit is contained in:
1
tooling/cli/node/index.d.ts
vendored
1
tooling/cli/node/index.d.ts
vendored
@@ -4,4 +4,5 @@
|
||||
/* auto-generated by NAPI-RS */
|
||||
|
||||
export function run(args: Array<string>, binName: string | undefined | null, callback: (...args: any[]) => any): void
|
||||
export function killDevApp(callback: (...args: any[]) => any): void
|
||||
export function logError(error: string): void
|
||||
|
||||
@@ -252,7 +252,8 @@ if (!nativeBinding) {
|
||||
throw new Error(`Failed to load native binding`)
|
||||
}
|
||||
|
||||
const { run, logError } = nativeBinding
|
||||
const { run, killDevApp, logError } = nativeBinding
|
||||
|
||||
module.exports.run = run
|
||||
module.exports.killDevApp = killDevApp
|
||||
module.exports.logError = logError
|
||||
|
||||
1
tooling/cli/node/main.d.ts
vendored
1
tooling/cli/node/main.d.ts
vendored
@@ -6,3 +6,4 @@
|
||||
/* eslint-disable */
|
||||
|
||||
export function run(args: Array<string>, binName: string | undefined | null): Promise<void>
|
||||
export function killDevApp(): Promise<void>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
const { run, logError } = require('./index')
|
||||
const { run, killDevApp, logError } = require('./index')
|
||||
|
||||
module.exports.run = (args, binName) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -16,4 +16,16 @@ module.exports.run = (args, binName) => {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.killDevApp = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
killDevApp(res => {
|
||||
if (res instanceof Error) {
|
||||
reject(res)
|
||||
} else {
|
||||
resolve(res)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.logError = logError
|
||||
|
||||
@@ -25,6 +25,23 @@ pub fn run(args: Vec<String>, bin_name: Option<String>, callback: JsFunction) ->
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[napi_derive::napi]
|
||||
pub fn kill_dev_app(callback: JsFunction) -> Result<()> {
|
||||
let function: ThreadsafeFunction<bool, ErrorStrategy::CalleeHandled> = callback
|
||||
.create_threadsafe_function(0, |ctx| ctx.env.get_boolean(ctx.value).map(|v| vec![v]))?;
|
||||
|
||||
// we need to run in a separate thread so Node.js (e.g. vue-cli-plugin-tauri) consumers
|
||||
// can do work while `tauri dev` is running.
|
||||
std::thread::spawn(move || match tauri_cli::kill_dev_app() {
|
||||
Ok(_) => function.call(Ok(true), ThreadsafeFunctionCallMode::Blocking),
|
||||
Err(e) => function.call(
|
||||
Err(Error::new(Status::GenericFailure, format!("{:#}", e))),
|
||||
ThreadsafeFunctionCallMode::Blocking,
|
||||
),
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[napi_derive::napi]
|
||||
pub fn log_error(error: String) {
|
||||
log::error!("{}", error);
|
||||
|
||||
Reference in New Issue
Block a user