Skip to content

Commit

Permalink
Merge pull request #30 from alexbarry/dev
Browse files Browse the repository at this point in the history
html: add version info to "About" popup, add logo, remove polyfill.io
  • Loading branch information
alexbarry authored Feb 1, 2025
2 parents c2bad48 + 0b54cd9 commit 66a82d9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/calc_core/calc_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ typedef val_t (*calc_func_t)(val_t, bool degree);
// TODO split into separate file, "unit_input"?
unit_t eval_units(const CalcData *calcData, std::vector<UnitInfoInput> input_units);

const char alexcalc_info[] = "\nAlexCalc created by Alex Barry ([email protected]). See https://github.com/alexbarry/AlexCalc . " ALEXCALC_BUILD_INFO;
#define ALEXCALC_HELLO_INFO ("\nAlexCalc created by Alex Barry ([email protected]). See https://github.com/alexbarry/AlexCalc . " ALEXCALC_BUILD_INFO)

const char alexcalc_hello_info[] = ALEXCALC_HELLO_INFO;
const char alexcalc_build_info[] = ALEXCALC_BUILD_INFO;

extern "C"
const char *alexcalc_info_func(void) {
return alexcalc_info;
(void)alexcalc_hello_info;
return alexcalc_build_info;
}

const char VAR_NAME_ANS[] = "ans";
Expand Down
14 changes: 13 additions & 1 deletion src/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<!--<script type="text/javascript" src="js/calc_wasm.js"></script>-->
<!--<script type="text/javascript" src="js/calc_wasm_wrapper.js"></script>-->
<!-- Needed by MathJax (I think) -->
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<!--<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>-->
<!-- For LaTeX support -->
<!--<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>-->

Expand Down Expand Up @@ -58,6 +58,12 @@
width: 100%;
}

.logo {
width: 48px;
height: 48px;
position: absolute;
}


div.main {
height: calc(100% - 2*5px);
Expand Down Expand Up @@ -359,6 +365,7 @@
<div id="output_text_window" class="output_txt_cls">
<div id="output_text">

<img class="logo" src="https://alexbarry.net/calc/favicon.png" alt="AlexCalc logo"/>
<h1>AlexCalc</h1>
<p id="wasm_loading_msg">Calc binary is loading, please wait...</p>
<p id="calc_terms_notice_small">By using this application you agree with its terms of use, available in the <a href="#" id="about_popup_link_terms_notice">about section</a>.</p>
Expand Down Expand Up @@ -640,6 +647,7 @@ <h2 style="text-align:center;margin-top:0">About AlexCalc</h2>
</p>
<p><strong>Terms of use</strong>: <span style="font-family:monospace">THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.<span><p>

<p>Version information: <span id="version_info_span">(not updated yet)</span></p>
<p><a class="licenses" href="licenses.html">Licenses</a></p>
<p><a id="close_about_popup_link" href="#">Close the "About" popup</a></p>
</div>
Expand Down Expand Up @@ -794,6 +802,10 @@ <h2 style="text-align:center;margin-top:0">About AlexCalc</h2>
ui.wasm_loaded = true;
//document.getElementById("wasm_loading_msg").innerHTML = "Calc binary ready!";
ui.generate_output_msg("Calc binary ready!", false);
alexcalc_get_info_promise().then( (info) => {
console.log("get_info_promise: ", info);
document.getElementById("version_info_span").innerText = info;
});
},

// TODO I don't like how this subtlely calls into calc_worker_wrapper.js,
Expand Down
7 changes: 7 additions & 0 deletions src/html/js/calc_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ onmessage = function(e) {
alexcalc_add_recently_used_unit(calcdata_ptr, unit_str);
let units_info = alexcalc_get_recently_used_units_json(calcdata_ptr);
send_recent_units_update(units_info.units);
} else if (data.msg_type == "get_info") {
const info_str = alexcalc_info_func();
output_data = {
msg_type: data.msg_type,
callback_key: data.callback_key,
info: info_str,
};
} else {
console.error("unhandled msg_type ", data.msg_type);
}
Expand Down
18 changes: 18 additions & 0 deletions src/html/js/calc_worker_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ function alexcalc_unit_referenced(unit_str) {
update_display_worker.postMessage({msg_type:"unit_referenced", unit_str: unit_str});
}

function alexcalc_async_get_info(callback) {
let callback_key = Date.now() + ", " + Math.random();
_calc_worker_state.callbacks[callback_key] = callback;
update_display_worker.postMessage({msg_type: "get_info", callback_key: callback_key });
}

function alexcalc_get_info_promise() {
return new Promise((resolve) => {
alexcalc_async_get_info(resolve);
});
}

update_display_worker.onmessage = function(e) {
console.debug("recvd ", e);
let data = e.data;
Expand Down Expand Up @@ -96,6 +108,12 @@ update_display_worker.onmessage = function(e) {
} else if (data.msg_type == "recently_used_units_update") {
console.debug("Updating recently used units: ", data.units);
update_recently_used_units(ui.unit_sel, data.units);
} else if (data.msg_type == "get_info") {
let callback = _calc_worker_state.callbacks[data.callback_key];
delete _calc_worker_state.callbacks[data.callback_key];
if (callback != null) {
callback(data.info);
}
} else {
console.error("unexpected msg_type: ", data.msg_type, data );
}
Expand Down

0 comments on commit 66a82d9

Please sign in to comment.