Skip to content

Commit 83b1000

Browse files
fix: hooks not working on free version (#2075)
* fix: hooks not working on free version * Update hooks/post-process.js Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update post-process.js ---------
1 parent bf50c7a commit 83b1000

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

hooks/post-process.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ enableStaticContext();
3030
patchTargetSdkVersion();
3131
enableKeyboardWorkaround();
3232

33+
function getPackageName() {
34+
const configPath = path.resolve(__dirname, '../config.xml');
35+
if (!fs.existsSync(configPath)) {
36+
console.warn('[Cordova Hook] ⚠️ config.xml not found at', configPath);
37+
throw new Error(`config.xml is missing at ${configPath}`);
38+
}
39+
const content = fs.readFileSync(configPath, 'utf-8');
40+
const match = content.match(/id="([^"]+)"/);
41+
const packageName = match ? match[1] : 'com.foxdebug.acode';
42+
return packageName;
43+
}
44+
3345

3446
function getTmpDir() {
3547
const tmpdirEnv = process.env.TMPDIR;
@@ -107,11 +119,17 @@ function enableLegacyJni() {
107119
const prefix = execSync('npm prefix').toString().trim();
108120
const gradleFile = path.join(prefix, 'platforms/android/app/build.gradle');
109121

110-
if (!fs.existsSync(gradleFile)) return;
122+
if (!fs.existsSync(gradleFile)){
123+
console.warn('[Cordova Hook] ⚠️ build.gradle not found');
124+
return
125+
};
111126

112127
let content = fs.readFileSync(gradleFile, 'utf-8');
113128
// Check for correct block to avoid duplicate insertion
114-
if (content.includes('useLegacyPackaging = true')) return;
129+
if (content.includes('useLegacyPackaging = true')){
130+
console.log('[Cordova Hook] ✅ Legacy JNI packaging already enabled, skipping');
131+
return
132+
};
115133

116134
// Inject under android block with correct Groovy syntax
117135
content = content.replace(/android\s*{/, match => {
@@ -133,12 +151,16 @@ function enableLegacyJni() {
133151
function enableStaticContext() {
134152
try {
135153
const prefix = execSync('npm prefix').toString().trim();
154+
const packageName = getPackageName();
136155
const mainActivityPath = path.join(
137156
prefix,
138-
'platforms/android/app/src/main/java/com/foxdebug/acode/MainActivity.java'
157+
'platforms/android/app/src/main/java',
158+
packageName.replace(/\./g, '/'),
159+
'MainActivity.java'
139160
);
140161

141162
if (!fs.existsSync(mainActivityPath)) {
163+
console.warn('[Cordova Hook] ⚠️ MainActivity.java not found at', mainActivityPath);
142164
return;
143165
}
144166

@@ -150,6 +172,7 @@ function enableStaticContext() {
150172
content.includes('public static Context getContext()') &&
151173
content.includes('weakContext = new WeakReference<>(this);')
152174
) {
175+
console.log('[Cordova Hook] ✅ Static context already enabled, skipping');
153176
return;
154177
}
155178

@@ -181,6 +204,7 @@ function enableStaticContext() {
181204
);
182205

183206
fs.writeFileSync(mainActivityPath, content, 'utf-8');
207+
console.log('[Cordova Hook] ✅ Enabled static context');
184208
} catch (err) {
185209
console.error('[Cordova Hook] ❌ Failed to patch MainActivity:', err.message);
186210
}
@@ -189,19 +213,24 @@ function enableStaticContext() {
189213
function enableKeyboardWorkaround() {
190214
try{
191215
const prefix = execSync('npm prefix').toString().trim();
216+
const packageName = getPackageName();
192217
const mainActivityPath = path.join(
193218
prefix,
194-
'platforms/android/app/src/main/java/com/foxdebug/acode/MainActivity.java'
219+
'platforms/android/app/src/main/java',
220+
packageName.replace(/\./g, '/'),
221+
'MainActivity.java'
195222
);
196223

197224
if (!fs.existsSync(mainActivityPath)) {
225+
console.warn('[Cordova Hook] ⚠️ MainActivity.java not found at', mainActivityPath);
198226
return;
199227
}
200228

201229
let content = fs.readFileSync(mainActivityPath, 'utf-8');
202230

203231
// Skip if already patched
204232
if (content.includes('SoftInputAssist')) {
233+
console.log('[Cordova Hook] ✅ Keyboard workaround already enabled, skipping');
205234
return;
206235
}
207236

src/plugins/system/android/com/foxdebug/system/System.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
138138
@Override
139139
public void run() {
140140
setNativeContextMenuDisabled(false);
141-
new SoftInputAssist(activity);
142141
}
143142
}
144143
);

0 commit comments

Comments
 (0)