mirror of
https://github.com/tauri-apps/tauri-plugin-shell.git
synced 2026-01-31 00:45:19 +01:00
chore: adjust prettier config, .gitignore and use taplo to format toml files (#1728)
* chore: adjust prettier config, .gitignore and use taplo to format toml files This brings the plugins-workspace repository to the same code style of the main tauri repo * format toml * ignore examples gen dir * add .vscode/extensions.json * remove packageManager field * fmt * fix audit * taplo ignore permissions autogenerated files * remove create dummy dist * fix prettier workflow * install fmt in prettier workflow --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app> Committed via a GitHub action: https://github.com/tauri-apps/plugins-workspace/actions/runs/10701104849 Co-authored-by: lucasfernog <lucasfernog@users.noreply.github.com>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/.tauri
|
|
||||||
@@ -10,11 +10,11 @@ repository = { workspace = true }
|
|||||||
links = "tauri-plugin-shell"
|
links = "tauri-plugin-shell"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
rustc-args = [ "--cfg", "docsrs" ]
|
rustc-args = ["--cfg", "docsrs"]
|
||||||
rustdoc-args = [ "--cfg", "docsrs" ]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri-plugin = { workspace = true, features = [ "build" ] }
|
tauri-plugin = { workspace = true, features = ["build"] }
|
||||||
schemars = { workspace = true }
|
schemars = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
|
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ fn main() {
|
|||||||
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import { Command } from "@tauri-apps/plugin-shell";
|
import { Command } from '@tauri-apps/plugin-shell'
|
||||||
Command.create("git", ["commit", "-m", "the commit message"]);
|
Command.create('git', ['commit', '-m', 'the commit message'])
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|||||||
@@ -20,4 +20,4 @@ We prefer to receive reports in English.
|
|||||||
|
|
||||||
Please disclose a vulnerability or security relevant issue here: [https://github.com/tauri-apps/plugins-workspace/security/advisories/new](https://github.com/tauri-apps/plugins-workspace/security/advisories/new).
|
Please disclose a vulnerability or security relevant issue here: [https://github.com/tauri-apps/plugins-workspace/security/advisories/new](https://github.com/tauri-apps/plugins-workspace/security/advisories/new).
|
||||||
|
|
||||||
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
|
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
|
||||||
|
|||||||
@@ -252,9 +252,9 @@ class Child {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
async write(data) {
|
async write(data) {
|
||||||
await core.invoke("plugin:shell|stdin_write", {
|
await core.invoke('plugin:shell|stdin_write', {
|
||||||
pid: this.pid,
|
pid: this.pid,
|
||||||
buffer: data,
|
buffer: data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -265,9 +265,9 @@ class Child {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
async kill() {
|
async kill() {
|
||||||
await core.invoke("plugin:shell|kill", {
|
await core.invoke('plugin:shell|kill', {
|
||||||
cmd: "killChild",
|
cmd: 'killChild',
|
||||||
pid: this.pid,
|
pid: this.pid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -309,7 +309,7 @@ class Command extends EventEmitter {
|
|||||||
/** Event emitter for the `stderr`. Emits the `data` event. */
|
/** Event emitter for the `stderr`. Emits the `data` event. */
|
||||||
this.stderr = new EventEmitter();
|
this.stderr = new EventEmitter();
|
||||||
this.program = program;
|
this.program = program;
|
||||||
this.args = typeof args === "string" ? [args] : args;
|
this.args = typeof args === 'string' ? [args] : args;
|
||||||
this.options = options ?? {};
|
this.options = options ?? {};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -355,31 +355,31 @@ class Command extends EventEmitter {
|
|||||||
const program = this.program;
|
const program = this.program;
|
||||||
const args = this.args;
|
const args = this.args;
|
||||||
const options = this.options;
|
const options = this.options;
|
||||||
if (typeof args === "object") {
|
if (typeof args === 'object') {
|
||||||
Object.freeze(args);
|
Object.freeze(args);
|
||||||
}
|
}
|
||||||
const onEvent = new core.Channel();
|
const onEvent = new core.Channel();
|
||||||
onEvent.onmessage = (event) => {
|
onEvent.onmessage = (event) => {
|
||||||
switch (event.event) {
|
switch (event.event) {
|
||||||
case "Error":
|
case 'Error':
|
||||||
this.emit("error", event.payload);
|
this.emit('error', event.payload);
|
||||||
break;
|
break;
|
||||||
case "Terminated":
|
case 'Terminated':
|
||||||
this.emit("close", event.payload);
|
this.emit('close', event.payload);
|
||||||
break;
|
break;
|
||||||
case "Stdout":
|
case 'Stdout':
|
||||||
this.stdout.emit("data", event.payload);
|
this.stdout.emit('data', event.payload);
|
||||||
break;
|
break;
|
||||||
case "Stderr":
|
case 'Stderr':
|
||||||
this.stderr.emit("data", event.payload);
|
this.stderr.emit('data', event.payload);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return await core.invoke("plugin:shell|spawn", {
|
return await core.invoke('plugin:shell|spawn', {
|
||||||
program,
|
program,
|
||||||
args,
|
args,
|
||||||
options,
|
options,
|
||||||
onEvent,
|
onEvent
|
||||||
}).then((pid) => new Child(pid));
|
}).then((pid) => new Child(pid));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -402,13 +402,13 @@ class Command extends EventEmitter {
|
|||||||
const program = this.program;
|
const program = this.program;
|
||||||
const args = this.args;
|
const args = this.args;
|
||||||
const options = this.options;
|
const options = this.options;
|
||||||
if (typeof args === "object") {
|
if (typeof args === 'object') {
|
||||||
Object.freeze(args);
|
Object.freeze(args);
|
||||||
}
|
}
|
||||||
return await core.invoke("plugin:shell|execute", {
|
return await core.invoke('plugin:shell|execute', {
|
||||||
program,
|
program,
|
||||||
args,
|
args,
|
||||||
options,
|
options
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -439,9 +439,9 @@ class Command extends EventEmitter {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
async function open(path, openWith) {
|
async function open(path, openWith) {
|
||||||
await core.invoke("plugin:shell|open", {
|
await core.invoke('plugin:shell|open', {
|
||||||
path,
|
path,
|
||||||
with: openWith,
|
with: openWith
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
dist-js/index.d.ts
vendored
6
dist-js/index.d.ts
vendored
@@ -201,12 +201,12 @@ declare class Command<O extends IOPayload> extends EventEmitter<CommandEvents> {
|
|||||||
private constructor();
|
private constructor();
|
||||||
static create(program: string, args?: string | string[]): Command<string>;
|
static create(program: string, args?: string | string[]): Command<string>;
|
||||||
static create(program: string, args?: string | string[], options?: SpawnOptions & {
|
static create(program: string, args?: string | string[], options?: SpawnOptions & {
|
||||||
encoding: "raw";
|
encoding: 'raw';
|
||||||
}): Command<Uint8Array>;
|
}): Command<Uint8Array>;
|
||||||
static create(program: string, args?: string | string[], options?: SpawnOptions): Command<string>;
|
static create(program: string, args?: string | string[], options?: SpawnOptions): Command<string>;
|
||||||
static sidecar(program: string, args?: string | string[]): Command<string>;
|
static sidecar(program: string, args?: string | string[]): Command<string>;
|
||||||
static sidecar(program: string, args?: string | string[], options?: SpawnOptions & {
|
static sidecar(program: string, args?: string | string[], options?: SpawnOptions & {
|
||||||
encoding: "raw";
|
encoding: 'raw';
|
||||||
}): Command<Uint8Array>;
|
}): Command<Uint8Array>;
|
||||||
static sidecar(program: string, args?: string | string[], options?: SpawnOptions): Command<string>;
|
static sidecar(program: string, args?: string | string[], options?: SpawnOptions): Command<string>;
|
||||||
/**
|
/**
|
||||||
@@ -274,4 +274,4 @@ type IOPayload = string | Uint8Array;
|
|||||||
*/
|
*/
|
||||||
declare function open(path: string, openWith?: string): Promise<void>;
|
declare function open(path: string, openWith?: string): Promise<void>;
|
||||||
export { Command, Child, EventEmitter, open };
|
export { Command, Child, EventEmitter, open };
|
||||||
export type { IOPayload, CommandEvents, TerminatedPayload, OutputEvents, ChildProcess, SpawnOptions, };
|
export type { IOPayload, CommandEvents, TerminatedPayload, OutputEvents, ChildProcess, SpawnOptions };
|
||||||
|
|||||||
@@ -250,9 +250,9 @@ class Child {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
async write(data) {
|
async write(data) {
|
||||||
await invoke("plugin:shell|stdin_write", {
|
await invoke('plugin:shell|stdin_write', {
|
||||||
pid: this.pid,
|
pid: this.pid,
|
||||||
buffer: data,
|
buffer: data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -263,9 +263,9 @@ class Child {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
async kill() {
|
async kill() {
|
||||||
await invoke("plugin:shell|kill", {
|
await invoke('plugin:shell|kill', {
|
||||||
cmd: "killChild",
|
cmd: 'killChild',
|
||||||
pid: this.pid,
|
pid: this.pid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -307,7 +307,7 @@ class Command extends EventEmitter {
|
|||||||
/** Event emitter for the `stderr`. Emits the `data` event. */
|
/** Event emitter for the `stderr`. Emits the `data` event. */
|
||||||
this.stderr = new EventEmitter();
|
this.stderr = new EventEmitter();
|
||||||
this.program = program;
|
this.program = program;
|
||||||
this.args = typeof args === "string" ? [args] : args;
|
this.args = typeof args === 'string' ? [args] : args;
|
||||||
this.options = options ?? {};
|
this.options = options ?? {};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -353,31 +353,31 @@ class Command extends EventEmitter {
|
|||||||
const program = this.program;
|
const program = this.program;
|
||||||
const args = this.args;
|
const args = this.args;
|
||||||
const options = this.options;
|
const options = this.options;
|
||||||
if (typeof args === "object") {
|
if (typeof args === 'object') {
|
||||||
Object.freeze(args);
|
Object.freeze(args);
|
||||||
}
|
}
|
||||||
const onEvent = new Channel();
|
const onEvent = new Channel();
|
||||||
onEvent.onmessage = (event) => {
|
onEvent.onmessage = (event) => {
|
||||||
switch (event.event) {
|
switch (event.event) {
|
||||||
case "Error":
|
case 'Error':
|
||||||
this.emit("error", event.payload);
|
this.emit('error', event.payload);
|
||||||
break;
|
break;
|
||||||
case "Terminated":
|
case 'Terminated':
|
||||||
this.emit("close", event.payload);
|
this.emit('close', event.payload);
|
||||||
break;
|
break;
|
||||||
case "Stdout":
|
case 'Stdout':
|
||||||
this.stdout.emit("data", event.payload);
|
this.stdout.emit('data', event.payload);
|
||||||
break;
|
break;
|
||||||
case "Stderr":
|
case 'Stderr':
|
||||||
this.stderr.emit("data", event.payload);
|
this.stderr.emit('data', event.payload);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return await invoke("plugin:shell|spawn", {
|
return await invoke('plugin:shell|spawn', {
|
||||||
program,
|
program,
|
||||||
args,
|
args,
|
||||||
options,
|
options,
|
||||||
onEvent,
|
onEvent
|
||||||
}).then((pid) => new Child(pid));
|
}).then((pid) => new Child(pid));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -400,13 +400,13 @@ class Command extends EventEmitter {
|
|||||||
const program = this.program;
|
const program = this.program;
|
||||||
const args = this.args;
|
const args = this.args;
|
||||||
const options = this.options;
|
const options = this.options;
|
||||||
if (typeof args === "object") {
|
if (typeof args === 'object') {
|
||||||
Object.freeze(args);
|
Object.freeze(args);
|
||||||
}
|
}
|
||||||
return await invoke("plugin:shell|execute", {
|
return await invoke('plugin:shell|execute', {
|
||||||
program,
|
program,
|
||||||
args,
|
args,
|
||||||
options,
|
options
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -437,9 +437,9 @@ class Command extends EventEmitter {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
async function open(path, openWith) {
|
async function open(path, openWith) {
|
||||||
await invoke("plugin:shell|open", {
|
await invoke('plugin:shell|open', {
|
||||||
path,
|
path,
|
||||||
with: openWith,
|
with: openWith
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,27 +63,27 @@
|
|||||||
* @module
|
* @module
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { invoke, Channel } from "@tauri-apps/api/core";
|
import { invoke, Channel } from '@tauri-apps/api/core'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
interface SpawnOptions {
|
interface SpawnOptions {
|
||||||
/** Current working directory. */
|
/** Current working directory. */
|
||||||
cwd?: string;
|
cwd?: string
|
||||||
/** Environment variables. set to `null` to clear the process env. */
|
/** Environment variables. set to `null` to clear the process env. */
|
||||||
env?: Record<string, string>;
|
env?: Record<string, string>
|
||||||
/**
|
/**
|
||||||
* Character encoding for stdout/stderr
|
* Character encoding for stdout/stderr
|
||||||
*
|
*
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* */
|
* */
|
||||||
encoding?: string;
|
encoding?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @ignore */
|
/** @ignore */
|
||||||
interface InternalSpawnOptions extends SpawnOptions {
|
interface InternalSpawnOptions extends SpawnOptions {
|
||||||
sidecar?: boolean;
|
sidecar?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,13 +91,13 @@ interface InternalSpawnOptions extends SpawnOptions {
|
|||||||
*/
|
*/
|
||||||
interface ChildProcess<O extends IOPayload> {
|
interface ChildProcess<O extends IOPayload> {
|
||||||
/** Exit code of the process. `null` if the process was terminated by a signal on Unix. */
|
/** Exit code of the process. `null` if the process was terminated by a signal on Unix. */
|
||||||
code: number | null;
|
code: number | null
|
||||||
/** If the process was terminated by a signal, represents that signal. */
|
/** If the process was terminated by a signal, represents that signal. */
|
||||||
signal: number | null;
|
signal: number | null
|
||||||
/** The data that the process wrote to `stdout`. */
|
/** The data that the process wrote to `stdout`. */
|
||||||
stdout: O;
|
stdout: O
|
||||||
/** The data that the process wrote to `stderr`. */
|
/** The data that the process wrote to `stderr`. */
|
||||||
stderr: O;
|
stderr: O
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,7 +108,7 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
/** @ignore */
|
/** @ignore */
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
|
||||||
private eventListeners: Record<keyof E, Array<(arg: any) => void>> =
|
private eventListeners: Record<keyof E, Array<(arg: any) => void>> =
|
||||||
Object.create(null);
|
Object.create(null)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alias for `emitter.on(eventName, listener)`.
|
* Alias for `emitter.on(eventName, listener)`.
|
||||||
@@ -117,9 +117,9 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
*/
|
*/
|
||||||
addListener<N extends keyof E>(
|
addListener<N extends keyof E>(
|
||||||
eventName: N,
|
eventName: N,
|
||||||
listener: (arg: E[typeof eventName]) => void,
|
listener: (arg: E[typeof eventName]) => void
|
||||||
): this {
|
): this {
|
||||||
return this.on(eventName, listener);
|
return this.on(eventName, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,9 +129,9 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
*/
|
*/
|
||||||
removeListener<N extends keyof E>(
|
removeListener<N extends keyof E>(
|
||||||
eventName: N,
|
eventName: N,
|
||||||
listener: (arg: E[typeof eventName]) => void,
|
listener: (arg: E[typeof eventName]) => void
|
||||||
): this {
|
): this {
|
||||||
return this.off(eventName, listener);
|
return this.off(eventName, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,16 +146,16 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
*/
|
*/
|
||||||
on<N extends keyof E>(
|
on<N extends keyof E>(
|
||||||
eventName: N,
|
eventName: N,
|
||||||
listener: (arg: E[typeof eventName]) => void,
|
listener: (arg: E[typeof eventName]) => void
|
||||||
): this {
|
): this {
|
||||||
if (eventName in this.eventListeners) {
|
if (eventName in this.eventListeners) {
|
||||||
// eslint-disable-next-line security/detect-object-injection
|
// eslint-disable-next-line security/detect-object-injection
|
||||||
this.eventListeners[eventName].push(listener);
|
this.eventListeners[eventName].push(listener)
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line security/detect-object-injection
|
// eslint-disable-next-line security/detect-object-injection
|
||||||
this.eventListeners[eventName] = [listener];
|
this.eventListeners[eventName] = [listener]
|
||||||
}
|
}
|
||||||
return this;
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -168,13 +168,13 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
*/
|
*/
|
||||||
once<N extends keyof E>(
|
once<N extends keyof E>(
|
||||||
eventName: N,
|
eventName: N,
|
||||||
listener: (arg: E[typeof eventName]) => void,
|
listener: (arg: E[typeof eventName]) => void
|
||||||
): this {
|
): this {
|
||||||
const wrapper = (arg: E[typeof eventName]): void => {
|
const wrapper = (arg: E[typeof eventName]): void => {
|
||||||
this.removeListener(eventName, wrapper);
|
this.removeListener(eventName, wrapper)
|
||||||
listener(arg);
|
listener(arg)
|
||||||
};
|
}
|
||||||
return this.addListener(eventName, wrapper);
|
return this.addListener(eventName, wrapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -185,15 +185,15 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
*/
|
*/
|
||||||
off<N extends keyof E>(
|
off<N extends keyof E>(
|
||||||
eventName: N,
|
eventName: N,
|
||||||
listener: (arg: E[typeof eventName]) => void,
|
listener: (arg: E[typeof eventName]) => void
|
||||||
): this {
|
): this {
|
||||||
if (eventName in this.eventListeners) {
|
if (eventName in this.eventListeners) {
|
||||||
// eslint-disable-next-line security/detect-object-injection
|
// eslint-disable-next-line security/detect-object-injection
|
||||||
this.eventListeners[eventName] = this.eventListeners[eventName].filter(
|
this.eventListeners[eventName] = this.eventListeners[eventName].filter(
|
||||||
(l) => l !== listener,
|
(l) => l !== listener
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
return this;
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,12 +206,12 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
removeAllListeners<N extends keyof E>(event?: N): this {
|
removeAllListeners<N extends keyof E>(event?: N): this {
|
||||||
if (event) {
|
if (event) {
|
||||||
// eslint-disable-next-line security/detect-object-injection
|
// eslint-disable-next-line security/detect-object-injection
|
||||||
delete this.eventListeners[event];
|
delete this.eventListeners[event]
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
this.eventListeners = Object.create(null);
|
this.eventListeners = Object.create(null)
|
||||||
}
|
}
|
||||||
return this;
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -226,11 +226,11 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
emit<N extends keyof E>(eventName: N, arg: E[typeof eventName]): boolean {
|
emit<N extends keyof E>(eventName: N, arg: E[typeof eventName]): boolean {
|
||||||
if (eventName in this.eventListeners) {
|
if (eventName in this.eventListeners) {
|
||||||
// eslint-disable-next-line security/detect-object-injection
|
// eslint-disable-next-line security/detect-object-injection
|
||||||
const listeners = this.eventListeners[eventName];
|
const listeners = this.eventListeners[eventName]
|
||||||
for (const listener of listeners) listener(arg);
|
for (const listener of listeners) listener(arg)
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -241,8 +241,8 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
listenerCount<N extends keyof E>(eventName: N): number {
|
listenerCount<N extends keyof E>(eventName: N): number {
|
||||||
if (eventName in this.eventListeners)
|
if (eventName in this.eventListeners)
|
||||||
// eslint-disable-next-line security/detect-object-injection
|
// eslint-disable-next-line security/detect-object-injection
|
||||||
return this.eventListeners[eventName].length;
|
return this.eventListeners[eventName].length
|
||||||
return 0;
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -257,16 +257,16 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
*/
|
*/
|
||||||
prependListener<N extends keyof E>(
|
prependListener<N extends keyof E>(
|
||||||
eventName: N,
|
eventName: N,
|
||||||
listener: (arg: E[typeof eventName]) => void,
|
listener: (arg: E[typeof eventName]) => void
|
||||||
): this {
|
): this {
|
||||||
if (eventName in this.eventListeners) {
|
if (eventName in this.eventListeners) {
|
||||||
// eslint-disable-next-line security/detect-object-injection
|
// eslint-disable-next-line security/detect-object-injection
|
||||||
this.eventListeners[eventName].unshift(listener);
|
this.eventListeners[eventName].unshift(listener)
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line security/detect-object-injection
|
// eslint-disable-next-line security/detect-object-injection
|
||||||
this.eventListeners[eventName] = [listener];
|
this.eventListeners[eventName] = [listener]
|
||||||
}
|
}
|
||||||
return this;
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -279,15 +279,15 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
*/
|
*/
|
||||||
prependOnceListener<N extends keyof E>(
|
prependOnceListener<N extends keyof E>(
|
||||||
eventName: N,
|
eventName: N,
|
||||||
listener: (arg: E[typeof eventName]) => void,
|
listener: (arg: E[typeof eventName]) => void
|
||||||
): this {
|
): this {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const wrapper = (arg: any): void => {
|
const wrapper = (arg: any): void => {
|
||||||
this.removeListener(eventName, wrapper);
|
this.removeListener(eventName, wrapper)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||||
listener(arg);
|
listener(arg)
|
||||||
};
|
}
|
||||||
return this.prependListener(eventName, wrapper);
|
return this.prependListener(eventName, wrapper)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,10 +296,10 @@ class EventEmitter<E extends Record<string, any>> {
|
|||||||
*/
|
*/
|
||||||
class Child {
|
class Child {
|
||||||
/** The child process `pid`. */
|
/** The child process `pid`. */
|
||||||
pid: number;
|
pid: number
|
||||||
|
|
||||||
constructor(pid: number) {
|
constructor(pid: number) {
|
||||||
this.pid = pid;
|
this.pid = pid
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -320,10 +320,10 @@ class Child {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
async write(data: IOPayload | number[]): Promise<void> {
|
async write(data: IOPayload | number[]): Promise<void> {
|
||||||
await invoke("plugin:shell|stdin_write", {
|
await invoke('plugin:shell|stdin_write', {
|
||||||
pid: this.pid,
|
pid: this.pid,
|
||||||
buffer: data,
|
buffer: data
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -334,20 +334,20 @@ class Child {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
async kill(): Promise<void> {
|
async kill(): Promise<void> {
|
||||||
await invoke("plugin:shell|kill", {
|
await invoke('plugin:shell|kill', {
|
||||||
cmd: "killChild",
|
cmd: 'killChild',
|
||||||
pid: this.pid,
|
pid: this.pid
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CommandEvents {
|
interface CommandEvents {
|
||||||
close: TerminatedPayload;
|
close: TerminatedPayload
|
||||||
error: string;
|
error: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OutputEvents<O extends IOPayload> {
|
interface OutputEvents<O extends IOPayload> {
|
||||||
data: O;
|
data: O
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -373,15 +373,15 @@ interface OutputEvents<O extends IOPayload> {
|
|||||||
*/
|
*/
|
||||||
class Command<O extends IOPayload> extends EventEmitter<CommandEvents> {
|
class Command<O extends IOPayload> extends EventEmitter<CommandEvents> {
|
||||||
/** @ignore Program to execute. */
|
/** @ignore Program to execute. */
|
||||||
private readonly program: string;
|
private readonly program: string
|
||||||
/** @ignore Program arguments */
|
/** @ignore Program arguments */
|
||||||
private readonly args: string[];
|
private readonly args: string[]
|
||||||
/** @ignore Spawn options. */
|
/** @ignore Spawn options. */
|
||||||
private readonly options: InternalSpawnOptions;
|
private readonly options: InternalSpawnOptions
|
||||||
/** Event emitter for the `stdout`. Emits the `data` event. */
|
/** Event emitter for the `stdout`. Emits the `data` event. */
|
||||||
readonly stdout = new EventEmitter<OutputEvents<O>>();
|
readonly stdout = new EventEmitter<OutputEvents<O>>()
|
||||||
/** Event emitter for the `stderr`. Emits the `data` event. */
|
/** Event emitter for the `stderr`. Emits the `data` event. */
|
||||||
readonly stderr = new EventEmitter<OutputEvents<O>>();
|
readonly stderr = new EventEmitter<OutputEvents<O>>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
@@ -395,25 +395,25 @@ class Command<O extends IOPayload> extends EventEmitter<CommandEvents> {
|
|||||||
private constructor(
|
private constructor(
|
||||||
program: string,
|
program: string,
|
||||||
args: string | string[] = [],
|
args: string | string[] = [],
|
||||||
options?: SpawnOptions,
|
options?: SpawnOptions
|
||||||
) {
|
) {
|
||||||
super();
|
super()
|
||||||
this.program = program;
|
this.program = program
|
||||||
this.args = typeof args === "string" ? [args] : args;
|
this.args = typeof args === 'string' ? [args] : args
|
||||||
this.options = options ?? {};
|
this.options = options ?? {}
|
||||||
}
|
}
|
||||||
|
|
||||||
static create(program: string, args?: string | string[]): Command<string>;
|
static create(program: string, args?: string | string[]): Command<string>
|
||||||
static create(
|
static create(
|
||||||
program: string,
|
program: string,
|
||||||
args?: string | string[],
|
args?: string | string[],
|
||||||
options?: SpawnOptions & { encoding: "raw" },
|
options?: SpawnOptions & { encoding: 'raw' }
|
||||||
): Command<Uint8Array>;
|
): Command<Uint8Array>
|
||||||
static create(
|
static create(
|
||||||
program: string,
|
program: string,
|
||||||
args?: string | string[],
|
args?: string | string[],
|
||||||
options?: SpawnOptions,
|
options?: SpawnOptions
|
||||||
): Command<string>;
|
): Command<string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a command to execute the given program.
|
* Creates a command to execute the given program.
|
||||||
@@ -430,22 +430,22 @@ class Command<O extends IOPayload> extends EventEmitter<CommandEvents> {
|
|||||||
static create<O extends IOPayload>(
|
static create<O extends IOPayload>(
|
||||||
program: string,
|
program: string,
|
||||||
args: string | string[] = [],
|
args: string | string[] = [],
|
||||||
options?: SpawnOptions,
|
options?: SpawnOptions
|
||||||
): Command<O> {
|
): Command<O> {
|
||||||
return new Command(program, args, options);
|
return new Command(program, args, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
static sidecar(program: string, args?: string | string[]): Command<string>;
|
static sidecar(program: string, args?: string | string[]): Command<string>
|
||||||
static sidecar(
|
static sidecar(
|
||||||
program: string,
|
program: string,
|
||||||
args?: string | string[],
|
args?: string | string[],
|
||||||
options?: SpawnOptions & { encoding: "raw" },
|
options?: SpawnOptions & { encoding: 'raw' }
|
||||||
): Command<Uint8Array>;
|
): Command<Uint8Array>
|
||||||
static sidecar(
|
static sidecar(
|
||||||
program: string,
|
program: string,
|
||||||
args?: string | string[],
|
args?: string | string[],
|
||||||
options?: SpawnOptions,
|
options?: SpawnOptions
|
||||||
): Command<string>;
|
): Command<string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a command to execute the given sidecar program.
|
* Creates a command to execute the given sidecar program.
|
||||||
@@ -462,11 +462,11 @@ class Command<O extends IOPayload> extends EventEmitter<CommandEvents> {
|
|||||||
static sidecar<O extends IOPayload>(
|
static sidecar<O extends IOPayload>(
|
||||||
program: string,
|
program: string,
|
||||||
args: string | string[] = [],
|
args: string | string[] = [],
|
||||||
options?: SpawnOptions,
|
options?: SpawnOptions
|
||||||
): Command<O> {
|
): Command<O> {
|
||||||
const instance = new Command<O>(program, args, options);
|
const instance = new Command<O>(program, args, options)
|
||||||
instance.options.sidecar = true;
|
instance.options.sidecar = true
|
||||||
return instance;
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -477,38 +477,38 @@ class Command<O extends IOPayload> extends EventEmitter<CommandEvents> {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
async spawn(): Promise<Child> {
|
async spawn(): Promise<Child> {
|
||||||
const program = this.program;
|
const program = this.program
|
||||||
const args = this.args;
|
const args = this.args
|
||||||
const options = this.options;
|
const options = this.options
|
||||||
|
|
||||||
if (typeof args === "object") {
|
if (typeof args === 'object') {
|
||||||
Object.freeze(args);
|
Object.freeze(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onEvent = new Channel<CommandEvent<O>>();
|
const onEvent = new Channel<CommandEvent<O>>()
|
||||||
onEvent.onmessage = (event) => {
|
onEvent.onmessage = (event) => {
|
||||||
switch (event.event) {
|
switch (event.event) {
|
||||||
case "Error":
|
case 'Error':
|
||||||
this.emit("error", event.payload);
|
this.emit('error', event.payload)
|
||||||
break;
|
break
|
||||||
case "Terminated":
|
case 'Terminated':
|
||||||
this.emit("close", event.payload);
|
this.emit('close', event.payload)
|
||||||
break;
|
break
|
||||||
case "Stdout":
|
case 'Stdout':
|
||||||
this.stdout.emit("data", event.payload);
|
this.stdout.emit('data', event.payload)
|
||||||
break;
|
break
|
||||||
case "Stderr":
|
case 'Stderr':
|
||||||
this.stderr.emit("data", event.payload);
|
this.stderr.emit('data', event.payload)
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
return await invoke<number>("plugin:shell|spawn", {
|
return await invoke<number>('plugin:shell|spawn', {
|
||||||
program,
|
program,
|
||||||
args,
|
args,
|
||||||
options,
|
options,
|
||||||
onEvent,
|
onEvent
|
||||||
}).then((pid) => new Child(pid));
|
}).then((pid) => new Child(pid))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -528,19 +528,19 @@ class Command<O extends IOPayload> extends EventEmitter<CommandEvents> {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
async execute(): Promise<ChildProcess<O>> {
|
async execute(): Promise<ChildProcess<O>> {
|
||||||
const program = this.program;
|
const program = this.program
|
||||||
const args = this.args;
|
const args = this.args
|
||||||
const options = this.options;
|
const options = this.options
|
||||||
|
|
||||||
if (typeof args === "object") {
|
if (typeof args === 'object') {
|
||||||
Object.freeze(args);
|
Object.freeze(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
return await invoke<ChildProcess<O>>("plugin:shell|execute", {
|
return await invoke<ChildProcess<O>>('plugin:shell|execute', {
|
||||||
program,
|
program,
|
||||||
args,
|
args,
|
||||||
options,
|
options
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -548,8 +548,8 @@ class Command<O extends IOPayload> extends EventEmitter<CommandEvents> {
|
|||||||
* Describes the event message received from the command.
|
* Describes the event message received from the command.
|
||||||
*/
|
*/
|
||||||
interface Event<T, V> {
|
interface Event<T, V> {
|
||||||
event: T;
|
event: T
|
||||||
payload: V;
|
payload: V
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -557,20 +557,20 @@ interface Event<T, V> {
|
|||||||
*/
|
*/
|
||||||
interface TerminatedPayload {
|
interface TerminatedPayload {
|
||||||
/** Exit code of the process. `null` if the process was terminated by a signal on Unix. */
|
/** Exit code of the process. `null` if the process was terminated by a signal on Unix. */
|
||||||
code: number | null;
|
code: number | null
|
||||||
/** If the process was terminated by a signal, represents that signal. */
|
/** If the process was terminated by a signal, represents that signal. */
|
||||||
signal: number | null;
|
signal: number | null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Event payload type */
|
/** Event payload type */
|
||||||
type IOPayload = string | Uint8Array;
|
type IOPayload = string | Uint8Array
|
||||||
|
|
||||||
/** Events emitted by the child process. */
|
/** Events emitted by the child process. */
|
||||||
type CommandEvent<O extends IOPayload> =
|
type CommandEvent<O extends IOPayload> =
|
||||||
| Event<"Stdout", O>
|
| Event<'Stdout', O>
|
||||||
| Event<"Stderr", O>
|
| Event<'Stderr', O>
|
||||||
| Event<"Terminated", TerminatedPayload>
|
| Event<'Terminated', TerminatedPayload>
|
||||||
| Event<"Error", string>;
|
| Event<'Error', string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a path or URL with the system's default app,
|
* Opens a path or URL with the system's default app,
|
||||||
@@ -599,18 +599,18 @@ type CommandEvent<O extends IOPayload> =
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
async function open(path: string, openWith?: string): Promise<void> {
|
async function open(path: string, openWith?: string): Promise<void> {
|
||||||
await invoke("plugin:shell|open", {
|
await invoke('plugin:shell|open', {
|
||||||
path,
|
path,
|
||||||
with: openWith,
|
with: openWith
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Command, Child, EventEmitter, open };
|
export { Command, Child, EventEmitter, open }
|
||||||
export type {
|
export type {
|
||||||
IOPayload,
|
IOPayload,
|
||||||
CommandEvents,
|
CommandEvents,
|
||||||
TerminatedPayload,
|
TerminatedPayload,
|
||||||
OutputEvents,
|
OutputEvents,
|
||||||
ChildProcess,
|
ChildProcess,
|
||||||
SpawnOptions,
|
SpawnOptions
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -2,39 +2,39 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
|
||||||
// open <a href="..."> links with the API
|
// open <a href="..."> links with the API
|
||||||
function openLinks(): void {
|
function openLinks(): void {
|
||||||
document.querySelector("body")?.addEventListener("click", function (e) {
|
document.querySelector('body')?.addEventListener('click', function (e) {
|
||||||
let target: HTMLElement | null = e.target as HTMLElement;
|
let target: HTMLElement | null = e.target as HTMLElement
|
||||||
while (target) {
|
while (target) {
|
||||||
if (target.matches("a")) {
|
if (target.matches('a')) {
|
||||||
const t = target as HTMLAnchorElement;
|
const t = target as HTMLAnchorElement
|
||||||
if (
|
if (
|
||||||
t.href !== "" &&
|
t.href !== '' &&
|
||||||
["http://", "https://", "mailto:", "tel:"].some((v) =>
|
['http://', 'https://', 'mailto:', 'tel:'].some((v) =>
|
||||||
t.href.startsWith(v),
|
t.href.startsWith(v)
|
||||||
) &&
|
) &&
|
||||||
t.target === "_blank"
|
t.target === '_blank'
|
||||||
) {
|
) {
|
||||||
void invoke("plugin:shell|open", {
|
void invoke('plugin:shell|open', {
|
||||||
path: t.href,
|
path: t.href
|
||||||
});
|
})
|
||||||
e.preventDefault();
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
target = target.parentElement;
|
target = target.parentElement
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
document.readyState === "complete" ||
|
document.readyState === 'complete' ||
|
||||||
document.readyState === "interactive"
|
document.readyState === 'interactive'
|
||||||
) {
|
) {
|
||||||
openLinks();
|
openLinks()
|
||||||
} else {
|
} else {
|
||||||
window.addEventListener("DOMContentLoaded", openLinks, true);
|
window.addEventListener('DOMContentLoaded', openLinks, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,4 @@ scope pre-configured. It will allow opening `http(s)://`,
|
|||||||
`tel:` and `mailto:` links.
|
`tel:` and `mailto:` links.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
permissions = [
|
permissions = ["allow-open"]
|
||||||
"allow-open",
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -2,21 +2,21 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import { createConfig } from "../../shared/rollup.config.js";
|
import { createConfig } from '../../shared/rollup.config.js'
|
||||||
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
||||||
import typescript from "@rollup/plugin-typescript";
|
import typescript from '@rollup/plugin-typescript'
|
||||||
import terser from "@rollup/plugin-terser";
|
import terser from '@rollup/plugin-terser'
|
||||||
|
|
||||||
export default createConfig({
|
export default createConfig({
|
||||||
additionalConfigs: {
|
additionalConfigs: {
|
||||||
input: "guest-js/init.ts",
|
input: 'guest-js/init.ts',
|
||||||
output: {
|
output: {
|
||||||
file: "src/init-iife.js",
|
file: 'src/init-iife.js',
|
||||||
format: "iife",
|
format: 'iife'
|
||||||
},
|
},
|
||||||
plugins: [typescript(), terser(), nodeResolve()],
|
plugins: [typescript(), terser(), nodeResolve()],
|
||||||
onwarn: (warning) => {
|
onwarn: (warning) => {
|
||||||
throw Object.assign(new Error(), warning);
|
throw Object.assign(new Error(), warning)
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
});
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user