Good changes

This commit is contained in:
EthanShoeDev
2025-09-20 04:08:23 -04:00
parent e1d8dc76c9
commit 0d904dfafe
10 changed files with 218 additions and 130 deletions

View File

@@ -186,6 +186,7 @@ pub struct ShellSessionInfo {
#[derive(uniffi::Object)]
pub struct SshConnection {
info: SshConnectionInfo,
on_disconnected_callback: Option<Arc<dyn ConnectionDisconnectedCallback>>,
client_handle: AsyncMutex<ClientHandle<NoopHandler>>,
shells: AsyncMutex<HashMap<u32, Arc<ShellSession>>>,
@@ -490,6 +491,11 @@ impl SshConnection {
let h = self.client_handle.lock().await;
h.disconnect(Disconnect::ByApplication, "bye", "").await?;
if let Some(on_disconnected_callback) = self.on_disconnected_callback.as_ref() {
on_disconnected_callback.on_change(self.info.connection_id.clone());
}
Ok(())
}
}
@@ -775,6 +781,7 @@ pub async fn connect(options: ConnectOptions) -> Result<Arc<SshConnection>, SshE
client_handle: AsyncMutex::new(handle),
shells: AsyncMutex::new(HashMap::new()),
self_weak: AsyncMutex::new(Weak::new()),
on_disconnected_callback: options.on_disconnected_callback.clone(),
});
// Initialize weak self reference.
*conn.self_weak.lock().await = Arc::downgrade(&conn);

View File

@@ -153,7 +153,7 @@ type RusshApi = {
// keySize?: number;
// comment?: string;
) => Promise<string>;
validatePrivateKey: (key: string) => boolean;
validatePrivateKey: (key: string) => { valid: true; error?: never } | { valid: false; error: GeneratedRussh.SshError };
};
// #endregion
@@ -196,6 +196,8 @@ const streamEnumToLiteral = {
[GeneratedRussh.StreamKind.Stderr]: 'stderr',
} as const satisfies Record<GeneratedRussh.StreamKind, StreamKind>;
function generatedConnDetailsToIdeal(
details: GeneratedRussh.ConnectionDetails
): ConnectionDetails {
@@ -379,17 +381,19 @@ async function generateKeyPair(type: 'rsa' | 'ecdsa' | 'ed25519') {
return GeneratedRussh.generateKeyPair(map[type]);
}
function validatePrivateKey(key: string) {
function validatePrivateKey(key: string): { valid: true; error?: never } | { valid: false; error: GeneratedRussh.SshError } {
try {
GeneratedRussh.validatePrivateKey(key);
return true;
} catch {
return false;
return { valid: true };
} catch (e) {
return { valid: false, error: e as GeneratedRussh.SshError };
}
}
// #endregion
export { SshError, SshError_Tags } from './generated/uniffi_russh';
export const RnRussh = {
uniffiInitAsync: GeneratedRussh.uniffiInitAsync,
connect,