Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved exit ui to modal. #9

Merged
merged 8 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 16 additions & 14 deletions crates/core/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ impl<'a> Controller<'a> {
}

/// Run the controller
pub fn run(&mut self, server: Server) {
pub fn run(&mut self, server: Server, chain_type: global::ChainTypes) {
let stat_update_interval = 1;
let mut next_stat_update = Utc::now().timestamp() + stat_update_interval;
let delay = Duration::from_millis(50);

warn!("Running...");
warn!("Running {:?}", chain_type);

loop {
if let Some(message) = self.controller_rx.try_iter().next() {
match message {
ControllerMessage::Shutdown => {
warn!("Shutdown in progress, please wait");
//self.ui.stop();
warn!("Shutdown {:?} in progress, please wait", chain_type);
// TODO this may hang on some errors
server.stop();
return;
}
Expand All @@ -152,7 +152,6 @@ impl<'a> Controller<'a> {
}
thread::sleep(delay);
}

}
}

Expand Down Expand Up @@ -216,21 +215,24 @@ impl NodeInterface {
GlobalConfig::new(config_path.to_str().unwrap()).unwrap()
}

pub fn shutdown_server(&mut self) {
pub fn shutdown_server(&mut self, join: bool) {
if let Some(handle) = self.handle.take() {
if !handle.is_finished() {
self.controller_tx.clone().unwrap().send(ControllerMessage::Shutdown);
self.controller_tx
.clone()
.unwrap()
.send(ControllerMessage::Shutdown);

if join {
handle.join().expect("could not join spawned thread");
}

self.node_started = false;
self.controller_tx = None;
}
}

pub fn restart_server(&mut self, chain_type: global::ChainTypes) {
if let Some(tx) = self.controller_tx.clone() {
tx.send(ControllerMessage::Shutdown);
self.node_started = true;
self.controller_tx = None;
}
self.shutdown_server(false);
self.start_server(chain_type);
}

Expand Down Expand Up @@ -310,7 +312,7 @@ impl NodeInterface {
|serv: servers::Server, logs_rx: Option<mpsc::Receiver<LogEntry>>| {
let mut controller =
Controller::new(logs_rx.unwrap(), ui_sender.clone(), &controller_rx);
controller.run(serv);
controller.run(serv, chain_type);
},
None,
api_chan,
Expand Down
5 changes: 3 additions & 2 deletions locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@
"status-line-title-main": "Status Mainnet",
"status-line-title-test": "Status Testnet",
"use-testnet": "This is a testnet wallet",
"exit-confirm-title": "Yes, exit now",
"exit-confirm-msg": "Are you sure you want to exit?",
"exit-confirm-title": "Quit application",
"exit-confirm-msg": "Are you sure you want to quit the application? This will shutdown any nodes that you have running.",
"yes": "Yes",
"no": "No",
"cancel":"Cancel"
}
5 changes: 3 additions & 2 deletions locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,14 @@
"status-line-title-test": "Status Testnet",
"wallet-list": "Wallets",
"yes": "Yes",
"no": "No",
"cancel":"Cancel",
"display-name":"Display Name",
"top-level-domain":"Wallet Directory",
"select-directory":"Choose Folder",
"load-wallet":"Load Wallet",
"select-other":"Locate Wallet",
"use-testnet": "This is a testnet wallet",
"exit-confirm-title": "Yes, exit now",
"exit-confirm-msg": "Are you sure you want to exit?"
"exit-confirm-title": "Quit application",
"exit-confirm-msg": "Are you sure you want to quit the application? This will shutdown any nodes that you have running."
}
84 changes: 0 additions & 84 deletions src/gui/element/exit.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/gui/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod about;
pub mod settings;
pub mod wallet;
pub mod node;
pub mod exit;
pub mod modal;

// Default values used on multiple elements.
pub static SMALLER_FONT_SIZE: u16 = 12;
Expand Down
121 changes: 121 additions & 0 deletions src/gui/element/modal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use iced::Renderer;

use {
super::super::{DEFAULT_FONT_SIZE, DEFAULT_HEADER_FONT_SIZE, SMALLER_FONT_SIZE},
crate::gui::{style, Interaction, Message},
crate::localization::localized_string,
grin_gui_core::theme::ColorPalette,
iced::{
alignment, button, Alignment, Button, Column, Container, Element, Length, Row, Space, Text,
},
iced_aw::{modal, native::card::Card, Modal},
};

pub struct StateContainer {
ok_state: button::State,
cancel_state: button::State,
}

impl Default for StateContainer {
fn default() -> Self {
Self {
ok_state: Default::default(),
cancel_state: Default::default(),
}
}
}

pub fn exit_card<'a>(
color_palette: ColorPalette,
state: &'a mut StateContainer,
) -> Card<Message, Renderer> {
let yes_button_label =
Container::new(Text::new(localized_string("yes")).size(DEFAULT_FONT_SIZE))
.center_x()
.align_x(alignment::Horizontal::Center);

let cancel_button_label =
Container::new(Text::new(localized_string("no")).size(DEFAULT_FONT_SIZE))
.center_x()
.align_x(alignment::Horizontal::Center);

let yes_button: Element<Interaction> =
Button::new(&mut state.ok_state, yes_button_label)
.style(style::DefaultBoxedButton(color_palette))
.on_press(Interaction::Exit)
.into();

let cancel_button: Element<Interaction> =
Button::new(&mut state.cancel_state, cancel_button_label)
.style(style::DefaultBoxedButton(color_palette))
.on_press(Interaction::ExitCancel)
.into();

let unit_spacing = 15;

let button_row = Row::new()
.push(yes_button.map(Message::Interaction))
.push(Space::new(Length::Units(unit_spacing), Length::Units(0)))
.push(cancel_button.map(Message::Interaction));

Card::new(
Text::new(localized_string("exit-confirm-title"))
.size(DEFAULT_HEADER_FONT_SIZE)
.horizontal_alignment(alignment::Horizontal::Center),
Text::new(localized_string("exit-confirm-msg")).size(DEFAULT_FONT_SIZE),
)
.foot(
Column::new()
.spacing(10)
.padding(5)
.width(Length::Fill)
.align_items(Alignment::Center)
.push(button_row),
)
.max_width(500)
.on_close(Message::Interaction(Interaction::CloseErrorModal))
.style(style::NormalModalCardContainer(color_palette))
}

pub fn error_card<'a>(
color_palette: ColorPalette,
state: &'a mut StateContainer,
error_cause: String,
) -> Card<Message, Renderer> {
Card::new(
Text::new(localized_string("error-detail")).size(DEFAULT_HEADER_FONT_SIZE),
Text::new(error_cause.clone()).size(DEFAULT_FONT_SIZE),
)
.foot(
Column::new()
.spacing(10)
.padding(5)
.width(Length::Fill)
.align_items(Alignment::Center)
.push(
Button::new(
&mut state.cancel_state,
Text::new(localized_string("ok-caps"))
.size(DEFAULT_FONT_SIZE)
.horizontal_alignment(alignment::Horizontal::Center),
)
.style(style::DefaultButton(color_palette))
.on_press(Message::Interaction(Interaction::CloseErrorModal)),
)
.push(
Button::new(
&mut state.ok_state,
Text::new(localized_string("copy-to-clipboard"))
.size(SMALLER_FONT_SIZE)
.horizontal_alignment(alignment::Horizontal::Center),
)
.style(style::NormalTextButton(color_palette))
.on_press(Message::Interaction(Interaction::WriteToClipboard(
error_cause,
))),
),
)
.max_width(500)
.on_close(Message::Interaction(Interaction::CloseErrorModal))
.style(style::NormalModalCardContainer(color_palette))
}