Skip to content

Commit

Permalink
Merge branch 'PojavLauncherTeam:v3_openjdk' into envpatch
Browse files Browse the repository at this point in the history
  • Loading branch information
SolDev69 authored Nov 5, 2023
2 parents 29de6c6 + 16c7c44 commit d71e90d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ public boolean onTouchEvent(MotionEvent e) {
if(hasDoubleTapped && hudKeyHandled == mLastHotbarKey && !PREF_DISABLE_SWAP_HAND){
//Prevent double tapping Event on two different slots
sendKeyPress(LwjglGlfwKeycode.GLFW_KEY_F);
} else {
mHandler.sendEmptyMessageDelayed(MSG_DROP_ITEM_BUTTON_CHECK, 350);
}

mHandler.sendEmptyMessageDelayed(MSG_DROP_ITEM_BUTTON_CHECK, 350);
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
mLastHotbarKey = hudKeyHandled;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -13,6 +14,7 @@
import android.webkit.WebViewClient;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import net.kdt.pojavlaunch.R;
Expand All @@ -24,30 +26,57 @@ public class MicrosoftLoginFragment extends Fragment {
public static final String TAG = "MICROSOFT_LOGIN_FRAGMENT";
private WebView mWebview;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mWebview = (WebView) inflater.inflate(R.layout.fragment_microsoft_login, container, false);
CookieManager.getInstance().removeAllCookies(this::onCookiesRemoved);
setWebViewSettings();
if(savedInstanceState == null) startNewSession();
else restoreWebViewState(savedInstanceState);
return mWebview;
}

@SuppressLint("SetJavaScriptEnabled") // required for Microsoft log-in
public void onCookiesRemoved(Boolean b) {
// WebView.restoreState() does not restore the WebSettings or the client, so set them there
// separately. Note that general state should not be altered here (aka no loading pages, no manipulating back/front lists),
// to avoid "undesirable side-effects"
@SuppressLint("SetJavaScriptEnabled")
private void setWebViewSettings() {
WebSettings settings = mWebview.getSettings();

settings.setJavaScriptEnabled(true);
mWebview.clearHistory();
mWebview.clearCache(true);
mWebview.clearFormData();
mWebview.clearHistory();
mWebview.setWebViewClient(new WebViewTrackClient());
}

private void startNewSession() {
CookieManager.getInstance().removeAllCookies((b)->{
mWebview.clearHistory();
mWebview.clearCache(true);
mWebview.clearFormData();
mWebview.clearHistory();
mWebview.loadUrl("https://login.live.com/oauth20_authorize.srf" +
"?client_id=00000000402b5328" +
"&response_type=code" +
"&scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL" +
"&redirect_url=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf");
});
}

mWebview.loadUrl("https://login.live.com/oauth20_authorize.srf" +
"?client_id=00000000402b5328" +
"&response_type=code" +
"&scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL" +
"&redirect_url=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf");
private void restoreWebViewState(Bundle savedInstanceState) {
Log.i("MSAuthFragment","Restoring state...");
if(mWebview.restoreState(savedInstanceState) == null) {
Log.w("MSAuthFragment", "Failed to restore state, starting afresh");
// if, for some reason, we failed to restore our session,
// just start afresh
startNewSession();
}
}

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
// Since the value cannot be null, just creaqte a "blank" client. This is done to not let Android
// kill us if something happens after onSaveInstanceState
mWebview.setWebViewClient(new WebViewClient());
mWebview.saveState(outState);
super.onSaveInstanceState(outState);
// if something happens after this, well, too bad
}

/* Expose webview actions to others */
Expand Down

1 comment on commit d71e90d

@SolDev69
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to get it to stop making merge commits aaaaaa

Please sign in to comment.