android: show sync progress at notification, prevent app to sleep, temp fix of hanging after closing from recent apps

This commit is contained in:
ardocrat
2023-05-23 01:46:42 +03:00
parent f05d930f60
commit 22c5b945c6
20 changed files with 426 additions and 234 deletions
+3 -3
View File
@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use eframe::epaint::{Color32, Stroke};
mod views;
pub use self::views::View;
@@ -24,11 +22,13 @@ mod network;
mod network_node;
mod network_tuning;
mod network_metrics;
mod network_mining;
pub use self::network::Network;
pub trait NetworkTab {
fn name(&self) -> &String;
fn ui(&mut self, ui: &mut egui::Ui, node: &mut crate::node::Node);
fn ui(&mut self, ui: &mut egui::Ui);
}
+8 -91
View File
@@ -42,8 +42,6 @@ enum Mode {
}
pub struct Network {
node: Node,
current_mode: Mode,
node_view: NetworkNode,
@@ -52,9 +50,8 @@ pub struct Network {
impl Default for Network {
fn default() -> Self {
let node = Node::new(ChainTypes::Mainnet, true);
Node::start(ChainTypes::Mainnet);
Self {
node,
current_mode: Mode::Node,
node_view: NetworkNode::default(),
metrics_view: NetworkMetrics::default()
@@ -67,7 +64,7 @@ impl Network {
ui: &mut egui::Ui,
frame: &mut eframe::Frame,
nav: &mut Navigator,
cb: &dyn PlatformCallbacks) {
_: &dyn PlatformCallbacks) {
egui::TopBottomPanel::top("network_title")
.resizable(false)
@@ -136,13 +133,13 @@ impl Network {
fn draw_tab_content(&mut self, ui: &mut egui::Ui) {
match self.current_mode {
Mode::Node => {
self.node_view.ui(ui, &mut self.node);
self.node_view.ui(ui);
}
Mode::Metrics => {
self.metrics_view.ui(ui, &mut self.node);
self.metrics_view.ui(ui);
}
Mode::Tuning => {
self.node_view.ui(ui, &mut self.node);
self.node_view.ui(ui);
}
Mode::Miner => {}
}
@@ -215,23 +212,12 @@ impl Network {
strip.cell(|ui| {
ui.centered_and_justified(|ui| {
// Select sync status text
let sync_status = self.node.state.get_sync_status();
let status_text = if self.node.state.is_restarting() {
t!("server_restarting")
} else {
match sync_status {
None => {
t!("server_down")
}
Some(ss) => {
get_sync_status_text(ss).to_string()
}
}
};
let sync_status = Node::get_sync_status();
let status_text = Node::get_sync_status_text(sync_status);
// Setup text color animation based on sync status
let idle = match sync_status {
None => { !self.node.state.is_starting() }
None => { !Node::is_starting() }
Some(ss) => { ss == SyncStatus::NoSync }
};
let (dark, bright) = (0.3, 1.0);
@@ -267,72 +253,3 @@ impl Network {
}
}
fn get_sync_status_text(sync_status: SyncStatus) -> String {
match sync_status {
SyncStatus::Initial => t!("sync_status.initial"),
SyncStatus::NoSync => t!("sync_status.no_sync"),
SyncStatus::AwaitingPeers(_) => t!("sync_status.awaiting_peers"),
SyncStatus::HeaderSync {
sync_head,
highest_height,
..
} => {
if highest_height == 0 {
t!("sync_status.header_sync")
} else {
let percent = sync_head.height * 100 / highest_height;
t!("sync_status.header_sync_percent", "percent" => percent)
}
}
SyncStatus::TxHashsetDownload(stat) => {
if stat.total_size > 0 {
let percent = stat.downloaded_size * 100 / stat.total_size;
t!("sync_status.tx_hashset_download_percent", "percent" => percent)
} else {
t!("sync_status.tx_hashset_download")
}
}
SyncStatus::TxHashsetSetup => {
t!("sync_status.tx_hashset_setup")
}
SyncStatus::TxHashsetRangeProofsValidation {
rproofs,
rproofs_total,
} => {
let r_percent = if rproofs_total > 0 {
(rproofs * 100) / rproofs_total
} else {
0
};
t!("sync_status.tx_hashset_range_proofs_validation", "percent" => r_percent)
}
SyncStatus::TxHashsetKernelsValidation {
kernels,
kernels_total,
} => {
let k_percent = if kernels_total > 0 {
(kernels * 100) / kernels_total
} else {
0
};
t!("sync_status.tx_hashset_kernels_validation", "percent" => k_percent)
}
SyncStatus::TxHashsetSave | SyncStatus::TxHashsetDone => {
t!("sync_status.tx_hashset_save")
}
SyncStatus::BodySync {
current_height,
highest_height,
} => {
if highest_height == 0 {
t!("sync_status.body_sync")
} else {
let percent = current_height * 100 / highest_height;
t!("sync_status.body_sync_percent", "percent" => percent)
}
}
SyncStatus::Shutdown => t!("sync_status.shutdown"),
}
}
+29 -25
View File
@@ -18,7 +18,7 @@ use egui::{RichText, ScrollArea, Spinner, Widget};
use grin_servers::DiffBlock;
use crate::gui::colors::{COLOR_DARK, COLOR_GRAY, COLOR_GRAY_LIGHT};
use crate::gui::icons::{AT, CALENDAR_PLUS, COINS, CUBE, CUBE_TRANSPARENT, HASH, HOURGLASS_LOW, HOURGLASS_MEDIUM, TIMER};
use crate::gui::icons::{AT, COINS, CUBE_TRANSPARENT, HASH, HOURGLASS_LOW, HOURGLASS_MEDIUM, TIMER};
use crate::gui::views::{NetworkTab, View};
use crate::node::Node;
@@ -43,8 +43,8 @@ impl NetworkTab for NetworkMetrics {
&self.title
}
fn ui(&mut self, ui: &mut egui::Ui, node: &mut Node) {
let server_stats = node.state.get_stats();
fn ui(&mut self, ui: &mut egui::Ui) {
let server_stats = Node::get_stats();
// Show loading widget if server is not working or difficulty height is zero.
if !server_stats.is_some() || server_stats.as_ref().unwrap().diff_stats.height == 0 {
ui.centered_and_justified(|ui| {
@@ -86,7 +86,7 @@ impl NetworkTab for NetworkMetrics {
});
ui.add_space(6.0);
// Show difficulty window info
// Show difficulty adjustment window info
ui.vertical_centered_justified(|ui| {
let title = t!("difficulty_at_window", "size" => stats.diff_stats.window_size);
View::sub_title(ui, format!("{} {}", HOURGLASS_MEDIUM, title));
@@ -114,28 +114,32 @@ impl NetworkTab for NetworkMetrics {
});
ui.add_space(6.0);
// Draw difficulty window blocks
// Show difficulty adjustment window blocks
let blocks_size = stats.diff_stats.last_blocks.len();
ScrollArea::vertical().auto_shrink([false; 2]).stick_to_bottom(true).show_rows(
ui,
DIFF_BLOCK_UI_HEIGHT,
blocks_size,
|ui, row_range| {
for index in row_range {
let db = stats.diff_stats.last_blocks.get(index).unwrap();
let rounding = if blocks_size == 1 {
[true, true]
} else if index == 0 {
[true, false]
} else if index == blocks_size - 1 {
[false, true]
} else {
[false, false]
};
draw_diff_block(ui, db, rounding)
}
},
);
ScrollArea::vertical()
.auto_shrink([false; 2])
.stick_to_bottom(true)
.id_source("diff_scroll")
.show_rows(
ui,
DIFF_BLOCK_UI_HEIGHT,
blocks_size,
|ui, row_range| {
for index in row_range {
let db = stats.diff_stats.last_blocks.get(index).unwrap();
let rounding = if blocks_size == 1 {
[true, true]
} else if index == 0 {
[true, false]
} else if index == blocks_size - 1 {
[false, true]
} else {
[false, false]
};
draw_diff_block(ui, db, rounding)
}
},
);
}
}
+13
View File
@@ -0,0 +1,13 @@
// Copyright 2023 The Grim Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
+8 -11
View File
@@ -14,7 +14,6 @@
use eframe::epaint::Stroke;
use egui::{Color32, RichText, Rounding, ScrollArea, Spinner, Widget};
use grin_servers::common::stats::TxStats;
use grin_servers::PeerStats;
use crate::gui::colors::{COLOR_DARK, COLOR_GRAY, COLOR_GRAY_LIGHT};
@@ -39,8 +38,8 @@ impl NetworkTab for NetworkNode {
&self.title
}
fn ui(&mut self, ui: &mut egui::Ui, node: &mut Node) {
let server_stats = node.state.get_stats();
fn ui(&mut self, ui: &mut egui::Ui) {
let server_stats = Node::get_stats();
if !server_stats.is_some() {
ui.centered_and_justified(|ui| {
Spinner::new().size(42.0).color(COLOR_GRAY).ui(ui);
@@ -80,9 +79,9 @@ impl NetworkTab for NetworkNode {
[false, false, true, false]);
});
columns[1].vertical_centered(|ui| {
let ts = stats.header_stats.latest_timestamp;
let h_ts = stats.header_stats.latest_timestamp;
View::rounded_box(ui,
format!("{}", ts.format("%d/%m/%Y %H:%M")),
format!("{}", h_ts.format("%d/%m/%Y %H:%M")),
t!("time_utc"),
[false, false, false, true]);
});
@@ -116,9 +115,9 @@ impl NetworkTab for NetworkNode {
[false, false, true, false]);
});
columns[1].vertical_centered(|ui| {
let ts = stats.chain_stats.latest_timestamp;
let b_ts = stats.chain_stats.latest_timestamp;
View::rounded_box(ui,
format!("{}", ts.format("%d/%m/%Y %H:%M")),
format!("{}", b_ts.format("%d/%m/%Y %H:%M")),
t!("time_utc"),
[false, false, false, true]);
});
@@ -265,9 +264,7 @@ fn draw_peer_stats(ui: &mut egui::Ui, peer: &PeerStats, rounding: [bool; 2]) {
});
// Add space after last item
if !rounding[0] && rounding[1] {
ui.add_space(5.0);
} else if rounding[0] && rounding[1] {
ui.add_space(2.0);
if rounding[1] {
ui.add_space(3.0);
}
}