Skip to content

Commit aa0d19c

Browse files
committed
Add moduleInfo() fallback
1 parent b558c74 commit aa0d19c

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

module/webroot/js/common.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,40 @@ import { exec, toast, moduleInfo } from './kernelsu.js';
22
import router_state from './router.js';
33
import { addLog } from './logs.js';
44

5-
export function updateModuleInformation () {
5+
async function readModuleProp () {
6+
try {
7+
const { stdout: details } = await exec(`cat /data/adb/modules/tcp_optimiser/module.prop`);
8+
const lines = details.trim().split('\n').filter(line => line);
9+
10+
// Convert lines to object
11+
let moduleInfo = lines.reduce((acc, line) => {
12+
const [key, ...rest] = line.split('=');
13+
const value = rest.join('=').trim(); // handle values with '=' in them
14+
acc[key.trim()] = value;
15+
return acc;
16+
}, {});
17+
18+
moduleInfo["moduleDir"] = `/data/adb/modules/${moduleInfo.id}`;
19+
return moduleInfo;
20+
} catch (error) {
21+
22+
}
23+
}
24+
25+
export async function updateModuleInformation () {
626
try {
727
router_state.moduleInformation = JSON.parse(moduleInfo());
8-
var versionStr = router_state.moduleInformation.version ? 'v' + router_state.moduleInformation.version : '';
9-
var versionCodeStr = router_state.moduleInformation.versionCode ? router_state.moduleInformation.versionCode : '';
10-
var finalVersionStr = versionStr != '' && versionCodeStr != '' ? `${versionStr} (${versionCodeStr})` : "module.prop might be corrupted!"
11-
document.getElementById('version').textContent = finalVersionStr;
28+
if(router_state.moduleInformation != {}) {
29+
router_state.moduleInformation = await readModuleProp();
30+
}
1231
}catch (error) {
1332
console.error('Error updating module info:', error);
1433
toast("Error fetching module info.");
1534
}
35+
var versionStr = router_state.moduleInformation.version ? 'v' + router_state.moduleInformation.version : '';
36+
var versionCodeStr = router_state.moduleInformation.versionCode ? router_state.moduleInformation.versionCode : '';
37+
var finalVersionStr = versionStr != '' && versionCodeStr != '' ? `${versionStr} (${versionCodeStr})` : "module.prop might be corrupted!"
38+
document.getElementById('version').textContent = finalVersionStr;
1639
}
1740

1841
export async function getModuleActiveState () {

module/webroot/js/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ document.addEventListener('DOMContentLoaded', async () => {
112112
setCSS(pageName);
113113

114114
if (!router_state.moduleInformation) {
115-
updateModuleInformation();
115+
updateModuleInformation().then(res => {});
116116
}
117117

118118
// Load page-specific script

0 commit comments

Comments
 (0)