some changes

This commit is contained in:
EthanShoeDev
2025-09-14 11:44:45 -04:00
parent 26e206abf2
commit ba1b37a258
4 changed files with 37 additions and 7 deletions

View File

@@ -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::sync::{Arc, Mutex, Weak};
use std::time::{SystemTime, UNIX_EPOCH};

View File

@@ -68,7 +68,9 @@ async function connect(options: ConnectOptions) {
security,
onStatusChange: options.onStatusChange ? {
onChange: (statusEnum) => {
options.onStatusChange?.(sshConnStatusEnumToLiteral[statusEnum]!);
const tsLiteral = sshConnStatusEnumToLiteral[statusEnum];
if (!tsLiteral) throw new Error(`Invalid status enum: ${statusEnum}`);
options.onStatusChange?.(tsLiteral);
},
} : undefined,
},
@@ -99,7 +101,20 @@ async function connect(options: ConnectOptions) {
}
type BetterStartShellFn = typeof 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>>;