Skip to content

Commit

Permalink
improved device select for apps, files and info
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Dec 24, 2024
1 parent eb6ab1f commit b60ccec
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 258 deletions.
136 changes: 68 additions & 68 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src-tauri/src/conn_pool/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::Path;
use std::sync::Mutex;
use std::time::Duration;

use libssh_rs::{AuthStatus, Session, SshKey, SshOption};
use libssh_rs::{AuthStatus, LogLevel, Session, SshKey, SshOption};
use regex::Regex;
use uuid::Uuid;

Expand All @@ -21,6 +21,7 @@ impl DeviceConnection {
session.set_option(SshOption::Hostname(device.host.clone()))?;
session.set_option(SshOption::Port(device.port.clone()))?;
session.set_option(SshOption::User(Some(device.username.clone())))?;
session.set_option(SshOption::LogLevel(LogLevel::Protocol))?;

session.connect()?;

Expand Down
19 changes: 14 additions & 5 deletions src-tauri/src/plugins/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::error::Error;
use crate::event_channel::{EventChannel, EventHandler};
use crate::session_manager::{Proc, ProcCallback, ProcData, SessionManager};
use crate::spawn_manager::SpawnManager;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use tauri::{
plugin::{Builder, TauriPlugin},
AppHandle, Manager, Runtime, State,
Expand All @@ -20,7 +20,7 @@ async fn exec<R: Runtime>(
command: String,
stdin: Option<ByteString>,
encoding: Option<Encoding>,
) -> Result<ByteString, Error> {
) -> Result<ExecOutput, Error> {
let encoding = encoding.unwrap_or(Encoding::Binary);
return tokio::task::spawn_blocking(move || {
let sessions = app.state::<SessionManager>();
Expand All @@ -32,8 +32,8 @@ async fn exec<R: Runtime>(
ch.stdin().write_all(&stdin.as_ref())?;
ch.send_eof()?;
}
let mut buf = Vec::<u8>::new();
ch.stdout().read_to_end(&mut buf)?;
let mut stdout = Vec::<u8>::new();
ch.stdout().read_to_end(&mut stdout)?;
let mut stderr = Vec::<u8>::new();
ch.stderr().read_to_end(&mut stderr)?;
let exit_code = ch.get_exit_status().unwrap_or(0);
Expand All @@ -48,7 +48,10 @@ async fn exec<R: Runtime>(
unhandled: true,
});
}
return Ok(ByteString::parse(&buf, encoding).unwrap());
return Ok(ExecOutput {
stdout: ByteString::parse(&stdout, encoding).unwrap(),
stderr: ByteString::parse(&stderr, encoding).unwrap(),
});
});
})
.await
Expand Down Expand Up @@ -113,6 +116,12 @@ struct TxPayload {
data: Option<Vec<u8>>,
}

#[derive(Serialize, Debug)]
struct ExecOutput {
stdout: ByteString,
stderr: ByteString,
}

impl<R: Runtime> ProcCallback for ProcCallbackImpl<R> {
fn rx(&self, fd: u32, data: &[u8]) {
self.channel.rx(ProcData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class DeviceEditorComponent implements OnInit {
const file = await showOpenDialog({
multiple: false,
defaultPath: sshDir,
}).then(result => result?.path);
}).then(result => result);
if (typeof (file) !== 'string' || !file) {
return;
}
Expand Down
14 changes: 9 additions & 5 deletions src/app/apps/apps.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<div class="w-100 h-100 d-flex flex-column overflow-hidden" xmlns="http://www.w3.org/1999/html">
<nav class="manager-toolbar navbar bg-panel border-bottom px-2">
<div class="me-auto">
<ul ngbNav #nav="ngbNav" class="nav-pills" [(activeId)]="tabId">
<div class="d-flex flex-row w-100">
<select class="form-select w-auto" [value]="device?.name" (change)="deviceManager.setDefault(deviceSelect.value)"
#deviceSelect>
@for (dev of devices$ | async; track dev.name) {
<option [ngValue]="dev.name" [selected]="dev.name === device?.name">{{ dev.name }}</option>
}
</select>
<ul ngbNav #nav="ngbNav" class="nav-pills flex-nowrap ms-2" [(activeId)]="tabId">
<li ngbNavItem="installed">
<a ngbNavLink>Installed</a>
<ng-template ngbNavContent>
Expand All @@ -15,9 +21,7 @@
</ng-template>
</li>
</ul>
</div>
<div>
<button class="btn btn-primary" (click)="openInstallChooser()">
<button class="btn btn-primary text-nowrap ms-auto" (click)="openInstallChooser()">
<i class="bi bi-folder-fill me-2"></i>Install
</button>
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/app/apps/apps.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class AppsComponent implements OnInit, OnDestroy {
packages$?: Observable<PackageInfo[] | null>;
instPackages?: Record<string, RawPackageInfo>;
device: Device | null = null;
devices$?: Observable<Device[]|null>;
tabId: string = 'installed';

@ViewChild('storageInfo') storageInfo?: StatStorageInfoComponent;
Expand All @@ -31,13 +32,14 @@ export class AppsComponent implements OnInit, OnDestroy {
private packagesSubscription?: Subscription;

constructor(
public deviceManager: DeviceManagerService,
private modalService: NgbModal,
private deviceManager: DeviceManagerService,
private appManager: AppManagerService,
) {
}

ngOnInit(): void {
this.devices$ = this.deviceManager.devices$;
this.deviceSubscription = this.deviceManager.selected$.subscribe((device) => {
this.device = device;
if (device) {
Expand Down Expand Up @@ -77,7 +79,7 @@ export class AppsComponent implements OnInit, OnDestroy {
filters: [{name: 'IPK package', extensions: ['ipk']}],
multiple: false,
defaultPath: await downloadDir(),
}).then(result => result?.path);
}).then(result => result);
if (!path) {
return;
}
Expand Down
Loading

0 comments on commit b60ccec

Please sign in to comment.