Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions hooks/post-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ copyDirRecursively(localResPath, resPath);
enableLegacyJni();
enableStaticContext();
patchTargetSdkVersion();
enableKeyboardWorkaround();


function getTmpDir() {
Expand Down Expand Up @@ -185,6 +186,57 @@ function enableStaticContext() {
}
}

function enableKeyboardWorkaround() {
try{
const prefix = execSync('npm prefix').toString().trim();
const mainActivityPath = path.join(
prefix,
'platforms/android/app/src/main/java/com/foxdebug/acode/MainActivity.java'
);

if (!fs.existsSync(mainActivityPath)) {
return;
}

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

// Skip if already patched
if (content.includes('SoftInputAssist')) {
return;
}

// Add import
if (!content.includes('import com.foxdebug.system.SoftInputAssist;')) {
content = content.replace(
/import java.lang.ref.WeakReference;/,
match =>
match + '\nimport com.foxdebug.system.SoftInputAssist;'
);
Comment thread
RohitKushvaha01 marked this conversation as resolved.
}

// Declare field
if (!content.includes('private SoftInputAssist softInputAssist;')) {
content = content.replace(
/public class MainActivity extends CordovaActivity\s*\{/,
match =>
match +
`\n\n private SoftInputAssist softInputAssist;\n`
);
}

// Initialize in onCreate
content = content.replace(
/loadUrl\(launchUrl\);/,
`loadUrl(launchUrl);\n\n softInputAssist = new SoftInputAssist(this);`
);
Comment thread
RohitKushvaha01 marked this conversation as resolved.

fs.writeFileSync(mainActivityPath, content, 'utf-8');
console.log('[Cordova Hook] ✅ Enabled keyboard workaround');
} catch (err) {
console.error('[Cordova Hook] ❌ Failed to enable keyboard workaround:', err.message);
}
}


/**
* Copy directory recursively
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.foxdebug.system;

import android.app.Activity;
import android.graphics.Rect;
import android.view.View;

public class SoftInputAssist {
private final View rootView;
private final View contentView;
private int baseline = -1;

public SoftInputAssist(Activity activity) {
rootView = activity.getWindow().getDecorView();
contentView = activity.findViewById(android.R.id.content);

rootView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
Rect r = new Rect();
rootView.getWindowVisibleDisplayFrame(r);

int heightDiff = rootView.getHeight() - (r.bottom - r.top);

// Save baseline (system bars only)
if (baseline == -1) {
baseline = heightDiff;
}
Comment thread
RohitKushvaha01 marked this conversation as resolved.
Outdated

int keyboardHeight = heightDiff - baseline;

if (keyboardHeight > 0) {
contentView.setPadding(0, 0, 0, keyboardHeight);
} else {
contentView.setPadding(0, 0, 0, 0);
}
});
}
}
15 changes: 8 additions & 7 deletions src/plugins/system/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
<resource-file src="res/android/icon.ttf" target="assets/font/icon.ttf" />
<source-file src="android/com/foxdebug/system/Ui.java" target-dir="src/com/foxdebug/system"/>
<source-file src="android/com/foxdebug/system/System.java" target-dir="src/com/foxdebug/system"/>

<framework src="androidx.core:core:1.6.0" />
<framework src="androidx.core:core-google-shortcuts:1.0.0" />
<framework src="androidx.documentfile:documentfile:1.0.1" />
<source-file src="android/com/foxdebug/system/RewardPassManager.java" target-dir="src/com/foxdebug/system"/>
</platform>
</plugin>
<source-file src="android/com/foxdebug/system/SoftInputAssist.java" target-dir="src/com/foxdebug/system"/>

<framework src="androidx.core:core:1.6.0" />
<framework src="androidx.core:core-google-shortcuts:1.0.0" />
<framework src="androidx.documentfile:documentfile:1.0.1" />
<source-file src="android/com/foxdebug/system/RewardPassManager.java" target-dir="src/com/foxdebug/system"/>
</platform>
</plugin>
Loading