Skip to content

Commit

Permalink
Merge pull request #2 from Moukrea/hotfix/betterxcloud-not-loading
Browse files Browse the repository at this point in the history
Resolve #1 - Better xCloud not loading
  • Loading branch information
moukrea authored Apr 15, 2024
2 parents d29cb6e + 08c5dad commit 05858d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions android/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0.0"
versionName "1.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private String fetchLatestVersion() {
}
return null; // Default or error handling
}

/**
* Loads Game Pass into WebView
* Injects custom scripts and Better xCloud
Expand Down Expand Up @@ -321,7 +321,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if (MainActivity.this.useBetterXcloud) { // Use the class field here
if (MainActivity.this.useBetterXcloud) {
injectScript(view);
}
}
Expand Down Expand Up @@ -481,16 +481,19 @@ private void injectScript(WebView webView) {
File scriptFile = new File(getFilesDir(), "better-xcloud.user.js");
InputStream inputStream = new FileInputStream(scriptFile);
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);
inputStream.close();
String encoded = Base64.encodeToString(buffer, Base64.NO_WRAP);

// JavaScript to ensure the script runs as early as possible
String script = "if (document.readyState === 'loading') {" +
"var script = document.createElement('script');" +
"script.type = 'text/javascript';" +
// Decode and set the script content
"script.text = decodeURIComponent(escape(window.atob('" + encoded + "')));" +
"document.documentElement.appendChild(script);" +
"} else {" +
// If the page is not in 'loading', force a reload
"window.location.reload();" +
"}";
webView.evaluateJavascript(script, null);
} catch (Exception e) {
Expand Down

0 comments on commit 05858d3

Please sign in to comment.