From 2568a35aa5cf66bf0dc88755d2c0c28d0491689b Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 20 Dec 2022 19:24:35 +0100 Subject: [PATCH] Add Ability to close QuickCss --- .../dev/vendicated/vencord/MainActivity.java | 5 ++- .../dev/vendicated/vencord/VencordNative.java | 1 + app/src/main/res/raw/vencord_mobile.js | 36 +++++++++++++++---- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/dev/vendicated/vencord/MainActivity.java b/app/src/main/java/dev/vendicated/vencord/MainActivity.java index e946351..346bea0 100644 --- a/app/src/main/java/dev/vendicated/vencord/MainActivity.java +++ b/app/src/main/java/dev/vendicated/vencord/MainActivity.java @@ -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); diff --git a/app/src/main/java/dev/vendicated/vencord/VencordNative.java b/app/src/main/java/dev/vendicated/vencord/VencordNative.java index 485b372..950a9ca 100644 --- a/app/src/main/java/dev/vendicated/vencord/VencordNative.java +++ b/app/src/main/java/dev/vendicated/vencord/VencordNative.java @@ -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(); }); } diff --git a/app/src/main/res/raw/vencord_mobile.js b/app/src/main/res/raw/vencord_mobile.js index 1cb012d..42ad552 100644 --- a/app/src/main/res/raw/vencord_mobile.js +++ b/app/src/main/res/raw/vencord_mobile.js @@ -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; } }; })();