Add server and client build versions

This commit is contained in:
2024-09-01 14:55:51 -07:00
parent fdaff70231
commit 1f393f1c7f
17 changed files with 342 additions and 13 deletions

View File

@@ -9,6 +9,9 @@ license = "MIT"
readme = "./README.md"
edition = "2018"
[build-dependencies]
build-info-build = "0.0.38"
[dev-dependencies]
wasm-bindgen-test = "0.3.33"
@@ -29,6 +32,7 @@ thiserror = "1.0.50"
seed_hooks = { git = "https://github.com/wathiede/styles_hooks", package = "seed_hooks", branch = "main" }
gloo-net = { version = "0.4.0", features = ["json", "serde_json"] }
human_format = "1.1.0"
build-info = "0.0.38"
[package.metadata.wasm-pack.profile.release]
wasm-opt = ['-Os']

5
web/build.rs Normal file
View File

@@ -0,0 +1,5 @@
fn main() {
// Calling `build_info_build::build_script` collects all data and makes it available to `build_info::build_info!`
// and `build_info::format!` in the main program.
build_info_build::build_script();
}

View File

@@ -22,4 +22,5 @@ query FrontPageQuery($query: String!, $after: String $before: String, $first: In
fgColor
unread
}
version
}

View File

@@ -1111,6 +1111,22 @@
"description": null,
"enumValues": null,
"fields": [
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "version",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
},
{
"args": [
{

View File

@@ -64,4 +64,5 @@ query ShowThreadQuery($threadId: String!) {
fgColor
unread
}
version
}

View File

@@ -1,7 +1,7 @@
use std::collections::HashSet;
use graphql_client::GraphQLQuery;
use log::{error, info};
use log::{error, info, warn};
use seed::{prelude::*, *};
use thiserror::Error;
@@ -27,6 +27,8 @@ pub fn unread_query() -> &'static str {
// `init` describes what should happen when your app started.
pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
let version = shared::build_version(bi);
info!("Build Info: {}", version);
if url.hash().is_none() {
orders.request_url(urls::search(unread_query(), 0));
} else {
@@ -41,12 +43,17 @@ pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
compute_scroll_ratio()
}));
build_info::build_info!(fn bi);
Model {
context: Context::None,
query: "".to_string(),
refreshing_state: RefreshingState::None,
tags: None,
read_completion_ratio: 0.,
versions: Version {
client: version,
server: None,
},
}
}
@@ -335,6 +342,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
pager: data.search.page_info,
selected_threads,
};
orders.send_msg(Msg::UpdateServerVersion(data.version));
}
Msg::ShowThreadRequest { thread_id } => {
@@ -384,6 +392,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
};
}
}
orders.send_msg(Msg::UpdateServerVersion(data.version));
}
Msg::ShowThreadResult(bad) => {
error!("show_thread_query error: {bad:#?}");
@@ -507,6 +516,15 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
Msg::SetProgress(ratio) => {
model.read_completion_ratio = ratio;
}
Msg::UpdateServerVersion(version) => {
if version != model.versions.client {
warn!(
"Server ({}) and client ({}) version mismatch",
version, model.versions.client
);
}
model.versions.server = Some(version);
}
}
}
// `Model` describes our app state.
@@ -516,6 +534,13 @@ pub struct Model {
pub refreshing_state: RefreshingState,
pub tags: Option<Vec<Tag>>,
pub read_completion_ratio: f64,
pub versions: Version,
}
#[derive(Debug)]
pub struct Version {
pub client: String,
pub server: Option<String>,
}
#[derive(Error, Debug)]
@@ -612,4 +637,5 @@ pub enum Msg {
CopyToClipboard(String),
SetProgress(f64),
UpdateServerVersion(String),
}

View File

@@ -4,12 +4,11 @@ use seed_hooks::topo;
use crate::{
graphql::show_thread_query::*,
state::{Context, Model, Msg},
view::{self, reading_progress, view_header, view_search_results, view_tags},
view::{self, reading_progress, view_header, view_search_results},
};
#[topo::nested]
pub(super) fn view(model: &Model) -> Node<Msg> {
log::info!("tablet::view");
let show_icon_text = true;
// Do two queries, one without `unread` so it loads fast, then a second with unread.
let content = match &model.context {
@@ -40,7 +39,7 @@ pub(super) fn view(model: &Model) -> Node<Msg> {
div![
C!["main-content"],
reading_progress(model.read_completion_ratio),
view_tags(model),
div![view::tags(model), view::versions(&model.versions)],
div![
view_header(&model.query, &model.refreshing_state),
content,

View File

@@ -8,12 +8,11 @@ use crate::{
state::{Context, Model, Msg},
view::{
self, human_age, pretty_authors, reading_progress, search_toolbar, set_title, tags_chiclet,
view_header, view_tags,
view_header,
},
};
pub(super) fn view(model: &Model) -> Node<Msg> {
log::info!("mobile::view");
let show_icon_text = false;
let content = match &model.context {
Context::None => div![h1!["Loading"]],
@@ -45,7 +44,7 @@ pub(super) fn view(model: &Model) -> Node<Msg> {
view_header(&model.query, &model.refreshing_state),
content,
view_header(&model.query, &model.refreshing_state),
view_tags(model),
div![view::tags(model), view::versions(&model.versions)]
]
}

View File

@@ -976,7 +976,7 @@ pub fn view(model: &Model) -> Node<Msg> {
_ => div![C!["desktop"], desktop::view(model)],
},]
}
pub fn view_tags(model: &Model) -> Node<Msg> {
pub fn tags(model: &Model) -> Node<Msg> {
fn view_tag_li(display_name: &str, indent: usize, t: &Tag, search_unread: bool) -> Node<Msg> {
let href = if search_unread {
urls::search(&format!("is:unread tag:{}", t.name), 0)
@@ -1199,3 +1199,20 @@ fn reading_progress(ratio: f64) -> Node<Msg> {
format!("{percent}%")
]
}
pub fn versions(versions: &crate::state::Version) -> Node<Msg> {
info!("versions {versions:?}");
aside![
C!["tags-menu", "menu"],
p![C!["menu-label"], "Versions"],
ul![
C!["menu-list"],
li!["Client"],
li![span![C!["tag-indent"], &versions.client]]
],
versions.server.as_ref().map(|v| ul![
C!["menu-list"],
li!["Server"],
li![span![C!["tag-indent"], v]]
])
]
}

View File

@@ -3,11 +3,10 @@ use seed::{prelude::*, *};
use crate::{
graphql::show_thread_query::*,
state::{Context, Model, Msg},
view::{self, reading_progress, view_header, view_search_results, view_tags},
view::{self, reading_progress, view_header, view_search_results},
};
pub(super) fn view(model: &Model) -> Node<Msg> {
log::info!("tablet::view");
let show_icon_text = false;
// Do two queries, one without `unread` so it loads fast, then a second with unread.
let content = match &model.context {
@@ -42,7 +41,8 @@ pub(super) fn view(model: &Model) -> Node<Msg> {
view_header(&model.query, &model.refreshing_state),
content,
view_header(&model.query, &model.refreshing_state),
view_tags(model),
view::tags(model),
view::versions(&model.versions)
]
]
}