mirror of
https://github.com/EthanShoeDev/fressh.git
synced 2026-01-11 14:22:51 +00:00
some changes
This commit is contained in:
@@ -22,11 +22,17 @@ export default function Shell() {
|
|||||||
const [shellData, setShellData] = useState('');
|
const [shellData, setShellData] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const channelListenerId = sshConn.client.addChannelListener({
|
// Decode ArrayBuffer bytes from the SSH channel into text
|
||||||
onData: (data) => {
|
const decoder = new TextDecoder('utf-8');
|
||||||
console.log('Received data (on Shell):', data);
|
const channelListenerId = sshConn.client.addChannelListener((data) => {
|
||||||
setShellData((prev) => prev + data);
|
try {
|
||||||
},
|
const bytes = new Uint8Array(data);
|
||||||
|
const chunk = decoder.decode(bytes);
|
||||||
|
console.log('Received data (on Shell):', chunk.length, 'chars');
|
||||||
|
setShellData((prev) => prev + chunk);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Failed to decode shell data', e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
sshConn.client.removeChannelListener(channelListenerId);
|
sshConn.client.removeChannelListener(channelListenerId);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { type SshConnection } from '@fressh/react-native-uniffi-russh';
|
import { type SshConnection } from '@fressh/react-native-uniffi-russh';
|
||||||
import * as Crypto from 'expo-crypto';
|
import * as Crypto from 'expo-crypto';
|
||||||
|
|
||||||
|
|
||||||
export type SSHConn = {
|
export type SSHConn = {
|
||||||
client: SshConnection;
|
client: SshConnection;
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
//! This file is used to generate Typescript bindings for the Russh library.
|
||||||
|
//!
|
||||||
|
//! For more information on the available data types, see the following links:
|
||||||
|
//! - https://jhugman.github.io/uniffi-bindgen-react-native/idioms/common-types.html
|
||||||
|
//! - https://jhugman.github.io/uniffi-bindgen-react-native/idioms/callback-interfaces.html
|
||||||
|
//! - https://jhugman.github.io/uniffi-bindgen-react-native/idioms/async-callbacks.html
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::{Arc, Mutex, Weak};
|
use std::sync::{Arc, Mutex, Weak};
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|||||||
@@ -68,7 +68,9 @@ async function connect(options: ConnectOptions) {
|
|||||||
security,
|
security,
|
||||||
onStatusChange: options.onStatusChange ? {
|
onStatusChange: options.onStatusChange ? {
|
||||||
onChange: (statusEnum) => {
|
onChange: (statusEnum) => {
|
||||||
options.onStatusChange?.(sshConnStatusEnumToLiteral[statusEnum]!);
|
const tsLiteral = sshConnStatusEnumToLiteral[statusEnum];
|
||||||
|
if (!tsLiteral) throw new Error(`Invalid status enum: ${statusEnum}`);
|
||||||
|
options.onStatusChange?.(tsLiteral);
|
||||||
},
|
},
|
||||||
} : undefined,
|
} : undefined,
|
||||||
},
|
},
|
||||||
@@ -99,7 +101,20 @@ async function connect(options: ConnectOptions) {
|
|||||||
}
|
}
|
||||||
type BetterStartShellFn = typeof betterStartShell;
|
type BetterStartShellFn = typeof betterStartShell;
|
||||||
(sshConnectionInterface as any).startShell = betterStartShell
|
(sshConnectionInterface as any).startShell = betterStartShell
|
||||||
return sshConnectionInterface as GeneratedRussh.SshConnectionInterface & { startShell: BetterStartShellFn };
|
|
||||||
|
|
||||||
|
const originalAddChannelListener = sshConnectionInterface.addChannelListener.bind(sshConnectionInterface);
|
||||||
|
const betterAddChannelListener = (listener: GeneratedRussh.ChannelListener['onData']) => {
|
||||||
|
return originalAddChannelListener({
|
||||||
|
onData: (data) => {
|
||||||
|
listener(data);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
type BetterAddChannelListenerFn = typeof betterAddChannelListener;
|
||||||
|
(sshConnectionInterface as any).addChannelListener = betterAddChannelListener;
|
||||||
|
|
||||||
|
return sshConnectionInterface as GeneratedRussh.SshConnectionInterface & { startShell: BetterStartShellFn; addChannelListener: BetterAddChannelListenerFn };
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SshConnection = Awaited<ReturnType<typeof connect>>;
|
export type SshConnection = Awaited<ReturnType<typeof connect>>;
|
||||||
|
|||||||
Reference in New Issue
Block a user