1
0
Fork 0

Add Ability to close QuickCss

This commit is contained in:
Vendicated 2022-12-20 19:24:35 +01:00
parent 90a1841a97
commit 2568a35aa5
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
3 changed files with 35 additions and 7 deletions

View file

@ -62,7 +62,10 @@ public class MainActivity extends Activity {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && wv != null) {
runOnUiThread(() -> wv.evaluateJavascript("VencordMobile.onBackPress()", null));
runOnUiThread(() -> wv.evaluateJavascript("VencordMobile.onBackPress()", r -> {
if ("false".equals(r))
this.onBackPressed ();
}));
return true;
}
return super.onKeyDown(keyCode, event);

View file

@ -19,6 +19,7 @@ public class VencordNative {
if (wv.canGoBack())
wv.goBack();
else
// no idea what i was smoking when I wrote this
activity.getActionBar();
});
}

View file

@ -1,13 +1,37 @@
!(() => {
const { findLazy, Common } = Vencord.Webpack;
const { findLazy, Common, onceReady } = Vencord.Webpack;
const ModalEscapeHandler = findLazy(m => m.binds?.length === 1 && m.binds[0] === "esc");
window.VencordMobile = {
onBackPress() {
// false implies modal closed
if (ModalEscapeHandler.action() === false) return;
let isSidebarOpen = false;
onceReady.then(() => {
Common.FluxDispatcher.subscribe("MOBILE_WEB_SIDEBAR_OPEN", () => {
isSidebarOpen = true;
});
Common.FluxDispatcher.subscribe("MOBILE_WEB_SIDEBAR_CLOSE", () => {
isSidebarOpen = false;
});
});
Common.FluxDispatcher.dispatch({ type: "MOBILE_WEB_SIDEBAR_OPEN" });
window.VencordMobile = {
// returns true if an action was taken, false if the java side should handle the back press
onBackPress() {
// false means modal closed (no further action rewuired?)
if (ModalEscapeHandler.action() === false) return true;
// try to close quick css window if open
const quickCssWin = window.__VENCORD_MONACO_WIN__?.deref();
if (quickCssWin && !quickCssWin.closed) {
quickCssWin.close();
delete window.__VENCORD_MONACO_WIN__;
return true;
}
if (!isSidebarOpen) {
Common.FluxDispatcher.dispatch({ type: "MOBILE_WEB_SIDEBAR_OPEN" });
return true;
}
return false;
}
};
})();