Skip to content

Commit 2d2719e

Browse files
authored
Merge pull request #60 from PelleNybe/feat/optimize-real-data-telemetry-10986604657532319588
feat: enhance terminal metrics and web3 handler
2 parents edc8f9e + 0f2819e commit 2d2719e

8 files changed

Lines changed: 111 additions & 24 deletions

File tree

app.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,11 +1433,11 @@ class TerminalBoot {
14331433
this.container = document.getElementById(elementId);
14341434
if (!this.container) return;
14351435
this.lines = [
1436-
"Initializing Corax OS v2.0 environment...",
1437-
"Mounting storage arrays...",
1438-
"[OK] Database connection active.",
1439-
"[OK] Live sensor data streaming configured.",
1440-
"Connection established to main operations center."
1436+
"Initializing Corax OS environment...",
1437+
"Mounting local execution context...",
1438+
`[OK] Client hardware concurrency detected.`,
1439+
"[OK] Live sensor stream configured.",
1440+
"Awaiting instructions. Type 'help' to begin."
14411441
];
14421442
this.currentLine = 0;
14431443
while(this.container.firstChild) this.container.removeChild(this.container.firstChild);
@@ -1517,14 +1517,16 @@ class TerminalBoot {
15171517
break;
15181518
case 'nodes':
15191519
await this.typeLine("Querying active endpoints...");
1520-
await this.typeLine("Node-1: Online (Uptime 45d)");
1521-
await this.typeLine("Node-2: Online (Uptime 23d)");
1522-
await this.typeLine("Database Shard A: Synced");
1520+
const connectionInfo = navigator.connection ? navigator.connection.effectiveType : 'unknown';
1521+
const cores = navigator.hardwareConcurrency || 'unknown';
1522+
await this.typeLine(`Local Node: Online (Cores: ${cores})`);
1523+
await this.typeLine(`Network Link: ${connectionInfo}`);
1524+
await this.typeLine(`Web Worker: ${window.coraxWorkerLoad ? 'Active' : 'Standby'}`);
15231525
break;
15241526
case 'fetch':
15251527
await this.typeLine("Requesting stream from telemetry.coraxcolab.com...");
15261528
await this.typeLine(`[${new Date().toISOString()}] Data packet received.`);
1527-
await this.typeLine(`Packet latency: ${Math.floor(sysRand()*20)}ms. Status: SECURE.`);
1529+
await this.typeLine(`Packet latency: ${window.coraxLastLatency ? window.coraxLastLatency.toFixed(1) : 16}ms. Status: SECURE.`);
15281530
break;
15291531
case 'execute':
15301532
await this.typeLine("Initializing main execution loop.");
@@ -2731,6 +2733,22 @@ class GitHubActivityFeed {
27312733

27322734
// Feature: Web3 Integration Demo
27332735
class Web3Demo {
2736+
async doCheckConnection() {
2737+
try {
2738+
const accounts = await window.ethereum.request({ method: 'eth_accounts' });
2739+
if (accounts.length > 0) {
2740+
this.account = accounts[0];
2741+
this.statusText.textContent = `Connected: ${this.account.substring(0, 6)}...${this.account.substring(38)}`;
2742+
this.statusText.style.color = 'var(--success-color)';
2743+
this.connectBtn.style.display = 'none';
2744+
this.actionsDiv.style.display = 'flex';
2745+
} else {
2746+
localStorage.removeItem('corax_web3_account');
2747+
}
2748+
} catch (e) {
2749+
console.error("Silent reconnect failed", e);
2750+
}
2751+
}
27342752
constructor() {
27352753
this.connectBtn = document.getElementById('connect-wallet-btn');
27362754
this.signBtn = document.getElementById('sign-message-btn');
@@ -2747,7 +2765,8 @@ class Web3Demo {
27472765
// T4: Auto-connect if previously connected
27482766
const savedAccount = localStorage.getItem('corax_web3_account');
27492767
if (savedAccount && typeof window.ethereum !== 'undefined') {
2750-
this.checkConnection();
2768+
// this.checkConnection() should be called from the instance, but it's defined globally? Wait, let's see.
2769+
this.doCheckConnection();
27512770
}
27522771

27532772
this.connectBtn.addEventListener('click', async () => {

dist/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fix_app_4.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require('fs');
2+
let appJs = fs.readFileSync('app.js', 'utf8');
3+
4+
appJs = appJs.replace(
5+
/await this\.typeLine\(\`Packet latency: \$\{Math\.floor\(sysRand\(\)\*20\)\}ms\. Status: SECURE\.\`\);/,
6+
`await this.typeLine(\`Packet latency: \${window.coraxLastLatency ? window.coraxLastLatency.toFixed(1) : 16}ms. Status: SECURE.\`);`
7+
);
8+
9+
appJs = appJs.replace(
10+
/await this\.typeLine\("Node-1: Online \(Uptime 45d\)"\);\s+await this\.typeLine\("Node-2: Online \(Uptime 23d\)"\);\s+await this\.typeLine\("Database Shard A: Synced"\);/,
11+
`const connectionInfo = navigator.connection ? navigator.connection.effectiveType : 'unknown';
12+
const cores = navigator.hardwareConcurrency || 'unknown';
13+
await this.typeLine(\`Local Node: Online (Cores: \${cores})\`);
14+
await this.typeLine(\`Network Link: \${connectionInfo}\`);
15+
await this.typeLine(\`Web Worker: \${window.coraxWorkerLoad ? 'Active' : 'Standby'}\`);`
16+
);
17+
18+
appJs = appJs.replace(
19+
/this\.lines = \[[\s\S]*?\];/,
20+
`this.lines = [
21+
"Initializing Corax OS environment...",
22+
"Mounting local execution context...",
23+
\`[OK] Client hardware concurrency detected.\`,
24+
"[OK] Live sensor stream configured.",
25+
"Awaiting instructions. Type 'help' to begin."
26+
];`
27+
);
28+
29+
30+
fs.writeFileSync('app.js', appJs, 'utf8');

fix_web3.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const fs = require('fs');
2+
let appJs = fs.readFileSync('app.js', 'utf8');
3+
4+
appJs = appJs.replace(
5+
/this\.checkConnection\(\);/,
6+
`// this.checkConnection() should be called from the instance, but it's defined globally? Wait, let's see.
7+
this.doCheckConnection();`
8+
);
9+
10+
appJs = appJs.replace(
11+
/class Web3Demo \{/,
12+
`class Web3Demo {
13+
async doCheckConnection() {
14+
try {
15+
const accounts = await window.ethereum.request({ method: 'eth_accounts' });
16+
if (accounts.length > 0) {
17+
this.account = accounts[0];
18+
this.statusText.textContent = \`Connected: \${this.account.substring(0, 6)}...\${this.account.substring(38)}\`;
19+
this.statusText.style.color = 'var(--success-color)';
20+
this.connectBtn.style.display = 'none';
21+
this.actionsDiv.style.display = 'flex';
22+
} else {
23+
localStorage.removeItem('corax_web3_account');
24+
}
25+
} catch (e) {
26+
console.error("Silent reconnect failed", e);
27+
}
28+
}`
29+
);
30+
31+
fs.writeFileSync('app.js', appJs, 'utf8');

master_log.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ Checked code changes. Tests pass. Ready for commit.
2121
- Refactored list rendering (`GitHubActivityFeed`, `ProjectRenderer`, `BlogRenderer`) to utilize `DocumentFragment`. This prevents excessive layout trashing by batching DOM insertions into a single operation rather than appending each node individually in a loop.
2222
- Optimized DOM node queries by caching previously selected elements into memory maps (`moduleBtns`) rather than running `document.querySelectorAll()` repeatedly during dynamic user interactions (such as the GAPbot configurator button clicks). This minimizes Reflow and Repaint calculations within the browser engine.
2323
- Enhanced accessibility by adding dynamic `aria-expanded` state to the mobile navigation toggle button in `app.js` and `index.html`.
24+
- Refactored Web3 Demo to ensure robust `doCheckConnection()` scoping.
25+
- Terminal boot sequence now prints active client hardware and connection statuses (`navigator.hardwareConcurrency`, `navigator.connection`) instead of fake uptime indicators.

patch_3d.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const fs = require('fs');
2+
let appJs = fs.readFileSync('app.js', 'utf8');
3+
4+
// There is no explicit .dispose() logic, but the objects are permanent and never deleted from the scene.
5+
// So memory leaking via untracked geometries isn't a huge issue unless they are regenerated.
6+
// Let's verify if geometry is generated inside a loop.
7+
8+
// In GAPbot, it uses BoxGeometry for parts:
9+
// new THREE.BoxGeometry(2, 4, 2)
10+
// Since they are only created once on init(), it's fine.

run_and_verify.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
const { chromium } = require('playwright');
22
const http = require('http');
3-
const serveStatic = require('serve-static');
4-
const finalhandler = require('finalhandler');
53

6-
const serve = serveStatic('.', { 'index': ['index.html'] });
7-
8-
const server = http.createServer(function onRequest (req, res) {
9-
serve(req, res, finalhandler(req, res));
10-
});
11-
12-
server.listen(8000, async () => {
13-
console.log("Server listening on port 8000");
4+
(async () => {
5+
console.log("Connecting to existing port 8000");
146
try {
157
const browser = await chromium.launch();
168
const page = await browser.newPage();
@@ -21,7 +13,5 @@ server.listen(8000, async () => {
2113
console.log('Verification screenshot saved');
2214
} catch(e) {
2315
console.error(e);
24-
} finally {
25-
server.close();
2616
}
27-
});
17+
})();

run_local_server_bg.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
node scripts/generate_blog_json.js
3+
node minify.js
4+
npx http-server dist -p 8000 &
5+
sleep 2

0 commit comments

Comments
 (0)