[go: up one dir, main page]

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 #997

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

7HR4IZ3
Copy link
@7HR4IZ3 7HR4IZ3 commented Jul 26, 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

System Run

system.run({
    command: "/data/data/com.termux/files/usr/bin/ls",
    workDir: "/data/data/com.termux/files/home", args: ["-a"],
    background: false, sessionAction: 3
  }).then(console.log)

Read this (TERMUX.RUN_COMMAND) for more info on sessionAction and other arguments

Using Acode PTY

You should use this for spawning and interacting with processes

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

@7HR4IZ3
Copy link
Author
7HR4IZ3 commented Jul 31, 2024

@bajrangCoder Could you test this out?

@bajrangCoder
Copy link
Collaborator

@bajrangCoder Could you test this out?

I will check it , I will notify if any changes will need

@bajrangCoder bajrangCoder self-assigned this Aug 1, 2024
@bajrangCoder
Copy link
Collaborator

I have tried many times but haven't succeeded, even after making modifications. None of my attempts have been successful; almost every time I try, it fails. Since this solution isn't working, I can't merge it. It needs to work flawlessly on supported devices. Please refine your implementation and also share a test APK for testing.

Additionally, why is there a need to ask for permission to run a command in Termux if the user doesn't have Termux installed?

I think your pull request is quite tangled. Have you tried building the APK from this PR? Did you succeed?

@7HR4IZ3 7HR4IZ3 marked this pull request as draft August 31, 2024 10:21
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.

2 participants