1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-09-19 23:21:34 +02:00

Add checks before injections (#180)

This commit is contained in:
Allan Wang 2017-08-15 13:46:41 -07:00 committed by GitHub
parent 203305e189
commit 19ec9b543e
3 changed files with 21 additions and 15 deletions

View File

@ -172,10 +172,13 @@ fun Context.createPrivateMediaFile(extension: String) = createPrivateMediaFile("
* @returns {@code true} if activity is resolved, {@code false} otherwise
*/
fun Context.resolveActivityForUri(uri: Uri): Boolean {
if (uri.toString().contains(FACEBOOK_COM) && !uri.toString().contains("intent:")) return false //ignore response as we will be triggering ourself
if (uri.toString().isFacebookUrl && !uri.toString().contains("intent:")) return false //ignore response as we will be triggering ourself
val intent = Intent(Intent.ACTION_VIEW, uri)
if (intent.resolveActivity(packageManager) == null) return false
startActivity(intent)
return true
}
inline val String?.isFacebookUrl
get() = this != null && this.contains(FACEBOOK_COM)

View File

@ -51,7 +51,7 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient
if (url == null) return
L.i("FWV Loading", url)
refreshObservable.onNext(true)
if (!url.contains(FACEBOOK_COM)) return
if (!url.isFacebookUrl) return
if (url.contains("logout.php")) FbCookie.logout(Prefs.userId, { launchLogin(view.context) })
else if (url.contains("login.php")) FbCookie.reset({ launchLogin(view.context) })
}
@ -71,18 +71,19 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient
override fun onPageCommitVisible(view: WebView, url: String?) {
super.onPageCommitVisible(view, url)
injectBackgroundColor()
view.jsInject(
CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons),
CssHider.HEADER,
CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends && IS_FROST_PRO),
Prefs.themeInjector,
CssHider.NON_RECENT.maybe(webCore.url?.contains("?sk=h_chr") ?: false))
if (url.isFacebookUrl)
view.jsInject(
CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons),
CssHider.HEADER,
CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends && IS_FROST_PRO),
Prefs.themeInjector,
CssHider.NON_RECENT.maybe(webCore.url?.contains("?sk=h_chr") ?: false))
}
override fun onPageFinished(view: WebView, url: String?) {
url ?: return
L.i("Page finished", url)
if (!url.contains(FACEBOOK_COM)) {
if (!url.isFacebookUrl) {
refreshObservable.onNext(false)
return
}

View File

@ -15,6 +15,7 @@ import com.pitchedapps.frost.injectors.CssHider
import com.pitchedapps.frost.injectors.jsInject
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.isFacebookUrl
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
@ -55,17 +56,18 @@ class LoginWebView @JvmOverloads constructor(
override fun onPageFinished(view: WebView, url: String?) {
super.onPageFinished(view, url)
val containsFacebook = url?.contains(FACEBOOK_COM) ?: false
checkForLogin(url) { id, cookie -> loginCallback(CookieModel(id, "", cookie)) }
view.jsInject(CssHider.HEADER.maybe(containsFacebook),
CssHider.CORE.maybe(containsFacebook),
Prefs.themeInjector.maybe(containsFacebook),
callback = { if (!view.isVisible) view.fadeIn(offset = WEB_LOAD_DELAY) })
if (url.isFacebookUrl)
view.jsInject(CssHider.HEADER,
CssHider.CORE,
Prefs.themeInjector,
callback = { if (!view.isVisible) view.fadeIn(offset = WEB_LOAD_DELAY) })
else if (!view.isVisible) view.fadeIn()
}
fun checkForLogin(url: String?, onFound: (id: Long, cookie: String) -> Unit) {
doAsync {
if (url == null || !url.contains(FACEBOOK_COM)) return@doAsync
if (!url.isFacebookUrl) return@doAsync
val cookie = CookieManager.getInstance().getCookie(url) ?: return@doAsync
L.d("Checking cookie for login", cookie)
val id = userMatcher.find(cookie)?.groups?.get(1)?.value?.toLong() ?: return@doAsync