Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Termux integration #941

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Termux integration #941

wants to merge 4 commits into from

Conversation

7HR4IZ3
Copy link

@7HR4IZ3 7HR4IZ3 commented Mar 10, 2024

Added system.run and system.execute commands to the system plugin.

  • system.run(Command): Promise: It runs the command then returns a PtyResponse or throws a PtyError
  • system.execute(Command): Promise: It runs the command but dosen’t wait for the output or any error thrown.

Added pty module and export to acode

The pty.host.run function takes the RunCommand type as argument

Example Usage

let pty = acode.require("pty");

// Create new connection
let connection = await pty.host.run({
  command: "bash", args: [],
  onmessage(stdout) {
    console.log(stdout);
  }
});

// Add listeners
connection.addEventListener("open", () => {});
connection.addEventListener("close", () => {});
connection.addEventListener("error", () => {});
connection.addEventListener("message", () => {});
connection.addEventListener("reconnect", () => {});

// Kill connection
connection.kll();

Type Interface

Command

  • command: String: Represent the command to be executed
  • args: Array: Arguments to be passed to the command
  • background: Boolean: Specify whether to run the command in the background as a task
  • homeDir: String: Path where the command should be executed from

PtyResponse

  • stderr: String
  • stdout: String
  • exitCode: Number
  • stderrLength: Number
  • stdoutLength: Number

PtyError

  • error: String
  • errorCode: Number
  • exitCode: Number

RunCommand

  • command: String: Represent the command to be executed
  • type: String: Specify connection type, should be either pty(pseudo terminal mode) or process(simply execute the command and relay putputs)
  • args: Array: Arguments to be passed to the command
  • onmessage: Function(data): void : Specify function to be called when a message comes through
  • autoReconnect: Boolean: Auto reconnect to server in case of disconnection?
  • reconnectDelay: Number: How long to wait before attempting to reconnect
  • maxRetries: Number: How many times to try to reconnect before giving up

@deadlyjack
Copy link
Owner

Hi, thanks for this PR. Seems to be an amazing update. As there are too many changes, I'll have to review it carefully and merge it.

@7HR4IZ3
Copy link
Author

7HR4IZ3 commented Mar 11, 2024

Alright.. I also had to make some modification to make it run on my device.

  • Like changing the package to the free version.
  • Adding tailwindcss (Pushed it by mistake)
  • Adding notifications plugin to notify users when a command is running
  • Adding http plugin to bypass cors limit on browser fetch function (planning on adding websocket server to the server plugin so it can be used to add live reload functions to the browser)

Also we still have to figure out a way to prevent plugins from running commands without the user's permission, like adding:

...
"permissions": ["acode.pty.command"]
...

But then we'll need to figure out a way to identify which plugin is running the command..

@deadlyjack
Copy link
Owner

Also we still have to figure out a way to prevent plugins from running commands without the user's permission, like adding:

Yeah, this is must. Let me get some free time and add the permission mechanism in the Acode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants