improved git commit fetching
This commit is contained in:
parent
6f8a7c9cc2
commit
ee2936dfc4
@ -18,6 +18,7 @@ meval = { git = "https://github.com/Titaniumtown/meval-rs.git" }
|
||||
egui = "0.17.0"
|
||||
eframe = "0.17.0"
|
||||
instant = { version = "0.1.12", features = ["wasm-bindgen"] }
|
||||
git-version = "0.3.5"
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
console_error_panic_hook = "0.1.7"
|
||||
|
||||
10
build.sh
10
build.sh
@ -10,12 +10,4 @@ mkdir tmp tmp/pkg
|
||||
cp -r pkg/integral_site_bg.wasm pkg/integral_site.js tmp/pkg/
|
||||
cp www/index.html www/style.css tmp/
|
||||
|
||||
sed -i 's/\.\.\/pkg/\.\/pkg/g' tmp/index.html
|
||||
|
||||
git ls-files --exclude-standard --others . >/dev/null 2>&1; ec=$?
|
||||
if test "$ec" = 0; then
|
||||
echo some untracked files
|
||||
elif test "$ec" = 1; then
|
||||
commit=$(git rev-parse HEAD)
|
||||
sed -i "s/let commit = ''/let commit = '${commit}'/g" tmp/index.html
|
||||
fi
|
||||
sed -i 's/\.\.\/pkg/\.\/pkg/g' tmp/index.html
|
||||
@ -5,7 +5,11 @@ use crate::misc::{digits_precision, test_func, Cache};
|
||||
use eframe::{egui, epi};
|
||||
use egui::plot::{Line, Plot, Value, Values};
|
||||
use egui::widgets::plot::{Bar, BarChart};
|
||||
use egui::{Color32, TextStyle, Vec2, Layout};
|
||||
use egui::Color32;
|
||||
use git_version::git_version;
|
||||
|
||||
// Grabs git version on compile time
|
||||
const GIT_VERSION: &str = git_version!();
|
||||
|
||||
pub struct MathApp {
|
||||
func_str: String,
|
||||
@ -16,11 +20,10 @@ pub struct MathApp {
|
||||
chart_manager: ChartManager,
|
||||
back_cache: Cache<Vec<Value>>,
|
||||
front_cache: Cache<(Vec<Bar>, f64)>,
|
||||
commit: String
|
||||
}
|
||||
|
||||
impl MathApp {
|
||||
pub fn new(commit: String) -> Self {
|
||||
impl Default for MathApp {
|
||||
fn default() -> Self {
|
||||
let def_func = "x^2".to_string();
|
||||
let def_min_x = -10.0;
|
||||
let def_max_x = 10.0;
|
||||
@ -35,11 +38,12 @@ impl MathApp {
|
||||
resolution: def_resolution,
|
||||
chart_manager: ChartManager::new(def_func, def_min_x, def_max_x, def_interval, def_resolution),
|
||||
back_cache: Cache::new_empty(),
|
||||
front_cache: Cache::new_empty(),
|
||||
commit
|
||||
front_cache: Cache::new_empty()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MathApp {
|
||||
#[inline]
|
||||
fn get_back(&mut self) -> Line {
|
||||
let data = if self.back_cache.is_valid() {
|
||||
@ -101,8 +105,7 @@ impl epi::App for MathApp {
|
||||
resolution,
|
||||
chart_manager,
|
||||
back_cache,
|
||||
front_cache,
|
||||
commit,
|
||||
front_cache
|
||||
} = self;
|
||||
|
||||
// Note: This Instant implementation does not show microseconds when using wasm.
|
||||
@ -155,14 +158,18 @@ impl epi::App for MathApp {
|
||||
"I'm Opensource! (and licensed under AGPLv3)",
|
||||
"https://github.com/Titaniumtown/integral_site",
|
||||
);
|
||||
|
||||
// Displays commit info
|
||||
ui.horizontal(|ui| {
|
||||
ui.with_layout(egui::Layout::top_down_justified(egui::Align::Min), |ui| {
|
||||
if commit.is_empty() {
|
||||
ui.label(format!("Current build is untracked!"));
|
||||
} else {
|
||||
ui.label("Commit: ");
|
||||
ui.hyperlink_to(commit.clone(), format!("https://github.com/Titaniumtown/integral_site/commit/{}", commit));
|
||||
}
|
||||
|
||||
// Only include hyperlink if the build doesn't have untracked files
|
||||
if !GIT_VERSION.contains("-modified") {
|
||||
ui.hyperlink_to(GIT_VERSION, format!("https://github.com/Titaniumtown/integral_site/commit/{}", GIT_VERSION));
|
||||
} else {
|
||||
ui.label(GIT_VERSION);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -170,6 +177,7 @@ impl epi::App for MathApp {
|
||||
if parse_error.is_empty() {
|
||||
let do_update = chart_manager.update(func_str.clone(), *min_x, *max_x, *num_interval, *resolution);
|
||||
|
||||
// Invalidates caches according to what settings were changed
|
||||
match do_update {
|
||||
UpdateType::Full => {
|
||||
back_cache.invalidate();
|
||||
|
||||
@ -23,7 +23,7 @@ extern "C" {
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[wasm_bindgen]
|
||||
pub fn start(canvas_id: &str, commit: &str) -> Result<(), wasm_bindgen::JsValue> {
|
||||
pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
|
||||
log("Initializing...");
|
||||
|
||||
// See performance in browser profiler!
|
||||
@ -39,6 +39,6 @@ pub fn start(canvas_id: &str, commit: &str) -> Result<(), wasm_bindgen::JsValue>
|
||||
log("Finished initializing!");
|
||||
|
||||
log("Starting App...");
|
||||
let app = egui_app::MathApp::new(commit.to_string());
|
||||
let app = egui_app::MathApp::default();
|
||||
eframe::start_web(canvas_id, Box::new(app))
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ mod misc;
|
||||
// For running the program natively! (Because why not?)
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn main() {
|
||||
let app = egui_app::MathApp::new("".to_string());
|
||||
let app = egui_app::MathApp::default();
|
||||
let options = eframe::NativeOptions {
|
||||
// Let's show off that we support transparent windows
|
||||
transparent: true,
|
||||
|
||||
@ -18,9 +18,7 @@
|
||||
|
||||
async function run() {
|
||||
await init();
|
||||
|
||||
let commit = '';
|
||||
start("canvas", commit);
|
||||
start("canvas");
|
||||
}
|
||||
run();
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user