From ea3c0724cc1fb6a51e4e8af9500f1d3457ac82e1 Mon Sep 17 00:00:00 2001
From: nepx <23300488+nepx@users.noreply.github.com>
Date: Thu, 24 Dec 2020 22:14:10 -0800
Subject: [PATCH] Add network status progress bar.
It's a bit ugly, but it works
---
index.html | 23 ++++++++++++++++++++++-
libhalfix.js | 13 ++++++++-----
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/index.html b/index.html
index 10c1f82..c6737fc 100644
--- a/index.html
+++ b/index.html
@@ -8,6 +8,17 @@
+
@@ -122,6 +133,9 @@
+
@@ -301,7 +315,7 @@ Other Settings
If checked, the emulator runs as fast as possible, causing time to become desynchronized.
-
+
@@ -374,6 +388,13 @@
Other Settings
opts.floppy = $("#inp_floppy")[0].checked;
opts.winnt_hack = getParameterByName("winnt") ? true : $("#inp_winnt")[0].checked;
+ var pbt = $("#pbt"),
+ pb = $("#pb")[0];
+ opts.onprogress = function(file, cur, tot) {
+ pbt.html(file);
+ pb.setAttribute("value", (cur / tot * 100) | 0);
+ };
+
var letters = ["a", "b", "c", "d"];
for (var i = 0; i < 4; i++) {
if (diskinfos[i].type !== "none") {
diff --git a/libhalfix.js b/libhalfix.js
index 35bade2..4a719ed 100644
--- a/libhalfix.js
+++ b/libhalfix.js
@@ -23,6 +23,8 @@
this.image_data = null;
this.config = this.buildConfiguration();
+
+ this.onprogress = options["onprogress"] || function (a, b, c) { };
}
var _cache = [];
@@ -108,10 +110,12 @@
};
/**
- * @param {number} progress Fraction of completion * 100
+ * @param {string} f name of file
+ * @param {number} a current position
+ * @param {number} b end
*/
- Halfix.prototype.updateNetworkProgress = function (progress) {
-
+ Halfix.prototype.updateNetworkProgress = function (f, a, b) {
+ this.onprogress(f, a, b);
};
/**
* @param {number} total Total bytes loaded
@@ -227,8 +231,7 @@
xhr.onprogress = function (e) {
if (e.lengthComputable) {
- var now = e.loaded / e.total * 100 | 0;
- _halfix.updateNetworkProgress(now - lastProgress | 0);
+ _halfix.updateNetworkProgress(path, e.loaded, e.total);
lastProgress = now;
}
};