-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
b5cecbe
commit 3713066
Showing
16 changed files
with
567 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"tauri": minor | ||
"api": minor | ||
--- | ||
|
||
The shell process spawning API was rewritten and now includes stream access. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<script> | ||
import { Command } from "@tauri-apps/api/shell" | ||
const windows = navigator.userAgent.includes('Windows') | ||
let cmd = windows ? 'cmd' : 'sh' | ||
let args = windows ? ['/C'] : ['-c'] | ||
export let onMessage; | ||
let script = 'echo "hello world"' | ||
let stdin = '' | ||
let child | ||
function spawn() { | ||
child = null | ||
const command = new Command(cmd, [...args, script]) | ||
command.on('close', data => { | ||
onMessage(`command finished with code ${data.code} and signal ${data.signal}`) | ||
child = null | ||
}) | ||
command.on('error', error => onMessage(`command error: "${error}"`)) | ||
command.stdout.on('data', line => onMessage(`command stdout: "${line}"`)) | ||
command.stderr.on('data', line => onMessage(`command stderr: "${line}"`)) | ||
command.spawn() | ||
.then(c => { | ||
child = c | ||
}) | ||
.catch(onMessage) | ||
} | ||
function kill() { | ||
child.kill().then(() => onMessage('killed child process')).error(onMessage) | ||
} | ||
function writeToStdin() { | ||
child.write(stdin).catch(onMessage) | ||
} | ||
</script> | ||
|
||
<div> | ||
<div> | ||
<input bind:value={script}> | ||
<button class="button" on:click={spawn}>Run</button> | ||
<button class="button" on:click={kill}>Kill</button> | ||
{#if child} | ||
<input placeholder="write to stdin" bind:value={stdin}> | ||
<button class="button" on:click={writeToStdin}>Write</button> | ||
{/if} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.