Skip to content

Commit

Permalink
Git tag and latest sha as version displayed in sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
niamu committed Nov 21, 2023
1 parent 9cc3704 commit 6e9ec0e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
10 changes: 10 additions & 0 deletions dim-core/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;
use std::path::Path;
use std::process::Command;

fn main() {
let out_dir = env::var("CARGO_TARGET_DIR").unwrap();
Expand All @@ -14,5 +15,14 @@ fn main() {
}

println!("cargo:rerun-if-changed=ui/build");

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);

println!("cargo:rerun-if-changed=build.rs");
}
6 changes: 6 additions & 0 deletions dim-core/src/routes/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ pub struct GlobalSettings {
pub verbose: bool,
pub secret_key: Option<[u8; 32]>,
pub enable_hwaccel: bool,
pub version: String,
}

impl Default for GlobalSettings {
fn default() -> Self {
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();
Self {
enable_ssl: false,
port: 8000,
Expand All @@ -61,6 +66,7 @@ impl Default for GlobalSettings {
verbose: false,
secret_key: None,
enable_hwaccel: true,
version: version.into(),
}
}
}
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 6e9ec0e

Please sign in to comment.