mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-10 04:52:38 +01:00
Update user agent (#1400)
* Rename user agent and update chrome for desktop, resolves #1387 * Rename more basic to desktop * Apply spotless
This commit is contained in:
parent
bf84c42b08
commit
e8c52e6ab1
@ -48,7 +48,7 @@
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/FrostTheme.Overlay.Slide" />
|
||||
<activity
|
||||
android:name=".activities.WebOverlayBasicActivity"
|
||||
android:name=".activities.WebOverlayDesktopActivity"
|
||||
android:configChanges="orientation|screenSize|locale"
|
||||
android:hardwareAccelerated="true"
|
||||
android:label="@string/frost_web"
|
||||
|
@ -58,7 +58,7 @@ import com.pitchedapps.frost.enums.OverlayContext
|
||||
import com.pitchedapps.frost.facebook.FB_URL_BASE
|
||||
import com.pitchedapps.frost.facebook.FbCookie
|
||||
import com.pitchedapps.frost.facebook.FbItem
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
|
||||
import com.pitchedapps.frost.facebook.formattedFbUrl
|
||||
import com.pitchedapps.frost.kotlin.subscribeDuringJob
|
||||
import com.pitchedapps.frost.services.FrostRunnable
|
||||
@ -141,10 +141,10 @@ class FrostWebActivity : WebOverlayActivityBase(false) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant that forces a basic user agent. This is largely internal,
|
||||
* Variant that forces a desktop user agent. This is largely internal,
|
||||
* and is only necessary when we are launching from an existing [WebOverlayActivityBase]
|
||||
*/
|
||||
class WebOverlayBasicActivity : WebOverlayActivityBase(true)
|
||||
class WebOverlayDesktopActivity : WebOverlayActivityBase(true)
|
||||
|
||||
/**
|
||||
* Internal overlay for the app; this is tied with the main task and is singleTop as opposed to singleInstance
|
||||
@ -153,7 +153,7 @@ class WebOverlayActivity : WebOverlayActivityBase(false)
|
||||
|
||||
@SuppressLint("Registered")
|
||||
@UseExperimental(ExperimentalCoroutinesApi::class)
|
||||
open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseActivity(),
|
||||
open class WebOverlayActivityBase(private val forceDesktopAgent: Boolean) : BaseActivity(),
|
||||
ActivityContract, FrostContentContainer,
|
||||
VideoViewHolder, FileChooserContract by FileChooserDelegate() {
|
||||
|
||||
@ -210,8 +210,8 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc
|
||||
}
|
||||
|
||||
with(web) {
|
||||
if (forceBasicAgent) //todo check; the webview already adds it dynamically
|
||||
userAgentString = USER_AGENT_BASIC
|
||||
if (forceDesktopAgent) //todo check; the webview already adds it dynamically
|
||||
userAgentString = USER_AGENT_DESKTOP
|
||||
Prefs.prevId = Prefs.userId
|
||||
launch {
|
||||
if (userId != Prefs.userId)
|
||||
|
@ -19,7 +19,7 @@ package com.pitchedapps.frost.debugger
|
||||
import ca.allanwang.kau.logging.KauLoggerExtension
|
||||
import ca.allanwang.kau.utils.copyFromInputStream
|
||||
import com.pitchedapps.frost.facebook.FB_CSS_URL_MATCHER
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
|
||||
import com.pitchedapps.frost.facebook.get
|
||||
import com.pitchedapps.frost.facebook.requests.call
|
||||
import com.pitchedapps.frost.utils.createFreshDir
|
||||
@ -59,7 +59,7 @@ class OfflineWebsite(
|
||||
* Directory that holds all the files
|
||||
*/
|
||||
val baseDir: File,
|
||||
private val userAgent: String = USER_AGENT_BASIC
|
||||
private val userAgent: String = USER_AGENT_DESKTOP
|
||||
) {
|
||||
|
||||
/**
|
||||
|
@ -29,11 +29,11 @@ const val FB_LOGIN_URL = "${FB_URL_BASE}login"
|
||||
const val FB_HOME_URL = "${FB_URL_BASE}home.php"
|
||||
|
||||
// Default user agent
|
||||
const val USER_AGENT_FULL =
|
||||
const val USER_AGENT_MOBILE =
|
||||
"Mozilla/5.0 (Linux; Android 8.0.0; ONEPLUS A3000) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Mobile Safari/537.36"
|
||||
// Basic user agent; non mobile version
|
||||
const val USER_AGENT_BASIC =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"
|
||||
// Desktop agent, for pages like messages
|
||||
const val USER_AGENT_DESKTOP =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Safari/537.36"
|
||||
|
||||
/**
|
||||
* Animation transition delay, just to ensure that the styles
|
||||
|
@ -22,7 +22,7 @@ import com.pitchedapps.frost.facebook.FB_JSON_URL_MATCHER
|
||||
import com.pitchedapps.frost.facebook.FB_REV_MATCHER
|
||||
import com.pitchedapps.frost.facebook.FB_URL_BASE
|
||||
import com.pitchedapps.frost.facebook.FB_USER_MATCHER
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
|
||||
import com.pitchedapps.frost.facebook.get
|
||||
import com.pitchedapps.frost.kotlin.Flyweight
|
||||
import com.pitchedapps.frost.utils.L
|
||||
@ -97,7 +97,7 @@ internal fun List<Pair<String, Any?>>.withEmptyData(vararg key: String): List<Pa
|
||||
|
||||
internal fun String?.requestBuilder(): Request.Builder {
|
||||
val builder = Request.Builder()
|
||||
.header("User-Agent", USER_AGENT_BASIC)
|
||||
.header("User-Agent", USER_AGENT_DESKTOP)
|
||||
if (this != null)
|
||||
builder.header("Cookie", this)
|
||||
// .cacheControl(CacheControl.FORCE_NETWORK)
|
||||
|
@ -30,7 +30,7 @@ import ca.allanwang.kau.utils.string
|
||||
import ca.allanwang.kau.utils.toast
|
||||
import com.pitchedapps.frost.R
|
||||
import com.pitchedapps.frost.dbflow.loadFbCookie
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
|
||||
|
||||
/**
|
||||
* Created by Allan Wang on 2017-08-04.
|
||||
@ -39,7 +39,7 @@ import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
|
||||
*/
|
||||
fun Context.frostDownload(
|
||||
url: String?,
|
||||
userAgent: String = USER_AGENT_BASIC,
|
||||
userAgent: String = USER_AGENT_DESKTOP,
|
||||
contentDisposition: String? = null,
|
||||
mimeType: String? = null,
|
||||
contentLength: Long = 0L
|
||||
@ -50,7 +50,7 @@ fun Context.frostDownload(
|
||||
|
||||
fun Context.frostDownload(
|
||||
uri: Uri?,
|
||||
userAgent: String = USER_AGENT_BASIC,
|
||||
userAgent: String = USER_AGENT_DESKTOP,
|
||||
contentDisposition: String? = null,
|
||||
mimeType: String? = null,
|
||||
contentLength: Long = 0L
|
||||
|
@ -61,14 +61,14 @@ import com.pitchedapps.frost.activities.SettingsActivity
|
||||
import com.pitchedapps.frost.activities.TabCustomizerActivity
|
||||
import com.pitchedapps.frost.activities.WebOverlayActivity
|
||||
import com.pitchedapps.frost.activities.WebOverlayActivityBase
|
||||
import com.pitchedapps.frost.activities.WebOverlayBasicActivity
|
||||
import com.pitchedapps.frost.activities.WebOverlayDesktopActivity
|
||||
import com.pitchedapps.frost.dbflow.CookieModel
|
||||
import com.pitchedapps.frost.facebook.FACEBOOK_COM
|
||||
import com.pitchedapps.frost.facebook.FBCDN_NET
|
||||
import com.pitchedapps.frost.facebook.FbCookie
|
||||
import com.pitchedapps.frost.facebook.FbItem
|
||||
import com.pitchedapps.frost.facebook.FbUrlFormatter.Companion.VIDEO_REDIRECT
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
|
||||
import com.pitchedapps.frost.facebook.formattedFbUrl
|
||||
import com.pitchedapps.frost.injectors.CssAssets
|
||||
import com.pitchedapps.frost.injectors.JsAssets
|
||||
@ -141,7 +141,7 @@ private inline fun <reified T : WebOverlayActivityBase> Context.launchWebOverlay
|
||||
|
||||
fun Context.launchWebOverlay(url: String) = launchWebOverlayImpl<WebOverlayActivity>(url)
|
||||
|
||||
fun Context.launchWebOverlayBasic(url: String) = launchWebOverlayImpl<WebOverlayBasicActivity>(url)
|
||||
fun Context.launchWebOverlayDesktop(url: String) = launchWebOverlayImpl<WebOverlayDesktopActivity>(url)
|
||||
|
||||
private fun Context.fadeBundle() = ActivityOptions.makeCustomAnimation(
|
||||
this,
|
||||
@ -393,7 +393,7 @@ fun frostJsoup(cookie: String?, url: String) =
|
||||
Jsoup.connect(url).run {
|
||||
if (cookie.isNullOrBlank()) this
|
||||
else cookie(FACEBOOK_COM, cookie)
|
||||
}.userAgent(USER_AGENT_BASIC).get()!!
|
||||
}.userAgent(USER_AGENT_DESKTOP).get()!!
|
||||
|
||||
fun Element.first(vararg select: String): Element? {
|
||||
select.forEach {
|
||||
|
@ -29,8 +29,8 @@ import com.pitchedapps.frost.contracts.FrostContentCore
|
||||
import com.pitchedapps.frost.contracts.FrostContentParent
|
||||
import com.pitchedapps.frost.facebook.FB_HOME_URL
|
||||
import com.pitchedapps.frost.facebook.FbItem
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_FULL
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE
|
||||
import com.pitchedapps.frost.fragments.WebFragment
|
||||
import com.pitchedapps.frost.utils.Prefs
|
||||
import com.pitchedapps.frost.utils.frostDownload
|
||||
@ -38,7 +38,7 @@ import com.pitchedapps.frost.web.FrostChromeClient
|
||||
import com.pitchedapps.frost.web.FrostJSI
|
||||
import com.pitchedapps.frost.web.FrostWebViewClient
|
||||
import com.pitchedapps.frost.web.NestedWebView
|
||||
import com.pitchedapps.frost.web.shouldUseBasicAgent
|
||||
import com.pitchedapps.frost.web.shouldUseDesktopAgent
|
||||
|
||||
/**
|
||||
* Created by Allan Wang on 2017-05-29.
|
||||
@ -66,8 +66,8 @@ class FrostWebView @JvmOverloads constructor(
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun bind(container: FrostContentContainer): View {
|
||||
userAgentString =
|
||||
if (parent.baseEnum == FbItem.MESSAGES || parent.baseUrl.shouldUseBasicAgent) USER_AGENT_BASIC
|
||||
else USER_AGENT_FULL
|
||||
if (parent.baseEnum == FbItem.MESSAGES || parent.baseUrl.shouldUseDesktopAgent) USER_AGENT_DESKTOP
|
||||
else USER_AGENT_MOBILE
|
||||
with(settings) {
|
||||
javaScriptEnabled = true
|
||||
mediaPlaybackRequiresUserGesture = false // TODO check if we need this
|
||||
|
@ -24,7 +24,7 @@ import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.webkit.WebView
|
||||
import ca.allanwang.kau.utils.withAlpha
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_FULL
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE
|
||||
import com.pitchedapps.frost.injectors.CssHider
|
||||
import com.pitchedapps.frost.injectors.jsInject
|
||||
import com.pitchedapps.frost.utils.L
|
||||
@ -55,7 +55,7 @@ class DebugWebView @JvmOverloads constructor(
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
private fun setupWebview() {
|
||||
settings.javaScriptEnabled = true
|
||||
settings.userAgentString = USER_AGENT_FULL
|
||||
settings.userAgentString = USER_AGENT_MOBILE
|
||||
setLayerType(View.LAYER_TYPE_HARDWARE, null)
|
||||
webViewClient = DebugClient()
|
||||
isDrawingCacheEnabled = true
|
||||
|
@ -22,7 +22,7 @@ import com.pitchedapps.frost.activities.WebOverlayActivityBase
|
||||
import com.pitchedapps.frost.contracts.VideoViewHolder
|
||||
import com.pitchedapps.frost.facebook.FbCookie
|
||||
import com.pitchedapps.frost.facebook.FbItem
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
|
||||
import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
|
||||
import com.pitchedapps.frost.facebook.formattedFbUrl
|
||||
import com.pitchedapps.frost.utils.L
|
||||
import com.pitchedapps.frost.utils.Prefs
|
||||
@ -32,7 +32,7 @@ import com.pitchedapps.frost.utils.isIndirectImageUrl
|
||||
import com.pitchedapps.frost.utils.isVideoUrl
|
||||
import com.pitchedapps.frost.utils.launchImageActivity
|
||||
import com.pitchedapps.frost.utils.launchWebOverlay
|
||||
import com.pitchedapps.frost.utils.launchWebOverlayBasic
|
||||
import com.pitchedapps.frost.utils.launchWebOverlayDesktop
|
||||
import com.pitchedapps.frost.views.FrostWebView
|
||||
|
||||
/**
|
||||
@ -76,15 +76,15 @@ fun FrostWebView.requestWebOverlay(url: String): Boolean {
|
||||
if (!Prefs.overlayEnabled) return false
|
||||
if (context is WebOverlayActivityBase) {
|
||||
L.v { "Check web request from overlay" }
|
||||
val shouldUseBasic = url.formattedFbUrl.shouldUseBasicAgent
|
||||
val shouldUseDesktop = url.formattedFbUrl.shouldUseDesktopAgent
|
||||
//already overlay; manage user agent
|
||||
if (userAgentString != USER_AGENT_BASIC && shouldUseBasic) {
|
||||
L.i { "Switch to basic agent overlay" }
|
||||
context.launchWebOverlayBasic(url)
|
||||
if (userAgentString != USER_AGENT_DESKTOP && shouldUseDesktop) {
|
||||
L.i { "Switch to desktop agent overlay" }
|
||||
context.launchWebOverlayDesktop(url)
|
||||
return true
|
||||
}
|
||||
if (userAgentString == USER_AGENT_BASIC && !shouldUseBasic) {
|
||||
L.i { "Switch from basic agent" }
|
||||
if (userAgentString == USER_AGENT_DESKTOP && !shouldUseDesktop) {
|
||||
L.i { "Switch from desktop agent" }
|
||||
context.launchWebOverlay(url)
|
||||
return true
|
||||
}
|
||||
@ -103,9 +103,9 @@ val messageWhitelist: Set<String> =
|
||||
setOf(FbItem.MESSAGES, FbItem.CHAT, FbItem.FEED_MOST_RECENT, FbItem.FEED_TOP_STORIES)
|
||||
.mapTo(mutableSetOf(), FbItem::url)
|
||||
|
||||
val String.shouldUseBasicAgent: Boolean
|
||||
val String.shouldUseDesktopAgent: Boolean
|
||||
get() = when {
|
||||
contains("story.php") -> false // do not use basic for comment section
|
||||
contains("story.php") -> false // do not use desktop for comment section
|
||||
contains("/events/") -> false // do not use for events (namely the map)
|
||||
contains("/messages") -> true // must use for messages
|
||||
else -> false // default to normal user agent
|
||||
|
@ -35,7 +35,6 @@ import com.pitchedapps.frost.facebook.FB_USER_MATCHER
|
||||
import com.pitchedapps.frost.facebook.FbCookie
|
||||
import com.pitchedapps.frost.facebook.get
|
||||
import com.pitchedapps.frost.injectors.CssHider
|
||||
import com.pitchedapps.frost.injectors.JsAssets
|
||||
import com.pitchedapps.frost.injectors.jsInject
|
||||
import com.pitchedapps.frost.utils.L
|
||||
import com.pitchedapps.frost.utils.Prefs
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
## v2.2.4
|
||||
* Show top bar to allow sharing posts
|
||||
* Fix unmuting videos when autoplay is enabled
|
||||
* Add shortcut to toggle autoplay in settings > behaviour
|
||||
* Update theme
|
||||
|
||||
## v2.2.3
|
||||
* Add ability to hide stories
|
||||
@ -9,6 +12,7 @@
|
||||
* Apply notification keyword filter to title as well
|
||||
* Remove round icon settings as they are the default in Facebook
|
||||
* Update theme
|
||||
* Update translations
|
||||
|
||||
## v2.2.2
|
||||
* New marketplace shortcut
|
||||
|
Loading…
Reference in New Issue
Block a user