windows cleanup

This commit is contained in:
John Smith 2023-10-07 23:00:28 -04:00
parent dca7f66c6f
commit 1fec1a5008
5 changed files with 79 additions and 48 deletions

1
Cargo.lock generated
View File

@ -5229,6 +5229,7 @@ dependencies = [
"async-std", "async-std",
"async-tungstenite", "async-tungstenite",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"chrono",
"clap 4.4.4", "clap 4.4.4",
"config", "config",
"crossbeam-channel", "crossbeam-channel",

View File

@ -2,7 +2,6 @@ use crate::command_processor::*;
use crate::peers_table_view::*; use crate::peers_table_view::*;
use crate::settings::Settings; use crate::settings::Settings;
use crate::tools::*; use crate::tools::*;
use async_tungstenite::tungstenite::http::header::STRICT_TRANSPORT_SECURITY;
use crossbeam_channel::Sender; use crossbeam_channel::Sender;
use cursive::align::*; use cursive::align::*;
use cursive::event::*; use cursive::event::*;
@ -15,12 +14,12 @@ use cursive::Cursive;
use cursive::CursiveRunnable; use cursive::CursiveRunnable;
use cursive_flexi_logger_view::{CursiveLogWriter, FlexiLoggerView}; use cursive_flexi_logger_view::{CursiveLogWriter, FlexiLoggerView};
// use cursive_multiplex::*; // use cursive_multiplex::*;
use chrono::{Datelike, Timelike};
use std::collections::{HashMap, VecDeque}; use std::collections::{HashMap, VecDeque};
use std::io::Write; use std::io::Write;
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use thiserror::Error; use thiserror::Error;
use std::sync::atomic::{AtomicU64, Ordering};
use chrono::{Datelike, Timelike};
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
/// ///
@ -52,8 +51,6 @@ impl<T> Dirty<T> {
pub type UICallback = Box<dyn Fn(&mut Cursive) + Send>; pub type UICallback = Box<dyn Fn(&mut Cursive) + Send>;
static START_TIME: AtomicU64 = AtomicU64::new(0); static START_TIME: AtomicU64 = AtomicU64::new(0);
struct UIState { struct UIState {
@ -365,7 +362,7 @@ impl UI {
let color = *Self::inner_mut(s).log_colors.get(&Level::Error).unwrap(); let color = *Self::inner_mut(s).log_colors.get(&Level::Error).unwrap();
cursive_flexi_logger_view::parse_lines_to_log( cursive_flexi_logger_view::parse_lines_to_log(
color.into(), color.into(),
format!(" {} Error: {}", UI::cli_ts(Self::get_start_time()), e) format!(" {} Error: {}", UI::cli_ts(Self::get_start_time()), e),
); );
} }
} }
@ -464,23 +461,7 @@ impl UI {
Self::command_processor(s).start_connection(); Self::command_processor(s).start_connection();
} }
fn copy_to_clipboard<S: AsRef<str>>(s: &mut Cursive, text: S) { fn copy_to_clipboard_osc52<S: AsRef<str>>(s: &mut Cursive, text: S) {
if let Ok(mut clipboard) = arboard::Clipboard::new() {
// X11/Wayland/other system copy
if clipboard.set_text(text.as_ref()).is_ok() {
let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap();
cursive_flexi_logger_view::parse_lines_to_log(
color.into(),
format!(">> {} Copied: {}", UI::cli_ts(Self::get_start_time()), text.as_ref()),
);
} else {
let color = *Self::inner_mut(s).log_colors.get(&Level::Warn).unwrap();
cursive_flexi_logger_view::parse_lines_to_log(
color.into(),
format!(">> {} Could not copy to clipboard", UI::cli_ts(Self::get_start_time()))
);
}
} else {
// OSC52 clipboard copy for terminals // OSC52 clipboard copy for terminals
if std::io::stdout() if std::io::stdout()
.write_all( .write_all(
@ -493,14 +474,43 @@ impl UI {
.is_ok() .is_ok()
&& std::io::stdout().flush().is_ok() && std::io::stdout().flush().is_ok()
{ {
if std::io::stdout().flush().is_ok() {
let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap();
cursive_flexi_logger_view::parse_lines_to_log( cursive_flexi_logger_view::parse_lines_to_log(
color.into(), color.into(),
format!(">> {} Copied: {}", UI::cli_ts(Self::get_start_time()), text.as_ref()), format!(
">> {} Copied: {}",
UI::cli_ts(Self::get_start_time()),
text.as_ref()
),
); );
} }
} }
fn copy_to_clipboard<S: AsRef<str>>(s: &mut Cursive, text: S) {
if let Ok(mut clipboard) = arboard::Clipboard::new() {
// X11/Wayland/other system copy
if clipboard.set_text(text.as_ref()).is_ok() {
let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap();
cursive_flexi_logger_view::parse_lines_to_log(
color.into(),
format!(
">> {} Copied: {}",
UI::cli_ts(Self::get_start_time()),
text.as_ref()
),
);
} else {
let color = *Self::inner_mut(s).log_colors.get(&Level::Warn).unwrap();
cursive_flexi_logger_view::parse_lines_to_log(
color.into(),
format!(
">> {} Could not copy to clipboard",
UI::cli_ts(Self::get_start_time())
),
);
}
} else {
Self::copy_to_clipboard_osc52(s, text)
} }
} }
@ -788,14 +798,11 @@ impl UI {
} }
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Public functions // Public functions
#[allow(clippy::format_in_format_args)]
pub fn cli_ts(ts: u64) -> String { pub fn cli_ts(ts: u64) -> String {
//let ts = get_timestamp();
let now = chrono::DateTime::<chrono::Utc>::from(SystemTime::now()); let now = chrono::DateTime::<chrono::Utc>::from(SystemTime::now());
let date = chrono::DateTime::<chrono::Utc>::from(UNIX_EPOCH + Duration::from_micros(ts)); let date = chrono::DateTime::<chrono::Utc>::from(UNIX_EPOCH + Duration::from_micros(ts));
@ -806,17 +813,20 @@ impl UI {
if show_year || show_month || show_date { if show_year || show_month || show_date {
UI::set_start_time(); UI::set_start_time();
} }
format!("{}{}", format!(
"{}{}",
if show_year || show_month || show_date { if show_year || show_month || show_date {
format!("Day changed: {:04}/{:02}/{:02} \n",now.year(), now.month(), now.day()) format!(
"Day changed: {:04}/{:02}/{:02} \n",
now.year(),
now.month(),
now.day()
)
} else { } else {
"".to_owned() "".to_owned()
}, },
format!("{:02}:{:02}:{:02}", format!("{:02}:{:02}:{:02}", now.hour(), now.minute(), now.second())
now.hour(), )
now.minute(),
now.second()
))
} }
pub fn set_start_time() { pub fn set_start_time() {
@ -985,7 +995,6 @@ impl UI {
// pub fn run(&mut self) { // pub fn run(&mut self) {
// self.siv.run(); // self.siv.run();
// } // }
} }
type CallbackSink = Box<dyn FnOnce(&mut Cursive) + 'static + Send>; type CallbackSink = Box<dyn FnOnce(&mut Cursive) + 'static + Send>;
@ -1088,7 +1097,10 @@ impl UISender {
{ {
let inner = self.inner.lock(); let inner = self.inner.lock();
let color = *inner.log_colors.get(&log_color).unwrap(); let color = *inner.log_colors.get(&log_color).unwrap();
cursive_flexi_logger_view::parse_lines_to_log(color.into(), format!("{}: {}", UI::cli_ts(UI::get_start_time()), event)); cursive_flexi_logger_view::parse_lines_to_log(
color.into(),
format!("{}: {}", UI::cli_ts(UI::get_start_time()), event),
);
} }
let _ = self.cb_sink.send(Box::new(UI::update_cb)); let _ = self.cb_sink.send(Box::new(UI::update_cb));
} }

View File

@ -69,7 +69,7 @@ impl SockAddr {
return None; return None;
} }
Some(IpAddr::V4(Ipv4Addr::new( Some(IpAddr::V4(Ipv4Addr::new(
((s_addr >> 0) & 255u32) as u8, (s_addr & 255u32) as u8,
((s_addr >> 8) & 255u32) as u8, ((s_addr >> 8) & 255u32) as u8,
((s_addr >> 16) & 255u32) as u8, ((s_addr >> 16) & 255u32) as u8,
((s_addr >> 24) & 255u32) as u8, ((s_addr >> 24) & 255u32) as u8,
@ -81,7 +81,7 @@ impl SockAddr {
if s6_addr[0] == 0xfe && s6_addr[1] == 0x80 { if s6_addr[0] == 0xfe && s6_addr[1] == 0x80 {
return None; return None;
} }
Some(IpAddr::V6(Ipv6Addr::from(s6_addr.clone()))) Some(IpAddr::V6(Ipv6Addr::from(*s6_addr)))
} }
None => None, None => None,
} }

View File

@ -9,12 +9,21 @@ include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
Corrosion Corrosion
GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git
GIT_TAG origin/master # Optionally specify a version tag or branch here GIT_TAG v0.4.4 # Optionally specify a version tag or branch here
) )
FetchContent_MakeAvailable(Corrosion) FetchContent_MakeAvailable(Corrosion)
corrosion_import_crate(MANIFEST_PATH ${CMAKE_SOURCE_DIR}/../../rust/Cargo.toml CRATES veilid-flutter) execute_process(COMMAND git rev-parse --show-cdup
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE relative_path_to_repository_root)
string(STRIP ${relative_path_to_repository_root} relative_path_to_repository_root)
get_filename_component(repository_root
"${CMAKE_SOURCE_DIR}/${relative_path_to_repository_root}"
ABSOLUTE)
corrosion_import_crate(MANIFEST_PATH ${repository_root}/../veilid/Cargo.toml CRATES veilid-flutter)
# Flutter-specific # Flutter-specific

View File

@ -9,12 +9,21 @@ include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
Corrosion Corrosion
GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git GIT_REPOSITORY https://github.com/AndrewGaspar/corrosion.git
GIT_TAG v0.2.1 # Optionally specify a version tag or branch here GIT_TAG v0.4.4 # Optionally specify a version tag or branch here
) )
FetchContent_MakeAvailable(Corrosion) FetchContent_MakeAvailable(Corrosion)
corrosion_import_crate(MANIFEST_PATH ${CMAKE_SOURCE_DIR}/../../rust/Cargo.toml CRATES veilid-flutter FEATURES rt-tokio ) execute_process(COMMAND git rev-parse --show-cdup
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE relative_path_to_repository_root)
string(STRIP ${relative_path_to_repository_root} relative_path_to_repository_root)
get_filename_component(repository_root
"${CMAKE_SOURCE_DIR}/${relative_path_to_repository_root}"
ABSOLUTE)
corrosion_import_crate(MANIFEST_PATH ${repository_root}/../veilid/Cargo.toml CRATES veilid-flutter)
# Flutter-specific # Flutter-specific