diff --git a/build.sh b/build.sh index 4eae769..5716e8d 100755 --- a/build.sh +++ b/build.sh @@ -4,3 +4,18 @@ wasm-pack build --target web --release --no-typescript wasm-opt -Oz -o pkg/integral_site_bg_2.wasm pkg/integral_site_bg.wasm mv pkg/integral_site_bg_2.wasm pkg/integral_site_bg.wasm llvm-strip --strip-all pkg/integral_site_bg.wasm + +rm -fr tmp | true #delete tmp folder if exists +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 diff --git a/push.sh b/push.sh index e175411..7fc650a 100755 --- a/push.sh +++ b/push.sh @@ -3,20 +3,6 @@ set -e #kill script if error occurs bash build.sh -rm -fr tmp | true #delete tmp folder if exists -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 - -# put the commit at the beginning of index.html -mv tmp/index.html tmp/index.html.bak -commit_comment="" -echo $commit_comment > tmp/index.html -cat tmp/index.html.bak >> tmp/index.html -rm -fr tmp/index.html.bak - echo "rsyncing" rsync -av --delete --info=progress2 tmp/ rpi-public:/mnt/hdd/http_share/integral-demo/ rsync -av --delete --info=progress2 --exclude=".git" tmp/ ../integral-demo/ diff --git a/src/egui_app.rs b/src/egui_app.rs index 18a01c7..a4b9417 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -5,7 +5,7 @@ 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; +use egui::{Color32, TextStyle, Vec2, Layout}; pub struct MathApp { func_str: String, @@ -16,10 +16,11 @@ pub struct MathApp { chart_manager: ChartManager, back_cache: Cache>, front_cache: Cache<(Vec, f64)>, + commit: String } -impl Default for MathApp { - fn default() -> Self { +impl MathApp { + pub fn new(commit: String) -> Self { let def_func = "x^2".to_string(); let def_min_x = -10.0; let def_max_x = 10.0; @@ -35,11 +36,10 @@ impl Default for MathApp { 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 } } -} -impl MathApp { #[inline] fn get_back(&mut self) -> Line { let data = if self.back_cache.is_valid() { @@ -102,15 +102,25 @@ impl epi::App for MathApp { chart_manager, back_cache, front_cache, + commit, } = self; // Note: This Instant implementation does not show microseconds when using wasm. let start = instant::Instant::now(); - + // Cute little window that lists supported functions! + // TODO: add more detail + egui::Window::new("Supported Functions").show(ctx, |ui| { + ui.label("- sqrt, abs"); + ui.label("- exp, ln, log10 (log10 can also be called as log)"); + ui.label("- sin, cos, tan, asin, acos, atan, atan2"); + ui.label("- sinh, cosh, tanh, asinh, acosh, atanh"); + ui.label("- floor, ceil, round"); + ui.label("- signum, min, max"); + }); let mut parse_error: String = "".to_string(); - egui::SidePanel::left("side_panel").show(ctx, |ui| { + egui::SidePanel::left("side_panel").resizable(false).show(ctx, |ui| { ui.heading("Side Panel"); ui.horizontal(|ui| { @@ -140,11 +150,21 @@ impl epi::App for MathApp { } ui.add(egui::Slider::new(num_interval, NUM_INTERVAL_RANGE).text("Interval")); - + // ui.add_space(ui.text_style_height(&TextStyle::Body)*10.0); ui.hyperlink_to( "I'm Opensource! (and licensed under AGPLv3)", "https://github.com/Titaniumtown/integral_site", ); + 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)); + } + }); + }); }); if parse_error.is_empty() { @@ -189,16 +209,5 @@ impl epi::App for MathApp { duration )); }); - - // Cute little window that lists supported functions! - // TODO: add more detail - egui::Window::new("Supported Functions").show(ctx, |ui| { - ui.label("- sqrt, abs"); - ui.label("- exp, ln, log10 (log10 can also be called as log)"); - ui.label("- sin, cos, tan, asin, acos, atan, atan2"); - ui.label("- sinh, cosh, tanh, asinh, acosh, atanh"); - ui.label("- floor, ceil, round"); - ui.label("- signum, min, max"); - }); } } diff --git a/src/lib.rs b/src/lib.rs index c876304..52a748e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,7 @@ extern "C" { #[cfg(target_arch = "wasm32")] #[wasm_bindgen] -pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> { +pub fn start(canvas_id: &str, commit: &str) -> Result<(), wasm_bindgen::JsValue> { log("Initializing..."); // See performance in browser profiler! @@ -39,6 +39,6 @@ pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> { log("Finished initializing!"); log("Starting App..."); - let app = egui_app::MathApp::default(); + let app = egui_app::MathApp::new(commit.to_string()); eframe::start_web(canvas_id, Box::new(app)) } diff --git a/src/main.rs b/src/main.rs index 96df7d7..ce84c56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::default(); + let app = egui_app::MathApp::new("".to_string()); let options = eframe::NativeOptions { // Let's show off that we support transparent windows transparent: true, diff --git a/start-server.sh b/start-server.sh index 6c1a949..9f7758e 100755 --- a/start-server.sh +++ b/start-server.sh @@ -3,13 +3,4 @@ set -e bash build.sh -rustup target add wasm32-unknown-unknown - -if [ -z "$(cargo install --list | grep wasm-pack)" ] -then - cargo install wasm-pack -fi - -wasm-pack build --release --target web --no-typescript - -basic-http-server \ No newline at end of file +basic-http-server tmp/ \ No newline at end of file diff --git a/www/index.html b/www/index.html index 46a90c4..3e30a60 100644 --- a/www/index.html +++ b/www/index.html @@ -5,7 +5,6 @@ - Integral Demonstration @@ -18,9 +17,10 @@ import init, { start } from '../pkg/integral_site.js'; async function run() { - await init(); - - start("canvas"); + await init(); + + let commit = ''; + start("canvas", commit); } run();