@tauri-apps/api
Advanced tools
Comparing version 1.5.6 to 1.6.0
# Changelog | ||
## \[1.6.0] | ||
### Enhancements | ||
- [`44e3335da`](https://www.github.com/tauri-apps/tauri/commit/44e3335da8c1a811a2ebe72f2036dfad2381da24) ([#9796](https://www.github.com/tauri-apps/tauri/pull/9796)) Enhance the speed of The JS `Command.execute` API from `shell` module. | ||
### Bug Fixes | ||
- [`44e3335da`](https://www.github.com/tauri-apps/tauri/commit/44e3335da8c1a811a2ebe72f2036dfad2381da24) ([#9796](https://www.github.com/tauri-apps/tauri/pull/9796)) Fix The JS `Command.execute` API from `shell` module including extra new lines. | ||
## \[1.5.6] | ||
@@ -4,0 +14,0 @@ |
{ | ||
"name": "@tauri-apps/api", | ||
"version": "1.5.6", | ||
"version": "1.6.0", | ||
"description": "Tauri API definitions", | ||
@@ -5,0 +5,0 @@ "funding": { |
78
shell.js
@@ -82,27 +82,2 @@ import { invokeTauriCommand } from './helpers/tauri.js'; | ||
/** | ||
* Spawns a process. | ||
* | ||
* @ignore | ||
* @param program The name of the scoped command. | ||
* @param onEvent Event handler. | ||
* @param args Program arguments. | ||
* @param options Configuration for the process spawn. | ||
* @returns A promise resolving to the process id. | ||
*/ | ||
async function execute(onEvent, program, args = [], options) { | ||
if (typeof args === 'object') { | ||
Object.freeze(args); | ||
} | ||
return invokeTauriCommand({ | ||
__tauriModule: 'Shell', | ||
message: { | ||
cmd: 'execute', | ||
program, | ||
args, | ||
options, | ||
onEventFn: transformCallback(onEvent) | ||
} | ||
}); | ||
} | ||
/** | ||
* @since 1.0.0 | ||
@@ -378,3 +353,9 @@ */ | ||
async spawn() { | ||
return execute((event) => { | ||
const program = this.program; | ||
const args = this.args; | ||
const options = this.options; | ||
if (typeof args === 'object') { | ||
Object.freeze(args); | ||
} | ||
const onEvent = (event) => { | ||
switch (event.event) { | ||
@@ -394,3 +375,13 @@ case 'Error': | ||
} | ||
}, this.program, this.args, this.options).then((pid) => new Child(pid)); | ||
}; | ||
return invokeTauriCommand({ | ||
__tauriModule: 'Shell', | ||
message: { | ||
cmd: 'execute', | ||
program, | ||
args, | ||
options, | ||
onEventFn: transformCallback(onEvent) | ||
} | ||
}).then((pid) => new Child(pid)); | ||
} | ||
@@ -412,21 +403,16 @@ /** | ||
async execute() { | ||
return new Promise((resolve, reject) => { | ||
this.on('error', reject); | ||
const stdout = []; | ||
const stderr = []; | ||
this.stdout.on('data', (line) => { | ||
stdout.push(line); | ||
}); | ||
this.stderr.on('data', (line) => { | ||
stderr.push(line); | ||
}); | ||
this.on('close', (payload) => { | ||
resolve({ | ||
code: payload.code, | ||
signal: payload.signal, | ||
stdout: stdout.join('\n'), | ||
stderr: stderr.join('\n') | ||
}); | ||
}); | ||
this.spawn().catch(reject); | ||
const program = this.program; | ||
const args = this.args; | ||
const options = this.options; | ||
if (typeof args === 'object') { | ||
Object.freeze(args); | ||
} | ||
return invokeTauriCommand({ | ||
__tauriModule: 'Shell', | ||
message: { | ||
cmd: 'executeAndReturn', | ||
program, | ||
args, | ||
options | ||
} | ||
}); | ||
@@ -433,0 +419,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
550066
15471