mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Notifications
This commit is contained in:
@@ -22,12 +22,15 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
// Locals
|
||||
use super::{ConfigClient, FileTransferActivity, LogLevel, LogRecord};
|
||||
use super::{ConfigClient, FileTransferActivity, LogLevel, LogRecord, TransferPayload};
|
||||
use crate::filetransfer::ProtocolParams;
|
||||
use crate::system::environment;
|
||||
use crate::system::notifications::Notification;
|
||||
use crate::system::sshkey_storage::SshKeyStorage;
|
||||
use crate::utils::fmt::fmt_millis;
|
||||
use crate::utils::path;
|
||||
// Ext
|
||||
use bytesize::ByteSize;
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use tuirealm::Update;
|
||||
@@ -146,4 +149,86 @@ impl FileTransferActivity {
|
||||
ProtocolParams::AwsS3(params) => params.bucket_name.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// ### get_connection_msg
|
||||
///
|
||||
/// Get connection message to show to client
|
||||
pub(super) fn get_connection_msg(params: &ProtocolParams) -> String {
|
||||
match params {
|
||||
ProtocolParams::Generic(params) => {
|
||||
info!(
|
||||
"Client is not connected to remote; connecting to {}:{}",
|
||||
params.address, params.port
|
||||
);
|
||||
format!("Connecting to {}:{}…", params.address, params.port)
|
||||
}
|
||||
ProtocolParams::AwsS3(params) => {
|
||||
info!(
|
||||
"Client is not connected to remote; connecting to {} ({})",
|
||||
params.bucket_name, params.region
|
||||
);
|
||||
format!("Connecting to {}…", params.bucket_name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// ### notify_transfer_completed
|
||||
///
|
||||
/// Send notification regarding transfer completed
|
||||
/// The notification is sent only when these conditions are satisfied:
|
||||
///
|
||||
/// - notifications are enabled
|
||||
/// - transfer size is greater or equal than notification threshold
|
||||
pub(super) fn notify_transfer_completed(&self, payload: &TransferPayload) {
|
||||
if self.config().get_notifications()
|
||||
&& self.config().get_notification_threshold() as usize <= self.transfer.full_size()
|
||||
{
|
||||
Notification::transfer_completed(self.transfer_completed_msg(payload));
|
||||
}
|
||||
}
|
||||
|
||||
/// ### notify_transfer_error
|
||||
///
|
||||
/// Send notification regarding transfer error
|
||||
/// The notification is sent only when these conditions are satisfied:
|
||||
///
|
||||
/// - notifications are enabled
|
||||
/// - transfer size is greater or equal than notification threshold
|
||||
pub(super) fn notify_transfer_error(&self, msg: &str) {
|
||||
if self.config().get_notifications()
|
||||
&& self.config().get_notification_threshold() as usize <= self.transfer.full_size()
|
||||
{
|
||||
Notification::transfer_error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
fn transfer_completed_msg(&self, payload: &TransferPayload) -> String {
|
||||
let transfer_stats = format!(
|
||||
"took {} seconds; at {}/s",
|
||||
fmt_millis(self.transfer.partial.started().elapsed()),
|
||||
ByteSize(self.transfer.partial.calc_bytes_per_second()),
|
||||
);
|
||||
match payload {
|
||||
TransferPayload::File(file) => {
|
||||
format!(
|
||||
"File \"{}\" has been successfully transferred ({})",
|
||||
file.name, transfer_stats
|
||||
)
|
||||
}
|
||||
TransferPayload::Any(entry) => {
|
||||
format!(
|
||||
"\"{}\" has been successfully transferred ({})",
|
||||
entry.get_name(),
|
||||
transfer_stats
|
||||
)
|
||||
}
|
||||
TransferPayload::Many(entries) => {
|
||||
format!(
|
||||
"{} files has been successfully transferred ({})",
|
||||
entries.len(),
|
||||
transfer_stats
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user