From 039d7a7c199c4d991dd143f3b096a0707100f6a3 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 12 Sep 2021 19:54:31 -0700 Subject: [PATCH] Fix multi account switching --- .../frost/activities/BaseMainActivity.kt | 2 +- .../frost/activities/SettingsActivity.kt | 2 +- .../pitchedapps/frost/facebook/FbCookie.kt | 21 ++++++++++++------- .../com/pitchedapps/frost/utils/Utils.kt | 2 +- .../com/pitchedapps/frost/web/FrostJSI.kt | 2 +- app/src/main/play/en-US/whatsnew | 7 +++---- app/src/main/res/values/styles.xml | 2 +- app/src/main/res/xml/frost_changelog.xml | 8 ++++--- docs/Changelog.md | 4 ++++ 9 files changed, 30 insertions(+), 20 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt index 19e54f688..3766aef73 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -500,7 +500,7 @@ abstract class BaseMainActivity : ) positiveButton(R.string.kau_yes) { this@BaseMainActivity.launch { - fbCookie.logout(this@BaseMainActivity) + fbCookie.logout(this@BaseMainActivity, deleteCookie = true) } } negativeButton(R.string.kau_no) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt index bce3aa486..8bf3345e9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt @@ -233,8 +233,8 @@ class SettingsActivity : KPrefActivity() { @SuppressLint("MissingSuperCall") override fun onCreate(savedInstanceState: Bundle?) { - activityThemer.setFrostTheme(forceTransparent = true) super.onCreate(savedInstanceState) + activityThemer.setFrostTheme(forceTransparent = true) animate = prefs.animate themeExterior(false) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt index ea1b09462..1a714374f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt @@ -48,8 +48,11 @@ class FbCookie @Inject internal constructor( ) { companion object { - private const val FB_COOKIE_DOMAIN = HTTPS_FACEBOOK_COM - private const val MESSENGER_COOKIE_DOMAIN = HTTPS_MESSENGER_COM + /** + * Domain information. Dot prefix still matters for Android browsers. + */ + private const val FB_COOKIE_DOMAIN = ".$FACEBOOK_COM" + private const val MESSENGER_COOKIE_DOMAIN = ".$MESSENGER_COM" } /** @@ -135,22 +138,24 @@ class FbCookie @Inject internal constructor( * Helper function to remove the current cookies * and launch the proper login page */ - suspend fun logout(context: Context) { + suspend fun logout(context: Context, deleteCookie: Boolean = true) { val cookies = arrayListOf() if (context is Activity) cookies.addAll(context.cookies().filter { it.id != prefs.userId }) - logout(prefs.userId) + logout(prefs.userId, deleteCookie) context.launchLogin(cookies, true) } /** * Clear the cookies of the given id */ - suspend fun logout(id: Long) { + suspend fun logout(id: Long, deleteCookie: Boolean = true) { L.d { "Logging out user" } - cookieDao.deleteById(id) - L.d { "Fb cookie deleted" } - L._d { id } + if (deleteCookie) { + cookieDao.deleteById(id) + L.d { "Fb cookie deleted" } + L._d { id } + } reset() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index ec8aec6c0..4ba872098 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -133,7 +133,7 @@ private inline fun Context.launchWebOverlay if (argUrl.isFacebookUrl && argUrl.contains("/logout.php")) { L.d { "Logout php found" } ctxCoroutine.launch { - fbCookie.logout(this@launchWebOverlayImpl) + fbCookie.logout(this@launchWebOverlayImpl, deleteCookie = false) } } else if (!(prefs.linksInDefaultApp && resolveActivityForUri(Uri.parse(argUrl)))) { startActivity( 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 0d7bbb79d..9a853dae3 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt @@ -121,7 +121,7 @@ class FrostJSI(val web: FrostWebView) { fun loadLogin() { L.d { "Sign up button found; load login" } context.ctxCoroutine.launch { - fbCookie.logout(context) + fbCookie.logout(context, deleteCookie = false) } } diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index dc12e80ed..1f46ec044 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -1,5 +1,4 @@ -v3.0.0 +v3.1.0 -* Removed email support. Please use GitHub for all inquiries as I no longer have time to look through all emails -* Added initial support for messenger.com (settings > appearance > main activity tabs) -* Fix swipe to refresh not disabling for certain pages \ No newline at end of file +* Fix multi account signin +* Only clear out cookies on explicit logout; Facebook logout redirects no longer erase cookies \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index fcacacc3d..17b12dcc8 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -49,7 +49,7 @@ diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index bdece3ae7..9a917099e 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -6,13 +6,15 @@ --> + + + + + - - - diff --git a/docs/Changelog.md b/docs/Changelog.md index 9f4712c57..346b70871 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,5 +1,9 @@ # Changelog +## v3.1.0 +* Fix multi account signin +* Only clear out cookies on explicit logout; Facebook logout redirects no longer erase cookies + ## v3.0.0 * Removed email support. Please use GitHub for all inquiries as I no longer have time to look through all emails * Added initial support for messenger.com (settings > appearance > main activity tabs)