From ae6709598ced6fd2eb1e423ff133154258efdcca Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 6 Aug 2019 21:38:39 -0700 Subject: Restrict notification service --- .../com/pitchedapps/frost/settings/Behaviour.kt | 4 +++ .../pitchedapps/frost/settings/Notifications.kt | 42 +++++++++++++++++++--- .../kotlin/com/pitchedapps/frost/utils/Prefs.kt | 2 ++ app/src/main/res/values/strings_pref_behaviour.xml | 4 +++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt index ba5b839b..c4fa4c4d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt @@ -83,6 +83,10 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.exit_confirmation_desc } + checkbox(R.string.web_only, Prefs::webOnly, { Prefs.webOnly = it }) { + descRes = R.string.web_only_desc + } + checkbox(R.string.analytics, Prefs::analytics, { Prefs.analytics = it }) { descRes = R.string.analytics_desc } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt index 4ef76b3b..40b9428d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt @@ -22,6 +22,7 @@ import android.media.RingtoneManager import android.os.Build import android.provider.Settings import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder +import ca.allanwang.kau.kpref.activity.KPrefItemActions import ca.allanwang.kau.kpref.activity.items.KPrefText import ca.allanwang.kau.utils.materialDialog import ca.allanwang.kau.utils.minuteToText @@ -48,6 +49,20 @@ import kotlinx.coroutines.launch @SuppressLint("InlinedApi") fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { + fun KPrefItemActions.leaveWebOnlyDialog() { + if (Prefs.webOnly) { + materialDialog { + title(R.string.leave_web_only_title) + message(R.string.leave_web_only_desc) + positiveButton(R.string.kau_yes) { + Prefs.webOnly = false + reloadSelf() + } + negativeButton(R.string.kau_no) + } + } + } + text( R.string.notification_frequency, Prefs::notificationFreq, @@ -67,10 +82,15 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { } } } + onDisabledClick = { + leaveWebOnlyDialog() + } enabler = { - val enabled = Prefs.notificationsGeneral || Prefs.notificationsInstantMessages - if (!enabled) + val enabled = + !Prefs.webOnly && (Prefs.notificationsGeneral || Prefs.notificationsInstantMessages) + if (!enabled) { scheduleNotifications(-1) + } enabled } textGetter = { minuteToText(it) } @@ -97,12 +117,19 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { reloadByTitle(R.string.notification_frequency) }) { descRes = R.string.notification_general_desc + enabler = { !Prefs.webOnly } + onDisabledClick = { + leaveWebOnlyDialog() + } } checkbox(R.string.notification_general_all_accounts, Prefs::notificationAllAccounts, { Prefs.notificationAllAccounts = it }) { descRes = R.string.notification_general_all_accounts_desc - enabler = Prefs::notificationsGeneral + enabler = { !Prefs.webOnly && Prefs.notificationsGeneral } + onDisabledClick = { + leaveWebOnlyDialog() + } } checkbox(R.string.notification_messages, Prefs::notificationsInstantMessages, @@ -113,12 +140,19 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { reloadByTitle(R.string.notification_frequency) }) { descRes = R.string.notification_messages_desc + enabler = { !Prefs.webOnly } + onDisabledClick = { + leaveWebOnlyDialog() + } } checkbox(R.string.notification_messages_all_accounts, Prefs::notificationsImAllAccounts, { Prefs.notificationsImAllAccounts = it }) { descRes = R.string.notification_messages_all_accounts_desc - enabler = Prefs::notificationsInstantMessages + enabler = { !Prefs.webOnly && Prefs.notificationsInstantMessages } + onDisabledClick = { + leaveWebOnlyDialog() + } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index eb8e4b35..f17645d0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -191,6 +191,8 @@ object Prefs : KPref() { var showCreateFab: Boolean by kpref("show_create_fab", true) + var webOnly: Boolean by kpref("web_only", false) + inline val mainActivityLayout: MainActivityLayout get() = MainActivityLayout(mainActivityLayoutType) diff --git a/app/src/main/res/values/strings_pref_behaviour.xml b/app/src/main/res/values/strings_pref_behaviour.xml index 32188698..890a7531 100644 --- a/app/src/main/res/values/strings_pref_behaviour.xml +++ b/app/src/main/res/values/strings_pref_behaviour.xml @@ -19,6 +19,10 @@ When loading a message thread, trigger a scroll to the bottom of the page rather than loading the page as is. Enable PIP Enable picture in picture videos + Web Only + Having troubles? Enable to use web exclusive features. All parsing and background services will be disabled. + Leave web only mode + Currently in web only mode. Would you like to disable it to continue? Autoplay Settings Open Facebook\'s auto play settings. Note that it must be disabled for PIP to work. Exit Confirmation -- cgit v1.2.3 From 2afb85489e30ce9823234715c32db80cd722677d Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 6 Aug 2019 21:48:07 -0700 Subject: Disable more components if web only --- .../com/pitchedapps/frost/activities/BaseMainActivity.kt | 11 +++++------ .../kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt | 2 +- .../com/pitchedapps/frost/services/FrostRequestService.kt | 7 ++++++- .../com/pitchedapps/frost/services/NotificationService.kt | 4 ++++ 4 files changed, 16 insertions(+), 8 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 05321b69..292db7cc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -635,12 +635,11 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, override fun getPageTitle(position: Int): CharSequence = getString(pages[position].titleId) override fun getItemPosition(fragment: Any) = - if (fragment !is BaseFragment) - POSITION_UNCHANGED - else if (fragment is WebFragment || fragment.valid) - POSITION_UNCHANGED - else - POSITION_NONE + when { + fragment !is BaseFragment -> POSITION_UNCHANGED + fragment is WebFragment || fragment.valid -> POSITION_UNCHANGED + else -> POSITION_NONE + } } override val lowerVideoPadding: PointF diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt index 55fbcd40..c580c9ed 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt @@ -67,7 +67,7 @@ abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, Dyna data: FbItem, position: Int ): BaseFragment { - val fragment = if (!useFallback) base() else WebFragment() + val fragment = if (useFallback || Prefs.webOnly) WebFragment() else base() val d = if (data == FbItem.FEED) FeedSort(Prefs.feedSort).item else data fragment.withArguments( ARG_URL to d.url, diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt index 0d707dae..fe59c421 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostRequestService.kt @@ -31,6 +31,7 @@ import com.pitchedapps.frost.utils.EnumBundle import com.pitchedapps.frost.utils.EnumBundleCompanion import com.pitchedapps.frost.utils.EnumCompanion import com.pitchedapps.frost.utils.L +import com.pitchedapps.frost.utils.Prefs import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -162,13 +163,17 @@ class FrostRequestService : BaseJobService() { override fun onStartJob(params: JobParameters?): Boolean { super.onStartJob(params) + if (Prefs.webOnly) { + L.i { "Web only; skipping request service" } + return false + } val bundle = params?.extras if (bundle == null) { L.eThrow("Launched ${this::class.java.simpleName} without param data") return false } val cookie = bundle.getCookie() - if (cookie.isNullOrBlank()) { + if (cookie.isBlank()) { L.eThrow("Launched ${this::class.java.simpleName} without cookie") return false } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt index 95726974..091fbb4b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt @@ -72,6 +72,10 @@ class NotificationService : BaseJobService() { override fun onStartJob(params: JobParameters?): Boolean { super.onStartJob(params) L.i { "Fetching notifications" } + if (Prefs.webOnly) { + L.i { "Web only mode; skipping notification service" } + return false + } launch { try { sendNotifications(params) -- cgit v1.2.3 From 281124b649304741dd1ad508b90bf056dba1192e Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 6 Aug 2019 22:00:23 -0700 Subject: Fix web only toggle reload --- app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt index 40b9428d..baf2949f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt @@ -56,7 +56,7 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { message(R.string.leave_web_only_desc) positiveButton(R.string.kau_yes) { Prefs.webOnly = false - reloadSelf() + reloadList() } negativeButton(R.string.kau_no) } -- cgit v1.2.3 From 81d357ce0a17a5b11bfb17d3762540c2bd7f11be Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 6 Aug 2019 22:16:33 -0700 Subject: Reduce notification update frequency --- app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt | 3 ++- .../pitchedapps/frost/activities/BaseMainActivity.kt | 5 +++++ .../pitchedapps/frost/services/FrostNotifications.kt | 7 +++++++ .../com/pitchedapps/frost/settings/Behaviour.kt | 5 ++++- .../com/pitchedapps/frost/settings/Notifications.kt | 19 ++++++++----------- .../main/kotlin/com/pitchedapps/frost/utils/Const.kt | 1 + 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt index d6d6faea..41a755d1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt @@ -36,6 +36,7 @@ import com.pitchedapps.frost.db.FrostDatabase import com.pitchedapps.frost.db.NotificationDb import com.pitchedapps.frost.glide.GlideApp import com.pitchedapps.frost.services.scheduleNotifications +import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs import com.pitchedapps.frost.services.setupNotificationChannels import com.pitchedapps.frost.utils.BuildUtils import com.pitchedapps.frost.utils.FrostPglAdBlock @@ -96,7 +97,7 @@ class FrostApp : Application() { setupNotificationChannels(applicationContext) - applicationContext.scheduleNotifications(Prefs.notificationFreq) + scheduleNotificationsFromPrefs() /** * Drawer profile loading logic 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 292db7cc..521049e7 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -83,6 +83,7 @@ import com.pitchedapps.frost.facebook.parsers.SearchParser import com.pitchedapps.frost.facebook.profilePictureUrl import com.pitchedapps.frost.fragments.BaseFragment import com.pitchedapps.frost.fragments.WebFragment +import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs import com.pitchedapps.frost.utils.ACTIVITY_SETTINGS import com.pitchedapps.frost.utils.EXTRA_COOKIES import com.pitchedapps.frost.utils.L @@ -90,6 +91,7 @@ import com.pitchedapps.frost.utils.MAIN_TIMEOUT_DURATION import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.REQUEST_FAB import com.pitchedapps.frost.utils.REQUEST_NAV +import com.pitchedapps.frost.utils.REQUEST_NOTIFICATION import com.pitchedapps.frost.utils.REQUEST_REFRESH import com.pitchedapps.frost.utils.REQUEST_RESTART import com.pitchedapps.frost.utils.REQUEST_RESTART_APPLICATION @@ -493,6 +495,9 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, if (hasRequest(REQUEST_FAB)) { fragmentChannel.offer(lastPosition) } + if (hasRequest(REQUEST_NOTIFICATION)) { + scheduleNotificationsFromPrefs() + } } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt index bb5594fe..cab1311c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt @@ -43,6 +43,7 @@ import com.pitchedapps.frost.facebook.parsers.NotifParser import com.pitchedapps.frost.facebook.parsers.ParseNotification import com.pitchedapps.frost.glide.FrostGlide import com.pitchedapps.frost.glide.GlideApp +import com.pitchedapps.frost.settings.hasNotifications import com.pitchedapps.frost.utils.ARG_USER_ID import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs @@ -321,6 +322,12 @@ data class FrostNotification( NotificationManagerCompat.from(context).notify(tag, id, notif.build()) } +fun Context.scheduleNotificationsFromPrefs(): Boolean { + val shouldSchedule = Prefs.hasNotifications + return if (shouldSchedule) scheduleNotifications(Prefs.notificationFreq) + else scheduleNotifications(-1) +} + fun Context.scheduleNotifications(minutes: Long): Boolean = scheduleJob(NOTIFICATION_PERIODIC_JOB, minutes) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt index c4fa4c4d..1ab53a56 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt @@ -83,7 +83,10 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.exit_confirmation_desc } - checkbox(R.string.web_only, Prefs::webOnly, { Prefs.webOnly = it }) { + checkbox(R.string.web_only, Prefs::webOnly, { + Prefs.webOnly = it + shouldRestartMain() + }) { descRes = R.string.web_only_desc } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt index baf2949f..ccf04935 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt @@ -36,8 +36,8 @@ import com.pitchedapps.frost.activities.SettingsActivity import com.pitchedapps.frost.db.FrostDatabase import com.pitchedapps.frost.db.deleteAll import com.pitchedapps.frost.services.fetchNotifications -import com.pitchedapps.frost.services.scheduleNotifications import com.pitchedapps.frost.utils.Prefs +import com.pitchedapps.frost.utils.REQUEST_NOTIFICATION import com.pitchedapps.frost.utils.frostSnackbar import com.pitchedapps.frost.utils.frostUri import com.pitchedapps.frost.views.Keywords @@ -46,6 +46,10 @@ import kotlinx.coroutines.launch /** * Created by Allan Wang on 2017-06-29. */ + +val Prefs.hasNotifications: Boolean + get() = !webOnly && (notificationsGeneral || notificationsInstantMessages) + @SuppressLint("InlinedApi") fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { @@ -56,7 +60,7 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { message(R.string.leave_web_only_desc) positiveButton(R.string.kau_yes) { Prefs.webOnly = false - reloadList() + reload() } negativeButton(R.string.kau_no) } @@ -78,21 +82,14 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = { initialSelection = options.indexOf(item.pref) ) { _, index, _ -> item.pref = options[index] - scheduleNotifications(item.pref) + setFrostResult(REQUEST_NOTIFICATION) } } } onDisabledClick = { leaveWebOnlyDialog() } - enabler = { - val enabled = - !Prefs.webOnly && (Prefs.notificationsGeneral || Prefs.notificationsInstantMessages) - if (!enabled) { - scheduleNotifications(-1) - } - enabled - } + enabler = { Prefs.hasNotifications } textGetter = { minuteToText(it) } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt index daca9676..5f65bba1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt @@ -32,5 +32,6 @@ const val REQUEST_TEXT_ZOOM = 1 shl 8 const val REQUEST_NAV = 1 shl 9 const val REQUEST_SEARCH = 1 shl 10 const val REQUEST_FAB = 1 shl 11 +const val REQUEST_NOTIFICATION = 1 shl 12 const val MAIN_TIMEOUT_DURATION = 30 * 60 * 1000 // 30 min -- cgit v1.2.3 From 5515d6dd562a28d576a87bdc102914a410b8490c Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 6 Aug 2019 22:22:55 -0700 Subject: Update changelog and apply spotless --- app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt | 1 - app/src/main/play/en-US/whatsnew | 3 ++- app/src/main/res/xml/frost_changelog.xml | 1 + docs/Changelog.md | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt index 41a755d1..2ebdd215 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt @@ -35,7 +35,6 @@ import com.pitchedapps.frost.db.FbTabsDb import com.pitchedapps.frost.db.FrostDatabase import com.pitchedapps.frost.db.NotificationDb import com.pitchedapps.frost.glide.GlideApp -import com.pitchedapps.frost.services.scheduleNotifications import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs import com.pitchedapps.frost.services.setupNotificationChannels import com.pitchedapps.frost.utils.BuildUtils diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index df5c33a5..85921c39 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -4,4 +4,5 @@ v2.3.2 * Update theme * Disable bugsnag completely when opting out of analytics * Filter urls before sending to other apps -* Allow hiding main fab (see settings > newsfeed) \ No newline at end of file +* Allow hiding main fab (see settings > newsfeed) +* Add option to disable non web based behaviour (settings > behaviour) \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 6e23cfb4..3c576a9e 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -13,6 +13,7 @@ + diff --git a/docs/Changelog.md b/docs/Changelog.md index 8c5346f1..58136a77 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -6,6 +6,7 @@ * Disable bugsnag completely when opting out of analytics * Filter urls before sending to other apps * Allow hiding main fab (see settings > newsfeed) +* Add option to disable non web based behaviour (settings > behaviour) ## v2.3.1 * Hide all story panels if enabled -- cgit v1.2.3 From e64c30732b5156144f18db41fcf5a713b1d11deb Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 6 Aug 2019 23:01:43 -0700 Subject: Fix up menu web view look --- .../com/pitchedapps/frost/injectors/JsInjector.kt | 13 +++++++++---- .../pitchedapps/frost/web/FrostWebViewClients.kt | 21 +++++++++++++++------ app/src/main/res/values/strings_pref_behaviour.xml | 9 +++++---- app/src/web/scss/core/_core_bg.scss | 2 +- app/src/web/ts/menu.ts | 3 +++ 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt index 00c7bcfc..13032479 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt @@ -52,14 +52,19 @@ class JsBuilder { val cssMin = css.replace(Regex("\\s*\n\\s*"), "") append("var a=document.createElement('style');") append("a.innerHTML='$cssMin';") - if (tag != null) append("a.id='$tag';") + if (tag != null) { + append("a.id='$tag';") + } append("document.head.appendChild(a);") } - if (js.isNotBlank()) + if (js.isNotBlank()) { append(js) + } } var content = builder.append("}()").toString() - if (tag != null) content = singleInjector(tag, content) + if (tag != null) { + content = singleInjector(tag, content) + } return content } @@ -101,4 +106,4 @@ fun FrostWebViewClient.jsInject(vararg injectors: InjectorContract) = web.jsInje class JsInjector(val function: String) : InjectorContract { override fun inject(webView: WebView) = webView.evaluateJavascript(function, null) -} +} \ No newline at end of file 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 ecedc997..025119aa 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -91,7 +91,7 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { override fun onPageCommitVisible(view: WebView, url: String?) { super.onPageCommitVisible(view, url) injectBackgroundColor() - if (url.isFacebookUrl) + if (url.isFacebookUrl) { view.jsInject( // CssHider.CORE, CssHider.HEADER, @@ -111,8 +111,9 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { JsAssets.CONTEXT_A, JsAssets.MEDIA ) - else + } else { refresh.offer(false) + } } override fun onPageFinished(view: WebView, url: String?) { @@ -212,19 +213,27 @@ class FrostWebViewClientMenu(web: FrostWebView) : FrostWebViewClient(web) { override fun onPageFinished(view: WebView, url: String?) { super.onPageFinished(view, url) - if (url == null) return - if (url.shouldInjectMenu) jsInject(JsAssets.MENU) + if (url == null) { + return + } + if (url.shouldInjectMenu) { + jsInject(JsAssets.MENU) + } } override fun emit(flag: Int) { super.emit(flag) when (flag) { - EMIT_FINISH -> super.injectAndFinish() + EMIT_FINISH -> { + super.injectAndFinish() + } } } override fun onPageFinishedActions(url: String) { v { "Should inject ${url.shouldInjectMenu}" } - if (!url.shouldInjectMenu) injectAndFinish() + if (!url.shouldInjectMenu) { + injectAndFinish() + } } } diff --git a/app/src/main/res/values/strings_pref_behaviour.xml b/app/src/main/res/values/strings_pref_behaviour.xml index 890a7531..d7043aa7 100644 --- a/app/src/main/res/values/strings_pref_behaviour.xml +++ b/app/src/main/res/values/strings_pref_behaviour.xml @@ -19,10 +19,11 @@ When loading a message thread, trigger a scroll to the bottom of the page rather than loading the page as is. Enable PIP Enable picture in picture videos - Web Only - Having troubles? Enable to use web exclusive features. All parsing and background services will be disabled. - Leave web only mode - Currently in web only mode. Would you like to disable it to continue? + + Web Only + Having troubles? Enable to use web exclusive features. All parsing and background services will be disabled. + Leave web only mode + Currently in web only mode. Would you like to disable it to continue? Autoplay Settings Open Facebook\'s auto play settings. Note that it must be disabled for PIP to work. Exit Confirmation diff --git a/app/src/web/scss/core/_core_bg.scss b/app/src/web/scss/core/_core_bg.scss index 17c93b7b..2c76cfaf 100644 --- a/app/src/web/scss/core/_core_bg.scss +++ b/app/src/web/scss/core/_core_bg.scss @@ -6,7 +6,7 @@ html, body, :root, #root, #header, #MComposer, ._1upc, input, ._2f9r, ._59e9, ._ ._5lp5, .container, .subpage, ._5n_f, #static_templates, ._22_8, ._1t4h, ._uoq, ._3qdh, ._8ca, ._3h8i, ._6-l ._2us7, ._6-l ._6-p:not([style*="background-image:"]), ._333v, div.sharerSelector, ._529j, ._305j, ._1pph, ._3t_l, ._4pvz, ._1g05, .acy, ._51-g, ._533c, ._ib-, .sharerAttachmentEmpty, .sharerBottomWrapper, ._24e1, -._3bg5 ._56do, ._5hfh, ._52e-, .mQuestionsPollResultsBar, ._5hoc, ._5oxw, ._32_4, ._1hiz, +._3bg5 ._56do, ._5hfh, ._52e-, .mQuestionsPollResultsBar, ._5hoc, ._5oxw, ._32_4, ._1hiz, ._53_-, ._38do, .bo, .cq, ._234-, ._a-5, ._2zh4, ._15ks, ._3oyc, ._36dc, ._3iyw ._3iyx, ._6bes, ._55wo, ._4-dy, .tlBody, #timelineBody, .timelineX, .timeline, .feed, .tlPrelude, .tlFeedPlaceholder, ._4_d0, .al, ._1gkq, ._5c5b, ._1qxg, ._5luf, ._2new, ._cld, ._3zvb, ._2nk0, .btnD, .btnI, ._2bdb, ._3ci9, diff --git a/app/src/web/ts/menu.ts b/app/src/web/ts/menu.ts index 6f9dbf16..b26e9cc9 100644 --- a/app/src/web/ts/menu.ts +++ b/app/src/web/ts/menu.ts @@ -20,6 +20,9 @@ return } + /* + * Required to remove height restrictions + */ const y = new MutationObserver(() => { viewport.removeAttribute('style'); root.removeAttribute('style'); -- cgit v1.2.3 From 6ab5ee6c839993b5340304dc86d4f43820b734fe Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 7 Aug 2019 23:07:40 -0700 Subject: Add user agent toggle --- app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt | 6 ++++-- .../main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt | 7 ------- .../kotlin/com/pitchedapps/frost/settings/Experimental.kt | 11 +++++++++++ app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt | 2 ++ app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt | 4 ++++ app/src/main/res/values/strings_pref_behaviour.xml | 5 ----- app/src/main/res/values/strings_pref_experimental.xml | 9 +++++++++ app/src/main/res/xml/frost_changelog.xml | 2 +- 8 files changed, 31 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt index f6316470..a83af46c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt @@ -16,6 +16,8 @@ */ package com.pitchedapps.frost.facebook +import com.pitchedapps.frost.utils.Prefs + /** * Created by Allan Wang on 2017-06-01. */ @@ -32,8 +34,8 @@ const val FB_HOME_URL = "${FB_URL_BASE}home.php" 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" // 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" +val USER_AGENT_DESKTOP = + if (Prefs.singleUserAgent) USER_AGENT_MOBILE else "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 diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt index 1ab53a56..ba5b839b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt @@ -83,13 +83,6 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.exit_confirmation_desc } - checkbox(R.string.web_only, Prefs::webOnly, { - Prefs.webOnly = it - shouldRestartMain() - }) { - descRes = R.string.web_only_desc - } - checkbox(R.string.analytics, Prefs::analytics, { Prefs.analytics = it }) { descRes = R.string.analytics_desc } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt index 7aac7526..3c43bc47 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt @@ -52,6 +52,17 @@ fun SettingsActivity.getExperimentalPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.verbose_logging_desc } + checkbox(R.string.web_only, Prefs::webOnly, { + Prefs.webOnly = it + shouldRestartMain() + }) { + descRes = R.string.web_only_desc + } + + checkbox(R.string.single_user_agent, Prefs::singleUserAgent, { Prefs.singleUserAgent }) { + descRes = R.string.single_user_agent_desc + } + plainText(R.string.restart_frost) { descRes = R.string.restart_frost_desc onClick = { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index f17645d0..3f844653 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -193,6 +193,8 @@ object Prefs : KPref() { var webOnly: Boolean by kpref("web_only", false) + var singleUserAgent: Boolean by kpref("single_user_agent", false) + inline val mainActivityLayout: MainActivityLayout get() = MainActivityLayout(mainActivityLayoutType) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt index 09796b15..14f49bd1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -33,6 +33,7 @@ import com.pitchedapps.frost.db.CookieEntity import com.pitchedapps.frost.facebook.FB_LOGIN_URL import com.pitchedapps.frost.facebook.FB_USER_MATCHER import com.pitchedapps.frost.facebook.FbCookie +import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.injectors.CssHider import com.pitchedapps.frost.injectors.jsInject @@ -57,6 +58,9 @@ class LoginWebView @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") private fun setupWebview() { settings.javaScriptEnabled = true + if (Prefs.singleUserAgent) { + settings.userAgentString = USER_AGENT_MOBILE + } setLayerType(View.LAYER_TYPE_HARDWARE, null) webViewClient = LoginClient() webChromeClient = LoginChromeClient() diff --git a/app/src/main/res/values/strings_pref_behaviour.xml b/app/src/main/res/values/strings_pref_behaviour.xml index d7043aa7..32188698 100644 --- a/app/src/main/res/values/strings_pref_behaviour.xml +++ b/app/src/main/res/values/strings_pref_behaviour.xml @@ -19,11 +19,6 @@ When loading a message thread, trigger a scroll to the bottom of the page rather than loading the page as is. Enable PIP Enable picture in picture videos - - Web Only - Having troubles? Enable to use web exclusive features. All parsing and background services will be disabled. - Leave web only mode - Currently in web only mode. Would you like to disable it to continue? Autoplay Settings Open Facebook\'s auto play settings. Note that it must be disabled for PIP to work. Exit Confirmation diff --git a/app/src/main/res/values/strings_pref_experimental.xml b/app/src/main/res/values/strings_pref_experimental.xml index 95d54ff2..161902bb 100644 --- a/app/src/main/res/values/strings_pref_experimental.xml +++ b/app/src/main/res/values/strings_pref_experimental.xml @@ -8,4 +8,13 @@ Enable verbose logging to help with crash reports. Logging will only be sent once an error is encountered, so repeat the issue to notify the dev. This will automatically be disabled if the app restarts. Restart Frost Launch a cold restart for the application. + + + Web Only + Having troubles? Enable to use web exclusive features. All parsing and background services will be disabled. + Leave web only mode + Currently in web only mode. Would you like to disable it to continue? + + Single user agent + Use one user agent across entire app \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 3c576a9e..349d4d83 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -13,7 +13,7 @@ - + -- cgit v1.2.3 From 7ed4ba701e3e29366f2bd73da010398929829d3e Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 7 Aug 2019 23:08:40 -0700 Subject: Restart main after applying --- app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt | 5 ++++- app/src/main/play/en-US/whatsnew | 2 +- docs/Changelog.md | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt index 3c43bc47..0762d87a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt @@ -59,7 +59,10 @@ fun SettingsActivity.getExperimentalPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.web_only_desc } - checkbox(R.string.single_user_agent, Prefs::singleUserAgent, { Prefs.singleUserAgent }) { + checkbox(R.string.single_user_agent, Prefs::singleUserAgent, { + Prefs.singleUserAgent + shouldRestartMain() + }) { descRes = R.string.single_user_agent_desc } diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index 85921c39..21737fa1 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -5,4 +5,4 @@ v2.3.2 * Disable bugsnag completely when opting out of analytics * Filter urls before sending to other apps * Allow hiding main fab (see settings > newsfeed) -* Add option to disable non web based behaviour (settings > behaviour) \ No newline at end of file +* Add many options under settings > experimental to help with recent \ No newline at end of file diff --git a/docs/Changelog.md b/docs/Changelog.md index 58136a77..7992d819 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -6,7 +6,7 @@ * Disable bugsnag completely when opting out of analytics * Filter urls before sending to other apps * Allow hiding main fab (see settings > newsfeed) -* Add option to disable non web based behaviour (settings > behaviour) +* Add many options under settings > experimental to help with recent ## v2.3.1 * Hide all story panels if enabled -- cgit v1.2.3 From b71c73565f551b5bcc2712c3cf8fdcd4a9562095 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 8 Aug 2019 00:08:22 -0700 Subject: Revert user agent changes --- .../main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt | 6 ++---- .../kotlin/com/pitchedapps/frost/settings/Behaviour.kt | 7 +++++++ .../kotlin/com/pitchedapps/frost/settings/Experimental.kt | 14 -------------- app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt | 2 -- .../main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt | 4 ---- app/src/main/play/en-US/whatsnew | 2 +- app/src/main/res/values/strings_pref_behaviour.xml | 5 +++++ app/src/main/res/values/strings_pref_experimental.xml | 9 --------- app/src/main/res/xml/frost_changelog.xml | 2 +- docs/Changelog.md | 2 +- 10 files changed, 17 insertions(+), 36 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt index a83af46c..f6316470 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt @@ -16,8 +16,6 @@ */ package com.pitchedapps.frost.facebook -import com.pitchedapps.frost.utils.Prefs - /** * Created by Allan Wang on 2017-06-01. */ @@ -34,8 +32,8 @@ const val FB_HOME_URL = "${FB_URL_BASE}home.php" 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" // Desktop agent, for pages like messages -val USER_AGENT_DESKTOP = - if (Prefs.singleUserAgent) USER_AGENT_MOBILE else "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Safari/537.36" +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 diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt index ba5b839b..1ab53a56 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt @@ -83,6 +83,13 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.exit_confirmation_desc } + checkbox(R.string.web_only, Prefs::webOnly, { + Prefs.webOnly = it + shouldRestartMain() + }) { + descRes = R.string.web_only_desc + } + checkbox(R.string.analytics, Prefs::analytics, { Prefs.analytics = it }) { descRes = R.string.analytics_desc } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt index 0762d87a..7aac7526 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt @@ -52,20 +52,6 @@ fun SettingsActivity.getExperimentalPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.verbose_logging_desc } - checkbox(R.string.web_only, Prefs::webOnly, { - Prefs.webOnly = it - shouldRestartMain() - }) { - descRes = R.string.web_only_desc - } - - checkbox(R.string.single_user_agent, Prefs::singleUserAgent, { - Prefs.singleUserAgent - shouldRestartMain() - }) { - descRes = R.string.single_user_agent_desc - } - plainText(R.string.restart_frost) { descRes = R.string.restart_frost_desc onClick = { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index 3f844653..f17645d0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -193,8 +193,6 @@ object Prefs : KPref() { var webOnly: Boolean by kpref("web_only", false) - var singleUserAgent: Boolean by kpref("single_user_agent", false) - inline val mainActivityLayout: MainActivityLayout get() = MainActivityLayout(mainActivityLayoutType) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt index 14f49bd1..09796b15 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -33,7 +33,6 @@ import com.pitchedapps.frost.db.CookieEntity import com.pitchedapps.frost.facebook.FB_LOGIN_URL import com.pitchedapps.frost.facebook.FB_USER_MATCHER import com.pitchedapps.frost.facebook.FbCookie -import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.injectors.CssHider import com.pitchedapps.frost.injectors.jsInject @@ -58,9 +57,6 @@ class LoginWebView @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") private fun setupWebview() { settings.javaScriptEnabled = true - if (Prefs.singleUserAgent) { - settings.userAgentString = USER_AGENT_MOBILE - } setLayerType(View.LAYER_TYPE_HARDWARE, null) webViewClient = LoginClient() webChromeClient = LoginChromeClient() diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index 21737fa1..85921c39 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -5,4 +5,4 @@ v2.3.2 * Disable bugsnag completely when opting out of analytics * Filter urls before sending to other apps * Allow hiding main fab (see settings > newsfeed) -* Add many options under settings > experimental to help with recent \ No newline at end of file +* Add option to disable non web based behaviour (settings > behaviour) \ No newline at end of file diff --git a/app/src/main/res/values/strings_pref_behaviour.xml b/app/src/main/res/values/strings_pref_behaviour.xml index 32188698..d7043aa7 100644 --- a/app/src/main/res/values/strings_pref_behaviour.xml +++ b/app/src/main/res/values/strings_pref_behaviour.xml @@ -19,6 +19,11 @@ When loading a message thread, trigger a scroll to the bottom of the page rather than loading the page as is. Enable PIP Enable picture in picture videos + + Web Only + Having troubles? Enable to use web exclusive features. All parsing and background services will be disabled. + Leave web only mode + Currently in web only mode. Would you like to disable it to continue? Autoplay Settings Open Facebook\'s auto play settings. Note that it must be disabled for PIP to work. Exit Confirmation diff --git a/app/src/main/res/values/strings_pref_experimental.xml b/app/src/main/res/values/strings_pref_experimental.xml index 161902bb..95d54ff2 100644 --- a/app/src/main/res/values/strings_pref_experimental.xml +++ b/app/src/main/res/values/strings_pref_experimental.xml @@ -8,13 +8,4 @@ Enable verbose logging to help with crash reports. Logging will only be sent once an error is encountered, so repeat the issue to notify the dev. This will automatically be disabled if the app restarts. Restart Frost Launch a cold restart for the application. - - - Web Only - Having troubles? Enable to use web exclusive features. All parsing and background services will be disabled. - Leave web only mode - Currently in web only mode. Would you like to disable it to continue? - - Single user agent - Use one user agent across entire app \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 349d4d83..3c576a9e 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -13,7 +13,7 @@ - + diff --git a/docs/Changelog.md b/docs/Changelog.md index 7992d819..58136a77 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -6,7 +6,7 @@ * Disable bugsnag completely when opting out of analytics * Filter urls before sending to other apps * Allow hiding main fab (see settings > newsfeed) -* Add many options under settings > experimental to help with recent +* Add option to disable non web based behaviour (settings > behaviour) ## v2.3.1 * Hide all story panels if enabled -- cgit v1.2.3 From b47900cbf82cdb216f7e3bd7961d29b7f6e1e507 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 8 Aug 2019 00:07:15 -0700 Subject: Hardcode const value --- app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt | 7 +++++-- app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt index f6316470..032ff31e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt @@ -29,12 +29,15 @@ 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_MOBILE = +private const val USER_AGENT_MOBILE_CONST = "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" // Desktop agent, for pages like messages -const val USER_AGENT_DESKTOP = +private const val USER_AGENT_DESKTOP_CONST = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Safari/537.36" +const val USER_AGENT_MOBILE = USER_AGENT_DESKTOP_CONST +const val USER_AGENT_DESKTOP = USER_AGENT_DESKTOP_CONST + /** * Animation transition delay, just to ensure that the styles * have properly set in diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt index 09796b15..8e437c29 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -33,6 +33,7 @@ import com.pitchedapps.frost.db.CookieEntity import com.pitchedapps.frost.facebook.FB_LOGIN_URL import com.pitchedapps.frost.facebook.FB_USER_MATCHER import com.pitchedapps.frost.facebook.FbCookie +import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.injectors.CssHider import com.pitchedapps.frost.injectors.jsInject @@ -57,6 +58,7 @@ class LoginWebView @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") private fun setupWebview() { settings.javaScriptEnabled = true + settings.userAgentString = USER_AGENT_MOBILE setLayerType(View.LAYER_TYPE_HARDWARE, null) webViewClient = LoginClient() webChromeClient = LoginChromeClient() -- cgit v1.2.3 From ca9eff5efe56e4ac1d65fda6e3d91dc6235986ac Mon Sep 17 00:00:00 2001 From: theopensourceguy Date: Tue, 13 Aug 2019 11:12:57 +0200 Subject: Obfuscate window tags for JS injection * Generates a random prefix at startup * Obfuscates tags based on their hashCode and a salt generated at startup as well as the generated prefix * Name mappings are logged in debug mode --- .../com/pitchedapps/frost/injectors/JsInjector.kt | 40 +++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt index 13032479..5d8c55e6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt @@ -16,10 +16,14 @@ */ package com.pitchedapps.frost.injectors +import android.util.Log import android.webkit.WebView +import com.pitchedapps.frost.BuildConfig +import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.web.FrostWebViewClient import org.apache.commons.text.StringEscapeUtils import java.util.Locale +import kotlin.random.Random class JsBuilder { private val css = StringBuilder() @@ -38,7 +42,7 @@ class JsBuilder { } fun single(tag: String): JsBuilder { - this.tag = "_frost_${tag.toLowerCase(Locale.CANADA)}" + this.tag = TagObfuscator.obfuscateTag(tag) return this } @@ -106,4 +110,38 @@ fun FrostWebViewClient.jsInject(vararg injectors: InjectorContract) = web.jsInje class JsInjector(val function: String) : InjectorContract { override fun inject(webView: WebView) = webView.evaluateJavascript(function, null) +} + +/** + * Helper object to obfuscate window tags for JS injection. + */ +private object TagObfuscator { + + fun obfuscateTag(tag: String) : String { + val rnd = Random(tag.hashCode() + salt) + val obfuscated = StringBuilder() + .append(prefix) + .append(randomChars(rnd, tag.length)) + L._d { "TagObfuscator: Obfuscating tag '$tag' to '$obfuscated'" } + //if (BuildConfig.DEBUG) { + // return "_frost_${tag.toLowerCase(Locale.CANADA)}" + //} else + return obfuscated.toString() + } + + private val salt by lazy { System.currentTimeMillis() } + + private val prefix by lazy { + val rnd = Random(System.currentTimeMillis()) + val length = rnd.nextInt(10, 16) + randomChars(rnd, length) + } + + private fun randomChars(random: Random, count: Int) : String { + val result = StringBuilder() + for (i in 1..count) { + result.append('a' + random.nextInt(0, 26)) + } + return result.toString() + } } \ No newline at end of file -- cgit v1.2.3 From 06408157dfde2f40c6368c5ab03e46479428f566 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 13 Aug 2019 23:49:04 -0700 Subject: Use one stringbuilder per tag creation and add test --- .../com/pitchedapps/frost/injectors/JsInjector.kt | 37 ++++++++++------------ .../frost/injectors/TagObfuscatorTest.kt | 22 +++++++++++++ 2 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 app/src/test/kotlin/com/pitchedapps/frost/injectors/TagObfuscatorTest.kt diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt index 5d8c55e6..eed2f819 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt @@ -16,13 +16,11 @@ */ package com.pitchedapps.frost.injectors -import android.util.Log import android.webkit.WebView -import com.pitchedapps.frost.BuildConfig +import androidx.annotation.VisibleForTesting import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.web.FrostWebViewClient import org.apache.commons.text.StringEscapeUtils -import java.util.Locale import kotlin.random.Random class JsBuilder { @@ -115,33 +113,30 @@ class JsInjector(val function: String) : InjectorContract { /** * Helper object to obfuscate window tags for JS injection. */ -private object TagObfuscator { +@VisibleForTesting +internal object TagObfuscator { - fun obfuscateTag(tag: String) : String { + fun obfuscateTag(tag: String): String { val rnd = Random(tag.hashCode() + salt) - val obfuscated = StringBuilder() - .append(prefix) - .append(randomChars(rnd, tag.length)) - L._d { "TagObfuscator: Obfuscating tag '$tag' to '$obfuscated'" } - //if (BuildConfig.DEBUG) { - // return "_frost_${tag.toLowerCase(Locale.CANADA)}" - //} else - return obfuscated.toString() + val obfuscated = buildString { + append(prefix) + append('_') + appendRandomChars(rnd, 16) + } + L.v { "TagObfuscator: Obfuscating tag '$tag' to '$obfuscated'" } + return obfuscated } - private val salt by lazy { System.currentTimeMillis() } + private val salt: Long = System.currentTimeMillis() - private val prefix by lazy { + private val prefix: String by lazy { val rnd = Random(System.currentTimeMillis()) - val length = rnd.nextInt(10, 16) - randomChars(rnd, length) + buildString { appendRandomChars(rnd, 8) } } - private fun randomChars(random: Random, count: Int) : String { - val result = StringBuilder() + private fun Appendable.appendRandomChars(random: Random, count: Int) { for (i in 1..count) { - result.append('a' + random.nextInt(0, 26)) + append('a' + random.nextInt(26)) } - return result.toString() } } \ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/injectors/TagObfuscatorTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/injectors/TagObfuscatorTest.kt new file mode 100644 index 00000000..5c316a4a --- /dev/null +++ b/app/src/test/kotlin/com/pitchedapps/frost/injectors/TagObfuscatorTest.kt @@ -0,0 +1,22 @@ +package com.pitchedapps.frost.injectors + +import java.util.UUID +import kotlin.test.Test +import kotlin.test.assertEquals + +class TagObfuscatorTest { + + /** + * The same key should result in the same tag per session + */ + @Test + fun consistentTags() { + val keys = generateSequence { UUID.randomUUID().toString() }.take(10).toSet() + val tags = keys.map { + val tag = generateSequence { TagObfuscator.obfuscateTag(it) }.take(10).toSet() + assertEquals(1, tag.size, "Key $it produced multiple tags: $tag") + tag.first() + } + assertEquals(keys.size, tags.size, "Key set and tag set have different sizes") + } +} -- cgit v1.2.3 From da3f1bb99df7f75e6adc62aa8aae15716033789b Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 13 Aug 2019 23:57:10 -0700 Subject: Move web only to experimental --- app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt | 7 ------- app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt | 7 +++++++ app/src/main/res/values/strings_pref_behaviour.xml | 5 ----- app/src/main/res/values/strings_pref_experimental.xml | 6 ++++++ app/src/main/res/xml/frost_changelog.xml | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt index 1ab53a56..ba5b839b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt @@ -83,13 +83,6 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = { descRes = R.string.exit_confirmation_desc } - checkbox(R.string.web_only, Prefs::webOnly, { - Prefs.webOnly = it - shouldRestartMain() - }) { - descRes = R.string.web_only_desc - } - checkbox(R.string.analytics, Prefs::analytics, { Prefs.analytics = it }) { descRes = R.string.analytics_desc } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt index 7aac7526..d0963665 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Experimental.kt @@ -43,6 +43,13 @@ fun SettingsActivity.getExperimentalPrefs(): KPrefAdapterBuilder.() -> Unit = { // Experimental content starts here ------------------ + checkbox(R.string.web_only, Prefs::webOnly, { + Prefs.webOnly = it + shouldRestartMain() + }) { + descRes = R.string.web_only_desc + } + // Experimental content ends here -------------------- checkbox(R.string.verbose_logging, Prefs::verboseLogging, { diff --git a/app/src/main/res/values/strings_pref_behaviour.xml b/app/src/main/res/values/strings_pref_behaviour.xml index d7043aa7..32188698 100644 --- a/app/src/main/res/values/strings_pref_behaviour.xml +++ b/app/src/main/res/values/strings_pref_behaviour.xml @@ -19,11 +19,6 @@ When loading a message thread, trigger a scroll to the bottom of the page rather than loading the page as is. Enable PIP Enable picture in picture videos - - Web Only - Having troubles? Enable to use web exclusive features. All parsing and background services will be disabled. - Leave web only mode - Currently in web only mode. Would you like to disable it to continue? Autoplay Settings Open Facebook\'s auto play settings. Note that it must be disabled for PIP to work. Exit Confirmation diff --git a/app/src/main/res/values/strings_pref_experimental.xml b/app/src/main/res/values/strings_pref_experimental.xml index 95d54ff2..fad29ff6 100644 --- a/app/src/main/res/values/strings_pref_experimental.xml +++ b/app/src/main/res/values/strings_pref_experimental.xml @@ -8,4 +8,10 @@ Enable verbose logging to help with crash reports. Logging will only be sent once an error is encountered, so repeat the issue to notify the dev. This will automatically be disabled if the app restarts. Restart Frost Launch a cold restart for the application. + + + Web Only + Having troubles? Enable to use web exclusive features. All parsing and background services will be disabled. + Leave web only mode + Currently in web only mode. Would you like to disable it to continue? \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 3c576a9e..6494fdd1 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -13,7 +13,7 @@ - + -- cgit v1.2.3 From f12762c4175e37a6f887ca17a07ddb4fc7508849 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 15 Aug 2019 22:04:22 -0700 Subject: Update changelog --- app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt | 2 +- app/src/main/play/en-US/whatsnew | 3 ++- app/src/main/res/xml/frost_changelog.xml | 4 ++-- docs/Changelog.md | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt index 13032479..40e3827c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt @@ -106,4 +106,4 @@ fun FrostWebViewClient.jsInject(vararg injectors: InjectorContract) = web.jsInje class JsInjector(val function: String) : InjectorContract { override fun inject(webView: WebView) = webView.evaluateJavascript(function, null) -} \ No newline at end of file +} diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index 85921c39..80bd6988 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -5,4 +5,5 @@ v2.3.2 * Disable bugsnag completely when opting out of analytics * Filter urls before sending to other apps * Allow hiding main fab (see settings > newsfeed) -* Add option to disable non web based behaviour (settings > behaviour) \ No newline at end of file +* Add some experimental options to debug login problems (settings > experimental) +* Enforce desktop user agent for now \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 3c576a9e..5ca0bd74 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -13,8 +13,8 @@ - - + + diff --git a/docs/Changelog.md b/docs/Changelog.md index 58136a77..a3e83d35 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -6,7 +6,8 @@ * Disable bugsnag completely when opting out of analytics * Filter urls before sending to other apps * Allow hiding main fab (see settings > newsfeed) -* Add option to disable non web based behaviour (settings > behaviour) +* Add some experimental options to debug login problems (settings > experimental) +* Enforce desktop user agent for now ## v2.3.1 * Hide all story panels if enabled -- cgit v1.2.3