From 34416c07fe7113079ed374dbc117c24f6e0f3a96 Mon Sep 17 00:00:00 2001 From: Kevin Date: Sun, 21 Jun 2020 02:27:55 -0500 Subject: [PATCH] made particles more efficient, finished basic blocks feed --- src/httpapi/sse/private/__init__.py | 9 +++- static-data/default_config.json | 1 + static-data/www/private/index.html | 64 ++++++++++++++++-------- static-data/www/shared/main/apicheck.js | 3 ++ static-data/www/shared/main/particles.js | 14 +++++- static-data/www/shared/main/recent.js | 57 ++++++++++++++++++--- static-data/www/shared/main/stats.js | 20 ++++++-- static-data/www/shared/main/torstats.js | 2 +- 8 files changed, 132 insertions(+), 38 deletions(-) diff --git a/src/httpapi/sse/private/__init__.py b/src/httpapi/sse/private/__init__.py index b0088dea..4213fd4f 100644 --- a/src/httpapi/sse/private/__init__.py +++ b/src/httpapi/sse/private/__init__.py @@ -57,9 +57,14 @@ def stream_tor_circuits(): def stream_recent_blocks(): def _compile_json(b_list): js = {} + block_obj = None for block in b_list: - js[block] = Block(block).btype - return ujson.dumps(js, reject_bytes=True) + block_obj = Block(block) + if block_obj.isEncrypted: + js[block] = 'encrypted' + else: + js[block] = Block(block).btype + return ujson.dumps({"blocks": js}, reject_bytes=True) def _stream_recent(): last_time = Path(block_meta_db).stat().st_ctime diff --git a/static-data/default_config.json b/static-data/default_config.json index 4845e67a..1aba4f7c 100755 --- a/static-data/default_config.json +++ b/static-data/default_config.json @@ -71,6 +71,7 @@ "tor": true }, "ui": { + "animated_background": true, "theme": "dark" } } \ No newline at end of file diff --git a/static-data/www/private/index.html b/static-data/www/private/index.html index 24745ba1..9ea73331 100755 --- a/static-data/www/private/index.html +++ b/static-data/www/private/index.html @@ -81,25 +81,6 @@
-
-
-

- - - -

-

- -

-

- - - - - -

-
-

@@ -202,6 +183,26 @@

+
+
+
+
+

+ + + +

+

+ +

+

+ +

+
+
+
+ +
@@ -248,6 +249,24 @@ Total Requests: None since start
+ +
+ Transport addresses +
+

+ + + +

+

+ +

+

+ +

+
+
+ Outgoing Connections:
@@ -268,7 +287,7 @@

-

diff --git a/static-data/www/shared/main/apicheck.js b/static-data/www/shared/main/apicheck.js index fb89777e..dba90f04 100644 --- a/static-data/www/shared/main/apicheck.js +++ b/static-data/www/shared/main/apicheck.js @@ -18,6 +18,9 @@ */ apiOnline = true async function doPing(){ + if (document.hidden){ + return + } out = setTimeout(function(){ if (apiOnline){ PNotify.notice('Connection lost with API server') diff --git a/static-data/www/shared/main/particles.js b/static-data/www/shared/main/particles.js index 09ba6a04..5107db29 100644 --- a/static-data/www/shared/main/particles.js +++ b/static-data/www/shared/main/particles.js @@ -1538,4 +1538,16 @@ var pJS = function(tag_id, params){ }; xhr.send(); - }; \ No newline at end of file + }; + let toggleAnimation = function () { + if (document.hidden) { + cancelRequestAnimFrame(pJSDom[0].pJS.fn.checkAnimFrame); + cancelRequestAnimFrame(pJSDom[0].pJS.fn.drawAnimFrame); + pJSDom[0].pJS.fn.particlesEmpty(); + pJSDom[0].pJS.fn.canvasClear(); + return; + } + pJSDom[0].pJS.fn.vendors.start(); + } + + document.addEventListener("visibilitychange", toggleAnimation, false); \ No newline at end of file diff --git a/static-data/www/shared/main/recent.js b/static-data/www/shared/main/recent.js index 2ae978bc..abc41a96 100644 --- a/static-data/www/shared/main/recent.js +++ b/static-data/www/shared/main/recent.js @@ -1,10 +1,51 @@ -var recentSource = new EventSourcePolyfill('/recentblocks', { - headers: { - "token": webpass +var getRecent = function(){ + var recentSource = new EventSourcePolyfill('/recentblocks', { + headers: { + "token": webpass + } + }) + + + recentSource.onmessage = function(e){ + if (e.data == "none"){ + return + } + var existing = document.getElementsByClassName('recentBlockList')[0].innerText; + let data = JSON.parse(e.data) + Object.entries(data.blocks).forEach(([key, value]) => { + if (existing.includes(key)){ + return + } + existing = key + " - " + value + "\n" + existing + }) + document.getElementsByClassName('recentBlockList')[0].innerText = existing + console.debug(data) } - }) - - -recentSource.onmessage = function(e){ - console.debug(e) + return recentSource } +recentSource = getRecent() +function toggleRecentStream() { + if (document.hidden){ + console.debug("Stopped recent block stream") + recentSource.close() + return + } + if (document.getElementsByClassName('recentModal')[0].classList.contains('is-active')){ + recentSource.close() + getRecent() + } +} + + +document.getElementsByClassName('recentBlocksBtn')[0].onclick = function(){ + document.getElementsByClassName('recentModal')[0].classList.add('is-active') +} + + +document.getElementsByClassName('recentBlocksBtn') +document.addEventListener("visibilitychange", toggleRecentStream, false); + +document.getElementsByClassName('closeRecentModal')[0].onclick = function(){ + document.getElementsByClassName('recentBlockList')[0].innerText = "" + document.getElementsByClassName('recentModal')[0].classList.remove('is-active') +} \ No newline at end of file diff --git a/static-data/www/shared/main/stats.js b/static-data/www/shared/main/stats.js index d2caf4f9..0632cd02 100755 --- a/static-data/www/shared/main/stats.js +++ b/static-data/www/shared/main/stats.js @@ -146,7 +146,19 @@ getStats() setInterval(function(){getStats()}, 1000) -/* particlesJS.load(@dom-id, @path-json, @callback (optional)); */ -particlesJS.load('particles-js', '/shared/main/particles.json', function() { - console.log('callback - particles.js config loaded'); - }); \ No newline at end of file + +fetch('/config/get/ui.animated_background', { + headers: { + "token": webpass + }}) + .then((resp) => resp.text()) // Transform the data into text + .then(function(resp) { + if (resp == "false"){ + return + } + /* particlesJS.load(@dom-id, @path-json, @callback (optional)); */ + particlesJS.load('particles-js', '/shared/main/particles.json', function() { + console.debug('callback - particles.js config loaded') + }) + } + ) \ No newline at end of file diff --git a/static-data/www/shared/main/torstats.js b/static-data/www/shared/main/torstats.js index e72a84fd..12706c83 100644 --- a/static-data/www/shared/main/torstats.js +++ b/static-data/www/shared/main/torstats.js @@ -5,7 +5,7 @@ fetch('/config/get/transports.tor', { .then((resp) => resp.text()) // Transform the data into text .then(function(resp) { var displays = document.getElementsByClassName('torInfo') - if (resp == true){ + if (resp == "true"){ var torSource = new EventSourcePolyfill('/torcircuits', { headers: { "token": webpass