Skip to content

Commit b558c74

Browse files
committed
Add Module Status
1 parent 57bf50b commit b558c74

File tree

4 files changed

+83
-48
lines changed

4 files changed

+83
-48
lines changed

module/webroot/js/common.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ export function updateModuleInformation () {
1515
}
1616
}
1717

18+
export async function getModuleActiveState () {
19+
try {
20+
const { stdout: file_exists } = await exec(`ls "/dev/.tcp_module_log_cleared"`);
21+
return file_exists != "" ? true: false;
22+
}catch (error) {
23+
console.error('Error updating module state:', error);
24+
toast("Error fetching module state.");
25+
}
26+
}
27+
1828
export async function get_active_iface () {
1929
try {
2030
const { stdout: active_iface } = await exec(`ip route get 192.0.2.1 2>/dev/null | awk '/dev/ {for(i=1;i<=NF;i++) if($i=="dev") print $(i+1)}'`);

module/webroot/js/home.js

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { exec, toast } from './kernelsu.js';
2-
import { get_active_iface, get_active_algorithm, getInitcwndInitrwndValue, get_wifi_calling_state } from './common.js';
2+
import { get_active_iface, get_active_algorithm, getInitcwndInitrwndValue, get_wifi_calling_state, getModuleActiveState } from './common.js';
33
import router_state from './router.js';
44

55
export async function updateModuleStatus () {
6+
var module_status = "Loading Module Status...⌛";
67
var active_iface = "None";
7-
var active_iface_type = "Unknown ⁉️"
8+
var active_iface_type = "Unknown ⁉️";
89
var active_algorithm = "Unknown ⁉️";
910
var wifi_calling_state = "Unknown ⁉️";
1011
var active_InitcwndInitrwndValue = [];
1112
try
1213
{
14+
module_status = (await getModuleActiveState()) == true ? "Enabled ✅" : "Disabled ❌";
1315
active_iface = await get_active_iface();
1416
active_iface = active_iface ? active_iface : "None";
1517
active_iface_type = active_iface.startsWith("rmnet") || active_iface.startsWith("ccmni") ? "Cellular 📶" : active_iface.startsWith("wlan") ? "Wi-Fi 🛜" : "Unknown ⁉️";
@@ -24,6 +26,7 @@ export async function updateModuleStatus () {
2426
addLog('Error updating status.');
2527
toast("Error updating status.");
2628
} finally {
29+
router_state.homePageParams.module_status = module_status;
2730
router_state.homePageParams.active_iface_type = active_iface_type;
2831
router_state.homePageParams.active_iface = active_iface;
2932
router_state.homePageParams.active_algorithm = active_algorithm;
@@ -34,54 +37,71 @@ export async function updateModuleStatus () {
3437

3538
export function updateHomeUI () {
3639
if (router_state.isInitializing == false) {
37-
document.getElementById('active_iface_type_value').textContent = router_state.homePageParams.active_iface_type;
38-
document.getElementById('active_iface_value').textContent = router_state.homePageParams.active_iface;
39-
document.getElementById('tcp_cong_value').textContent = router_state.homePageParams.active_algorithm;
40-
41-
const wifiCallingDiv = document.getElementById('wifi_calling_value_div');
42-
const wifiCallingSpan = document.getElementById('wifi_calling_value');
43-
44-
if(router_state.homePageParams.active_iface_type == "Wi-Fi 🛜")
40+
document.getElementById('module_status_value').textContent = router_state.homePageParams.module_status;
41+
if(router_state.homePageParams.module_status == "Enabled ✅")
4542
{
46-
if (wifiCallingDiv?.classList.contains('hidden'))
47-
wifiCallingDiv.classList.remove('hidden');
43+
const ifaceTypeDiv = document.getElementById('active_iface_type_div');
44+
const ifaceValDiv = document.getElementById('active_iface_div');
45+
const tcpCongValDiv = document.getElementById('tcp_cong_div');
4846

49-
wifiCallingSpan.textContent = router_state.homePageParams.wifi_calling_state;
50-
}
51-
else
52-
{
53-
if (wifiCallingDiv.classList.contains('hidden'))
54-
wifiCallingDiv.classList.add('hidden');
55-
wifiCallingSpan.textContent = "Unknown ⁉️";
56-
}
57-
58-
const initcwndDiv = document.getElementById('initcwnd_value_div');
59-
const initrwndDiv = document.getElementById('initrwnd_value_div');
60-
const initcwndSpan = document.getElementById('initcwnd_value');
61-
const initrwndSpan = document.getElementById('initrwnd_value');
62-
63-
const values = router_state.homePageParams.active_InitcwndInitrwndValue;
64-
const isLoading = values.length < 2 && router_state.settingsPageParams.initcwndInitrwnd;
65-
66-
if(values.length == 2 || isLoading)
67-
{
68-
if (initcwndDiv?.classList.contains('hidden'))
69-
initcwndDiv.classList.remove('hidden');
47+
document.getElementById('active_iface_type_value').textContent = router_state.homePageParams.active_iface_type;
48+
document.getElementById('active_iface_value').textContent = router_state.homePageParams.active_iface;
49+
document.getElementById('tcp_cong_value').textContent = router_state.homePageParams.active_algorithm;
7050

71-
if (initrwndDiv?.classList.contains('hidden'))
72-
initrwndDiv.classList.remove('hidden');
51+
if (ifaceTypeDiv?.classList.contains('hidden'))
52+
ifaceTypeDiv.classList.remove('hidden');
7353

74-
initcwndSpan.textContent = values.length == 2 ? values[0] : "Loading initcwnd value...";
75-
initrwndSpan.textContent = values.length == 2 ? values[1] : "Loading initrwnd value...";
76-
}
77-
else
78-
{
79-
// No data and not loading → hide the section
80-
if (initcwndDiv && !initcwndDiv.classList.contains('hidden'))
81-
initcwndDiv.classList.add('hidden');
54+
if (ifaceValDiv?.classList.contains('hidden'))
55+
ifaceValDiv.classList.remove('hidden');
56+
57+
if (tcpCongValDiv?.classList.contains('hidden'))
58+
tcpCongValDiv.classList.remove('hidden');
59+
60+
const wifiCallingDiv = document.getElementById('wifi_calling_value_div');
61+
const wifiCallingSpan = document.getElementById('wifi_calling_value');
62+
63+
if(router_state.homePageParams.active_iface_type == "Wi-Fi 🛜")
64+
{
65+
if (wifiCallingDiv?.classList.contains('hidden'))
66+
wifiCallingDiv.classList.remove('hidden');
67+
68+
wifiCallingSpan.textContent = router_state.homePageParams.wifi_calling_state;
69+
}
70+
else
71+
{
72+
if (wifiCallingDiv.classList.contains('hidden'))
73+
wifiCallingDiv.classList.add('hidden');
74+
wifiCallingSpan.textContent = "Unknown ⁉️";
75+
}
76+
77+
const initcwndDiv = document.getElementById('initcwnd_value_div');
78+
const initrwndDiv = document.getElementById('initrwnd_value_div');
79+
const initcwndSpan = document.getElementById('initcwnd_value');
80+
const initrwndSpan = document.getElementById('initrwnd_value');
81+
82+
const values = router_state.homePageParams.active_InitcwndInitrwndValue;
83+
const isLoading = values.length < 2 && router_state.settingsPageParams.initcwndInitrwnd;
8284

83-
if (initrwndDiv && !initrwndDiv.classList.contains('hidden'))
84-
initrwndDiv.classList.add('hidden');
85+
if(values.length == 2 || isLoading)
86+
{
87+
if (initcwndDiv?.classList.contains('hidden'))
88+
initcwndDiv.classList.remove('hidden');
89+
90+
if (initrwndDiv?.classList.contains('hidden'))
91+
initrwndDiv.classList.remove('hidden');
92+
93+
initcwndSpan.textContent = values.length == 2 ? values[0] : "Loading initcwnd value...";
94+
initrwndSpan.textContent = values.length == 2 ? values[1] : "Loading initrwnd value...";
95+
}
96+
else
97+
{
98+
// No data and not loading → hide the section
99+
if (initcwndDiv && !initcwndDiv.classList.contains('hidden'))
100+
initcwndDiv.classList.add('hidden');
101+
102+
if (initrwndDiv && !initrwndDiv.classList.contains('hidden'))
103+
initrwndDiv.classList.add('hidden');
104+
}
85105
}
86106
}
87107
}

module/webroot/js/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const router_state = {
88
moduleInformation: null,
99
isInitializing: true,
1010
homePageParams: {
11+
module_status: "Loading Module Status...⌛",
1112
active_iface_type: "None",
1213
active_iface: "Unknown ⁉️",
1314
active_algorithm: "Unknown",

module/webroot/pages/home.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<div class="card system-info">
22
<div class="card-header">
3-
<h3>Module Status</h3>
3+
<h3>Status</h3>
44
</div>
55
<div class="info-row">
6+
<span class="label">Module Status</span>
7+
<span id="module_status_value" class="value">Loading Module Status...</span>
8+
</div>
9+
<div id="active_iface_type_div" class="info-row hidden">
610
<span class="label">Interface Type</span>
711
<span id="active_iface_type_value" class="value">Loading Active interface type...</span>
812
</div>
9-
<div class="info-row">
13+
<div id="active_iface_div" class="info-row hidden">
1014
<span class="label">Interface Name</span>
1115
<span id="active_iface_value" class="value">Loading Active interface...</span>
1216
</div>
13-
<div class="info-row">
17+
<div id="tcp_cong_div" class="info-row hidden">
1418
<span class="label">TCP Congestion Algorithm</span>
1519
<span id="tcp_cong_value" class="value">Loading Active Algorithm...</span>
1620
</div>

0 commit comments

Comments
 (0)