From f0519246eddca119eb3710c93e7dabb3b0b1d22e Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 15 Sep 2022 18:23:06 -0700 Subject: [PATCH] Delete custom menu item logic --- .../com/pitchedapps/frost/facebook/FbItem.kt | 8 +--- .../frost/fragments/WebFragments.kt | 2 - .../pitchedapps/frost/injectors/CssAsset.kt | 7 --- .../pitchedapps/frost/injectors/JsAssets.kt | 3 +- .../pitchedapps/frost/views/FrostWebView.kt | 2 - .../com/pitchedapps/frost/web/FrostJSI.kt | 13 +++--- .../frost/web/FrostWebViewClients.kt | 43 ------------------- app/src/web/ts/menu.ts | 32 -------------- app/src/web/ts/menu_quick.ts | 24 ----------- 9 files changed, 8 insertions(+), 126 deletions(-) delete mode 100644 app/src/web/ts/menu.ts delete mode 100644 app/src/web/ts/menu_quick.ts diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt index 9559bf0bc..afe6e706a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt @@ -45,13 +45,7 @@ enum class FbItem( FRIENDS(R.string.friends, GoogleMaterial.Icon.gmd_person_add, "friends/center/requests"), GROUPS(R.string.groups, GoogleMaterial.Icon.gmd_group, "groups"), MARKETPLACE(R.string.marketplace, GoogleMaterial.Icon.gmd_store, "marketplace"), - - /* - * Unlike other urls, menus cannot be linked directly as it is a soft reference. Instead, we can - * pick any url with the blue bar and manually click to enter the menu. - * We pick home.php as some back interactions default to home regardless of the base url. - */ - MENU(R.string.menu, GoogleMaterial.Icon.gmd_menu, "home.php"), + MENU(R.string.menu, GoogleMaterial.Icon.gmd_menu, "bookmarks"), MESSAGES(R.string.messages, MaterialDesignIconic.Icon.gmi_comments, "messages"), MESSENGER( R.string.messenger, diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt index 1981fea87..f365533ef 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt @@ -25,7 +25,6 @@ import com.pitchedapps.frost.injectors.JsActions import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.views.FrostWebView import com.pitchedapps.frost.web.FrostWebViewClient -import com.pitchedapps.frost.web.FrostWebViewClientMenu import com.pitchedapps.frost.web.FrostWebViewClientMessenger /** @@ -41,7 +40,6 @@ class WebFragment : BaseFragment() { fun client(web: FrostWebView) = when (baseEnum) { FbItem.MESSENGER -> FrostWebViewClientMessenger(web) - FbItem.MENU -> FrostWebViewClientMenu(web) else -> FrostWebViewClient(web) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt index e4f06c12d..aa3ce1f0c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt @@ -23,13 +23,6 @@ import com.pitchedapps.frost.prefs.Prefs enum class CssAsset(private val content: String) : InjectorContract { FullSizeImage( "div._4prr[style*=\"max-width\"][style*=\"max-height\"]{max-width:none !important;max-height:none !important}" - ), - - /* - * Remove top margin and hide some contents from the top bar and home page (as it's our base url) - */ - Menu( - "#bookmarks_flyout{margin-top:0 !important}#m_news_feed_stream,#MComposer{display:none !important}" ); val injector: JsInjector by lazy { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt index c7f3caa10..bf12c47ac 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt @@ -30,11 +30,10 @@ import kotlinx.coroutines.withContext /** * Created by Allan Wang on 2017-05-31. Mapping of the available assets The enum name must match the - * css file name + * js file name */ enum class JsAssets(private val singleLoad: Boolean = true) : InjectorContract { MENU, - MENU_QUICK(singleLoad = false), CLICK_A, CONTEXT_A, MEDIA, diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt index a0406a82f..9af3a5017 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt @@ -46,7 +46,6 @@ import com.pitchedapps.frost.web.FrostWebClientEntryPoint import com.pitchedapps.frost.web.FrostWebComponentBuilder import com.pitchedapps.frost.web.FrostWebEntryPoint import com.pitchedapps.frost.web.FrostWebViewClient -import com.pitchedapps.frost.web.FrostWebViewClientMenu import com.pitchedapps.frost.web.FrostWebViewClientMessenger import com.pitchedapps.frost.web.NestedWebView import dagger.hilt.EntryPoints @@ -107,7 +106,6 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 frostWebClient = when (parent.baseEnum) { FbItem.MESSENGER -> FrostWebViewClientMessenger(this) - FbItem.MENU -> FrostWebViewClientMenu(this) else -> clientEntryPoint.webClient() } webViewClient = frostWebClient diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt index 5c0b0ba4f..79c2794b6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt @@ -32,8 +32,8 @@ import com.pitchedapps.frost.utils.isIndependent import com.pitchedapps.frost.utils.launchImageActivity import com.pitchedapps.frost.utils.showWebContextMenu import com.pitchedapps.frost.views.FrostWebView -import javax.inject.Inject import kotlinx.coroutines.launch +import javax.inject.Inject /** Created by Allan Wang on 2017-06-01. */ @FrostWebScoped @@ -87,7 +87,7 @@ internal constructor( activity.showWebContextMenu( WebContext(url.takeIf { it.isIndependent }, text), fbCookie, - prefs + prefs, ) } } @@ -136,10 +136,8 @@ internal constructor( @JavascriptInterface fun isReady() { - if (web.frostWebClient !is FrostWebViewClientMenu) { - L.v { "JSI is ready" } - refreshEmit(false) - } + L.v { "JSI is ready" } + refreshEmit(false) } @JavascriptInterface @@ -168,5 +166,6 @@ internal constructor( this.isScrolling = scrolling } - @JavascriptInterface fun isScrolling(): Boolean = isScrolling + @JavascriptInterface + fun isScrolling(): Boolean = isScrolling } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt index 407bbe11f..66dcccbf8 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -271,49 +271,6 @@ private const val EMIT_ID = 0b10 private const val EMIT_COMPLETE = EMIT_THEME or EMIT_ID private const val EMIT_FINISH = 0 -/** Client variant for the menu view */ -class FrostWebViewClientMenu(web: FrostWebView) : FrostWebViewClient(web) { - - override fun onPageFinished(view: WebView, url: String?) { - super.onPageFinished(view, url) - if (url == null) { - return - } - jsInject(JsAssets.MENU, prefs = prefs) - } - - /* - * We do not inject headers as they include the menu flyout. - * Instead, we remove the flyout margins within the js script so that it covers the header. - */ - override val facebookJsInjectors: List = - super.facebookJsInjectors - CssHider.HEADER + CssAsset.Menu - - override fun emit(flag: Int) { - super.emit(flag) - when (flag) { - EMIT_FINISH -> { - super.injectAndFinish() - } - } - } - - /* - * Facebook doesn't properly load back to the menu even in standard browsers. - * Instead, if we detect the base soft url, we will manually click the menu item - */ - override fun doUpdateVisitedHistory(view: WebView, url: String?, isReload: Boolean) { - super.doUpdateVisitedHistory(view, url, isReload) - if (url?.startsWith(FbItem.MENU.url) == true) { - jsInject(JsAssets.MENU_QUICK, prefs = prefs) - } - } - - override fun onPageFinishedActions(url: String) { - // Skip - } -} - class FrostWebViewClientMessenger(web: FrostWebView) : FrostWebViewClient(web) { override fun onPageFinished(view: WebView, url: String?) { diff --git a/app/src/web/ts/menu.ts b/app/src/web/ts/menu.ts deleted file mode 100644 index 5b3e6fa93..000000000 --- a/app/src/web/ts/menu.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Click menu after delay and notify -(function () { - const viewport = document.querySelector("#viewport"); - const root = document.querySelector("#root"); - const bookmarkJewel = document.querySelector("#bookmarks_jewel"); - if (!viewport || !root || !bookmarkJewel) { - console.log('Menu.js: main elements not found'); - Frost.emit(0); - return - } - const menuA = bookmarkJewel.querySelector("a"); - if (!menuA) { - console.log('Menu.js: menu links not found'); - Frost.emit(0); - return - } - const jewel = document.querySelector('#mJewelNav'); - if (!jewel) { - console.log('Menu.js: jewel is null'); - return - } - - // Js handling is a bit slow so we need to wait - setTimeout(() => { - menuA.click(); - console.log("Menu setup clicked"); - // Reaction is also slow so we need to wait - setTimeout(() => { - Frost.emit(0); - }, 100); - }, 500); -}).call(undefined); diff --git a/app/src/web/ts/menu_quick.ts b/app/src/web/ts/menu_quick.ts deleted file mode 100644 index f7b117a48..000000000 --- a/app/src/web/ts/menu_quick.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Copy of menu.ts without timeouts or notifications -(function () { - const viewport = document.querySelector("#viewport"); - const root = document.querySelector("#root"); - const bookmarkJewel = document.querySelector("#bookmarks_jewel"); - if (!viewport || !root || !bookmarkJewel) { - console.log('Menu.js: main elements not found'); - Frost.emit(0); - return - } - const menuA = bookmarkJewel.querySelector("a"); - if (!menuA) { - console.log('Menu.js: menu links not found'); - Frost.emit(0); - return - } - const jewel = document.querySelector('#mJewelNav'); - if (!jewel) { - console.log('Menu.js: jewel is null'); - return - } - - menuA.click(); -}).call(undefined);