Skip to content

Commit

Permalink
Git tag and latest commit sha as version displayed in sidebar (#580)
Browse files Browse the repository at this point in the history
* Git tag and latest sha as version displayed in sidebar

* HTTP API for get/set global settings shows version number

---------

Co-authored-by: Valerian G <[email protected]>
  • Loading branch information
niamu and vgarleanu authored Nov 29, 2023
1 parent 5bf5b3b commit ff29114
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
2 changes: 2 additions & 0 deletions dim-core/src/routes/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct GlobalSettings {
pub verbose: bool,
pub secret_key: Option<[u8; 32]>,
pub enable_hwaccel: bool,
pub version: String,
}

impl Default for GlobalSettings {
Expand All @@ -54,6 +55,7 @@ impl Default for GlobalSettings {
verbose: false,
secret_key: None,
enable_hwaccel: true,
version: String::new(),
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions dim-web/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
use std::env;
use std::error::Error;
use std::path::Path;
use std::process::Command;

fn main() -> Result<(), Box<dyn Error>> {
let out_dir = env::var("CARGO_TARGET_DIR").unwrap();

let db_file = format!("{out_dir}/dim_dev.db");
println!("cargo:rustc-env=DATABASE_URL=sqlite://{db_file}");

let git_tag_output = Command::new("git").args(&["describe", "--abbrev=0"]).output().unwrap();
let git_tag = String::from_utf8(git_tag_output.stdout).unwrap();
println!("cargo:rustc-env=GIT_TAG={}", git_tag);

let git_sha_256_output = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap();
let git_sha_256 = String::from_utf8(git_sha_256_output.stdout).unwrap();
println!("cargo:rustc-env=GIT_SHA_256={}", git_sha_256);

if Path::new("../ui/build").exists() {
println!("cargo:rustc-cfg=feature=\"embed_ui\"");
} else {
Expand Down
13 changes: 12 additions & 1 deletion dim-web/src/routes/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use axum::extract::Json;
use axum::extract::State;
use axum::Extension;

use dim_core::routes::settings::{GlobalSettings, get_global_settings, set_global_settings};
use dim_core::routes::settings;
use dim_core::routes::settings::{GlobalSettings, set_global_settings};
use dim_database::DatabaseError;
use dim_database::user::UpdateableUser;
use dim_database::user::User;
Expand Down Expand Up @@ -41,6 +42,16 @@ pub async fn post_user_settings(
Ok(axum::response::Json(&new_settings).into_response())
}

fn get_global_settings() -> GlobalSettings {
let mut global_settings: GlobalSettings = settings::get_global_settings();
let git_tag = String::from(env!("GIT_TAG")).to_owned();
let mut git_sha = String::from(env!("GIT_SHA_256")).to_owned();
git_sha.truncate(8);
let version = git_tag + " " + git_sha.as_str();
global_settings.version = version;
global_settings
}

// TODO: Hide secret key.
pub async fn http_get_global_settings() -> Result<Response, AuthError> {
Ok(axum::response::Json(&get_global_settings()).into_response())
Expand Down
3 changes: 2 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"dashjs": "=4.1.0",
"fuse.js": "^6.6.2",
"jassub": "^1.7.1",
"sass": "^1.67.0",
"react": "^17.0.2",
"react-collapse": "^5.1.1",
"react-dom": "^17.0.1",
Expand All @@ -19,6 +18,7 @@
"react-scripts": "^5.0.1",
"redux": "^4.0.5",
"reselect": "^4.0.0",
"sass": "^1.67.0",
"typescript": "^4.4.4",
"web-vitals": "^1.0.1"
},
Expand All @@ -44,6 +44,7 @@
},
"license": "SEE LICENSE IN LICENSE.md",
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
Expand Down
3 changes: 2 additions & 1 deletion ui/src/Components/Sidebar/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useRef } from "react";

import { useAppDispatch } from "hooks/store";
import { fetchUserSettings } from "actions/settings.js";
import { fetchGlobalSettings, fetchUserSettings } from "actions/settings.js";
import { fetchLibraries } from "actions/library.js";

import Profile from "./Profile/Index";
Expand All @@ -20,6 +20,7 @@ function Sidebar() {
useEffect(() => {
dispatch(fetchLibraries());
dispatch(fetchUserSettings());
dispatch(fetchGlobalSettings());
}, [dispatch]);

return (
Expand Down
9 changes: 9 additions & 0 deletions ui/src/Components/Sidebar/Toggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
width: 32px;
}

.version {
display: inline-block;
vertical-align: middle;
height: 100%;
margin-left: 1rem;
color: var(--tertiaryTextColor);
font-size: 0.8em;
}

.toggle {
position: absolute;
bottom: 25%;
Expand Down
9 changes: 9 additions & 0 deletions ui/src/Components/Sidebar/Toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import React, { useCallback, useEffect, useState } from "react";
import { useSelector } from "react-redux";

import { RootState } from "../../store";

import DimLogo from "assets/DimLogo";
import AngleLeftIcon from "assets/Icons/AngleLeft";
Expand All @@ -13,6 +16,11 @@ function Toggle(props: Props) {
const [defaultChecked, setDefaultChecked] = useState(false);
const [visible, setVisible] = useState(true);

const version = useSelector((store: RootState) => {
const { data } = store.settings.globalSettings;
return data.version;
});

/*
disabling animation is mainly intended for on-load layout prep changes
e.g. hiding sidebar by default if not enough space detected.
Expand Down Expand Up @@ -83,6 +91,7 @@ function Toggle(props: Props) {
return (
<section className="sidebarToggleWrapper">
<DimLogo />
<span className="version">{version}</span>
<div className="toggle" onClick={toggleSidebar}>
<AngleLeftIcon />
</div>
Expand Down

0 comments on commit ff29114

Please sign in to comment.