mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 01:26:04 -08:00
Cache version fetched from Github
This commit is contained in:
@@ -20,6 +20,7 @@ Released on FIXME: date
|
|||||||
|
|
||||||
- Enhancements:
|
- Enhancements:
|
||||||
- Improved performance regarding configuration I/O (config client is now shared in the activity context)
|
- Improved performance regarding configuration I/O (config client is now shared in the activity context)
|
||||||
|
- Fetch latest version from Github once; cache previous value in the Context Storage.
|
||||||
- Bugfix:
|
- Bugfix:
|
||||||
- Fixed file format cursor position in the GUI
|
- Fixed file format cursor position in the GUI
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
use super::{
|
use super::{
|
||||||
AuthActivity, Context, DialogYesNoOption, FileTransferProtocol, InputField, InputForm, Popup,
|
AuthActivity, Context, DialogYesNoOption, FileTransferProtocol, InputField, InputForm, Popup,
|
||||||
};
|
};
|
||||||
|
use crate::ui::store::Store;
|
||||||
use crate::utils::fmt::align_text_center;
|
use crate::utils::fmt::align_text_center;
|
||||||
// Ext
|
// Ext
|
||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
@@ -44,6 +45,7 @@ impl AuthActivity {
|
|||||||
/// Draw UI
|
/// Draw UI
|
||||||
pub(super) fn draw(&mut self) {
|
pub(super) fn draw(&mut self) {
|
||||||
let mut ctx: Context = self.context.take().unwrap();
|
let mut ctx: Context = self.context.take().unwrap();
|
||||||
|
let store: &Store = &ctx.store;
|
||||||
let _ = ctx.terminal.draw(|f| {
|
let _ = ctx.terminal.draw(|f| {
|
||||||
// Prepare chunks
|
// Prepare chunks
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
@@ -81,7 +83,7 @@ impl AuthActivity {
|
|||||||
.split(chunks[1]);
|
.split(chunks[1]);
|
||||||
// Draw header
|
// Draw header
|
||||||
f.render_widget(self.draw_header(), auth_chunks[0]);
|
f.render_widget(self.draw_header(), auth_chunks[0]);
|
||||||
f.render_widget(self.draw_new_version(), auth_chunks[1]);
|
f.render_widget(self.draw_new_version(store), auth_chunks[1]);
|
||||||
// Draw input fields
|
// Draw input fields
|
||||||
f.render_widget(self.draw_remote_address(), auth_chunks[2]);
|
f.render_widget(self.draw_remote_address(), auth_chunks[2]);
|
||||||
f.render_widget(self.draw_remote_port(), auth_chunks[3]);
|
f.render_widget(self.draw_remote_port(), auth_chunks[3]);
|
||||||
@@ -289,8 +291,8 @@ impl AuthActivity {
|
|||||||
/// ### draw_new_version
|
/// ### draw_new_version
|
||||||
///
|
///
|
||||||
/// Draw new version disclaimer
|
/// Draw new version disclaimer
|
||||||
fn draw_new_version(&self) -> Paragraph {
|
fn draw_new_version(&self, store: &Store) -> Paragraph {
|
||||||
let content: String = match self.new_version.as_ref() {
|
let content: String = match store.get_string(super::STORE_KEY_LATEST_VERSION) {
|
||||||
Some(ver) => format!("TermSCP {} is now available! Download it from <https://github.com/veeso/termscp/releases/latest>", ver),
|
Some(ver) => format!("TermSCP {} is now available! Download it from <https://github.com/veeso/termscp/releases/latest>", ver),
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ use tui::style::Color;
|
|||||||
// Types
|
// Types
|
||||||
type DialogCallback = fn(&mut AuthActivity);
|
type DialogCallback = fn(&mut AuthActivity);
|
||||||
|
|
||||||
|
// Store keys
|
||||||
|
const STORE_KEY_LATEST_VERSION: &str = "AUTH_LATEST_VERSION";
|
||||||
|
|
||||||
/// ### InputField
|
/// ### InputField
|
||||||
///
|
///
|
||||||
/// InputField describes the current input field to edit
|
/// InputField describes the current input field to edit
|
||||||
@@ -115,8 +118,6 @@ pub struct AuthActivity {
|
|||||||
bookmarks_list: Vec<String>, // List of bookmarks
|
bookmarks_list: Vec<String>, // List of bookmarks
|
||||||
recents_idx: usize, // Index of selected recent
|
recents_idx: usize, // Index of selected recent
|
||||||
recents_list: Vec<String>, // list of recents
|
recents_list: Vec<String>, // list of recents
|
||||||
// misc
|
|
||||||
new_version: Option<String>, // Contains new version of termscp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AuthActivity {
|
impl Default for AuthActivity {
|
||||||
@@ -152,7 +153,6 @@ impl AuthActivity {
|
|||||||
bookmarks_list: Vec::new(),
|
bookmarks_list: Vec::new(),
|
||||||
recents_idx: 0,
|
recents_idx: 0,
|
||||||
recents_list: Vec::new(),
|
recents_list: Vec::new(),
|
||||||
new_version: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,19 +160,36 @@ impl AuthActivity {
|
|||||||
///
|
///
|
||||||
/// If enabled in configuration, check for updates from Github
|
/// If enabled in configuration, check for updates from Github
|
||||||
fn check_for_updates(&mut self) {
|
fn check_for_updates(&mut self) {
|
||||||
if let Some(client) = self.context.as_ref().unwrap().config_client.as_ref() {
|
// Check version only if unset in the store
|
||||||
if client.get_check_for_updates() {
|
let ctx: &Context = self.context.as_ref().unwrap();
|
||||||
// Send request
|
if !ctx.store.isset(STORE_KEY_LATEST_VERSION) {
|
||||||
match git::check_for_updates(env!("CARGO_PKG_VERSION")) {
|
let mut new_version: Option<String> = match ctx.config_client.as_ref() {
|
||||||
Ok(version) => self.new_version = version,
|
Some(client) => {
|
||||||
Err(err) => {
|
if client.get_check_for_updates() {
|
||||||
// Report error
|
// Send request
|
||||||
self.popup = Some(Popup::Alert(
|
match git::check_for_updates(env!("CARGO_PKG_VERSION")) {
|
||||||
Color::Red,
|
Ok(version) => version,
|
||||||
format!("Could not check for new updates: {}", err),
|
Err(err) => {
|
||||||
))
|
// Report error
|
||||||
|
self.popup = Some(Popup::Alert(
|
||||||
|
Color::Red,
|
||||||
|
format!("Could not check for new updates: {}", err),
|
||||||
|
));
|
||||||
|
// None
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
let ctx: &mut Context = self.context.as_mut().unwrap();
|
||||||
|
// Set version into the store (or just a flag)
|
||||||
|
match new_version.take() {
|
||||||
|
Some(new_version) => ctx.store.set_string(STORE_KEY_LATEST_VERSION, new_version), // If Some, set String
|
||||||
|
None => ctx.store.set(STORE_KEY_LATEST_VERSION), // If None, just set flag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ use std::collections::HashMap;
|
|||||||
/// ## StoreState
|
/// ## StoreState
|
||||||
///
|
///
|
||||||
/// Store state describes a value in the store
|
/// Store state describes a value in the store
|
||||||
|
#[allow(dead_code)]
|
||||||
enum StoreState {
|
enum StoreState {
|
||||||
Str(String), // String
|
Str(String), // String
|
||||||
Signed(isize), // Signed number
|
Signed(isize), // Signed number
|
||||||
@@ -52,6 +53,7 @@ pub(crate) struct Store {
|
|||||||
store: HashMap<String, StoreState>,
|
store: HashMap<String, StoreState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
impl Store {
|
impl Store {
|
||||||
/// ### init
|
/// ### init
|
||||||
///
|
///
|
||||||
@@ -68,11 +70,8 @@ impl Store {
|
|||||||
/// Get string from store
|
/// Get string from store
|
||||||
pub fn get_string(&self, key: &str) -> Option<&str> {
|
pub fn get_string(&self, key: &str) -> Option<&str> {
|
||||||
match self.store.get(key) {
|
match self.store.get(key) {
|
||||||
None => None,
|
Some(StoreState::Str(s)) => Some(s.as_str()),
|
||||||
Some(val) => match val {
|
_ => None,
|
||||||
StoreState::Str(s) => Some(s.as_str()),
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,11 +80,8 @@ impl Store {
|
|||||||
/// Get signed from store
|
/// Get signed from store
|
||||||
pub fn get_signed(&self, key: &str) -> Option<isize> {
|
pub fn get_signed(&self, key: &str) -> Option<isize> {
|
||||||
match self.store.get(key) {
|
match self.store.get(key) {
|
||||||
None => None,
|
Some(StoreState::Signed(i)) => Some(*i),
|
||||||
Some(val) => match val {
|
_ => None,
|
||||||
StoreState::Signed(i) => Some(*i),
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,11 +90,8 @@ impl Store {
|
|||||||
/// Get unsigned from store
|
/// Get unsigned from store
|
||||||
pub fn get_unsigned(&self, key: &str) -> Option<usize> {
|
pub fn get_unsigned(&self, key: &str) -> Option<usize> {
|
||||||
match self.store.get(key) {
|
match self.store.get(key) {
|
||||||
None => None,
|
Some(StoreState::Unsigned(u)) => Some(*u),
|
||||||
Some(val) => match val {
|
_ => None,
|
||||||
StoreState::Unsigned(u) => Some(*u),
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,11 +100,8 @@ impl Store {
|
|||||||
/// get float from store
|
/// get float from store
|
||||||
pub fn get_float(&self, key: &str) -> Option<f64> {
|
pub fn get_float(&self, key: &str) -> Option<f64> {
|
||||||
match self.store.get(key) {
|
match self.store.get(key) {
|
||||||
None => None,
|
Some(StoreState::Float(f)) => Some(*f),
|
||||||
Some(val) => match val {
|
_ => None,
|
||||||
StoreState::Float(f) => Some(*f),
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,11 +110,8 @@ impl Store {
|
|||||||
/// get boolean from store
|
/// get boolean from store
|
||||||
pub fn get_boolean(&self, key: &str) -> Option<bool> {
|
pub fn get_boolean(&self, key: &str) -> Option<bool> {
|
||||||
match self.store.get(key) {
|
match self.store.get(key) {
|
||||||
None => None,
|
Some(StoreState::Boolean(b)) => Some(*b),
|
||||||
Some(val) => match val {
|
_ => None,
|
||||||
StoreState::Boolean(b) => Some(*b),
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user