Skip to content

Commit

Permalink
Merge branch 'hotfix-2024.10.4.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacderida committed Nov 7, 2024
2 parents 647d510 + bf0f2df commit c15803e
Show file tree
Hide file tree
Showing 17 changed files with 410 additions and 230 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

*When editing this file, please respect a line length of 100.*

## 2024-11-07

### Launchpad

#### Added

- You can select a node. Pressing L will show its logs.
- The upgrade screen has an estimated time.

#### Changed

- Launchpad now uses multiple threads. This allows the UI to be functional while nodes are being
started, upgraded, and so on.
- Mbps vs Mb units on status screen.

#### Fixed

- Spinners now move when updating.

## 2024-11-06

### Network
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions node-launchpad/.config/config.json5
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"<Ctrl-b>": {"StatusActions":"TriggerRewardsAddress"},
"<Ctrl-B>": {"StatusActions":"TriggerRewardsAddress"},
"<Ctrl-Shift-b>": {"StatusActions":"TriggerRewardsAddress"},
"<l>": {"StatusActions":"TriggerNodeLogs"},
"<L>": {"StatusActions":"TriggerNodeLogs"},

"up" : {"StatusActions":"PreviousTableItem"},
"down": {"StatusActions":"NextTableItem"},
Expand Down
2 changes: 1 addition & 1 deletion node-launchpad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["MaidSafe Developers <[email protected]>"]
description = "Node Launchpad"
name = "node-launchpad"
version = "0.4.3"
version = "0.4.4"
edition = "2021"
license = "GPL-3.0"
homepage = "https://maidsafe.net"
Expand Down
1 change: 1 addition & 0 deletions node-launchpad/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub enum StatusActions {

TriggerManageNodes,
TriggerRewardsAddress,
TriggerNodeLogs,

PreviousTableItem,
NextTableItem,
Expand Down
2 changes: 1 addition & 1 deletion node-launchpad/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl App {
let change_connection_mode = ChangeConnectionModePopUp::new(connection_mode)?;
let port_range = PortRangePopUp::new(connection_mode, port_from, port_to);
let rewards_address = RewardsAddress::new(app_data.discord_username.clone());
let upgrade_nodes = UpgradeNodesPopUp::default();
let upgrade_nodes = UpgradeNodesPopUp::new(app_data.nodes_to_start);

Ok(Self {
config,
Expand Down
77 changes: 30 additions & 47 deletions node-launchpad/src/bin/tui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use node_launchpad::{
use sn_node_manager::config::is_running_as_root;
use sn_peers_acquisition::PeersArgs;
use std::{env, path::PathBuf};
use tokio::task::LocalSet;

#[derive(Parser, Debug)]
#[command(disable_version_flag = true)]
Expand Down Expand Up @@ -68,7 +67,36 @@ pub struct Cli {
version: bool,
}

async fn tokio_main() -> Result<()> {
fn is_running_in_terminal() -> bool {
atty::is(atty::Stream::Stdout)
}

#[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<()> {
initialize_logging()?;
configure_winsw().await?;

if !is_running_in_terminal() {
info!("Running in non-terminal mode. Launching terminal.");
// If we weren't already running in a terminal, this process returns early, having spawned
// a new process that launches a terminal.
let terminal_type = terminal::detect_and_setup_terminal()?;
terminal::launch_terminal(&terminal_type)
.inspect_err(|err| error!("Error while launching terminal: {err:?}"))?;
return Ok(());
} else {
// Windows spawns the terminal directly, so the check for root has to happen here as well.
debug!("Running inside a terminal!");
#[cfg(target_os = "windows")]
if !is_running_as_root() {
{
// TODO: There is no terminal to show this error message when double clicking on the exe.
error!("Admin privileges required to run on Windows. Exiting.");
color_eyre::eyre::bail!("Admin privileges required to run on Windows. Exiting.");
}
}
}

initialize_panic_handler()?;
let args = Cli::parse();

Expand Down Expand Up @@ -108,48 +136,3 @@ async fn tokio_main() -> Result<()> {

Ok(())
}

fn is_running_in_terminal() -> bool {
atty::is(atty::Stream::Stdout)
}

#[tokio::main]
async fn main() -> Result<()> {
initialize_logging()?;
configure_winsw().await?;

if !is_running_in_terminal() {
info!("Running in non-terminal mode. Launching terminal.");
// If we weren't already running in a terminal, this process returns early, having spawned
// a new process that launches a terminal.
let terminal_type = terminal::detect_and_setup_terminal()?;
terminal::launch_terminal(&terminal_type)
.inspect_err(|err| error!("Error while launching terminal: {err:?}"))?;
return Ok(());
} else {
// Windows spawns the terminal directly, so the check for root has to happen here as well.
debug!("Running inside a terminal!");
#[cfg(target_os = "windows")]
if !is_running_as_root() {
{
// TODO: There is no terminal to show this error message when double clicking on the exe.
error!("Admin privileges required to run on Windows. Exiting.");
color_eyre::eyre::bail!("Admin privileges required to run on Windows. Exiting.");
}
}
}

// Construct a local task set that can run `!Send` futures.
let local = LocalSet::new();
local
.run_until(async {
if let Err(e) = tokio_main().await {
eprintln!("{} failed:", env!("CARGO_PKG_NAME"));

Err(e)
} else {
Ok(())
}
})
.await
}
5 changes: 4 additions & 1 deletion node-launchpad/src/components/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ impl StatefulWidget for Footer {
Span::styled("[Ctrl+S] ", command_style),
Span::styled("Start Nodes", text_style),
Span::styled(" ", Style::default()),
Span::styled("[L] ", command_style),
Span::styled("Open Logs", Style::default().fg(EUCALYPTUS)),
Span::styled(" ", Style::default()),
Span::styled("[Ctrl+X] ", command_style),
Span::styled(
"Stop Nodes",
"Stop All",
if matches!(state, NodesToStart::Running) {
Style::default().fg(EUCALYPTUS)
} else {
Expand Down
17 changes: 3 additions & 14 deletions node-launchpad/src/components/options.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use std::{cmp::max, path::PathBuf};

use color_eyre::eyre::{eyre, Ok, Result};
use color_eyre::eyre::Result;
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Style, Stylize},
text::{Line, Span},
widgets::{Block, Borders, Cell, Row, Table},
Frame,
};
use sn_releases::ReleaseType;
use tokio::sync::mpsc::UnboundedSender;

use super::{header::SelectedMenuItem, Component};
use super::{header::SelectedMenuItem, utils::open_logs, Component};
use crate::{
action::{Action, OptionsActions},
components::header::Header,
Expand All @@ -20,9 +19,7 @@ use crate::{
style::{
COOL_GREY, EUCALYPTUS, GHOST_WHITE, LIGHT_PERIWINKLE, VERY_LIGHT_AZURE, VIVID_SKY_BLUE,
},
system,
};
use sn_node_manager::config::get_service_log_dir_path;

#[derive(Clone)]
pub struct Options {
Expand Down Expand Up @@ -416,15 +413,7 @@ impl Component for Options {
self.rewards_address = rewards_address;
}
OptionsActions::TriggerAccessLogs => {
if let Err(e) = system::open_folder(
get_service_log_dir_path(ReleaseType::NodeLaunchpad, None, None)?
.to_str()
.ok_or_else(|| {
eyre!("We cannot get the log dir path for Node-Launchpad")
})?,
) {
error!("Failed to open folder: {}", e);
}
open_logs(None)?;
}
OptionsActions::TriggerUpdateNodes => {
return Ok(Some(Action::SwitchScene(Scene::UpgradeNodesPopUp)));
Expand Down
29 changes: 20 additions & 9 deletions node-launchpad/src/components/popup/upgrade_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::super::utils::centered_rect_fixed;
use super::super::Component;
use crate::{
action::{Action, OptionsActions},
components::status,
mode::{InputMode, Scene},
style::{clear_area, EUCALYPTUS, GHOST_WHITE, LIGHT_PERIWINKLE, VIVID_SKY_BLUE},
};
Expand All @@ -18,19 +19,17 @@ use crossterm::event::{KeyCode, KeyEvent};
use ratatui::{prelude::*, widgets::*};

pub struct UpgradeNodesPopUp {
nodes_to_start: usize,
/// Whether the component is active right now, capturing keystrokes + draw things.
active: bool,
}

impl UpgradeNodesPopUp {
pub fn new() -> Self {
Self { active: false }
}
}

impl Default for UpgradeNodesPopUp {
fn default() -> Self {
Self::new()
pub fn new(nodes_to_start: usize) -> Self {
Self {
nodes_to_start,
active: false,
}
}
}

Expand Down Expand Up @@ -69,6 +68,10 @@ impl Component for UpgradeNodesPopUp {
None
}
},
Action::StoreNodesToStart(ref nodes_to_start) => {
self.nodes_to_start = *nodes_to_start;
None
}
_ => None,
};
Ok(send_back)
Expand Down Expand Up @@ -133,7 +136,15 @@ impl Component for UpgradeNodesPopUp {
"No data will be lost.",
Style::default().fg(LIGHT_PERIWINKLE),
)),
Line::from(Span::styled("\n\n", Style::default())),
Line::from(Span::styled(
format!(
"Upgrade time ~ {:.1?} mins ({:?} nodes * {:?} secs)",
self.nodes_to_start * (status::FIXED_INTERVAL / 1_000) as usize / 60,
self.nodes_to_start,
status::FIXED_INTERVAL / 1_000,
),
Style::default().fg(LIGHT_PERIWINKLE),
)),
Line::from(Span::styled("\n\n", Style::default())),
Line::from(vec![
Span::styled("You’ll need to ", Style::default().fg(LIGHT_PERIWINKLE)),
Expand Down
Loading

0 comments on commit c15803e

Please sign in to comment.