Bug 1796482 - Report save to PDF errors.

This commit is contained in:
Arturo Mejia 2022-11-01 18:59:56 -04:00 committed by mergify[bot]
parent 1b9a86bfaa
commit 3c70d237d8
3 changed files with 50 additions and 0 deletions

View File

@ -92,6 +92,7 @@ import org.mozilla.fenix.perf.StrictModeManager
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.settings.advanced.getSelectedLocale
import org.mozilla.fenix.share.SaveToPDFMiddleware
import org.mozilla.fenix.telemetry.TelemetryMiddleware
import org.mozilla.fenix.utils.getUndoDelay
import org.mozilla.geckoview.GeckoRuntime
@ -244,6 +245,7 @@ class Core(
LastMediaAccessMiddleware(),
HistoryMetadataMiddleware(historyMetadataService),
SessionPrioritizationMiddleware(),
SaveToPDFMiddleware(context),
)
BrowserStore(

View File

@ -0,0 +1,46 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.share
import android.content.Context
import android.widget.Toast
import android.widget.Toast.LENGTH_LONG
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import mozilla.components.browser.state.action.BrowserAction
import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.lib.state.Action
import mozilla.components.lib.state.Middleware
import mozilla.components.lib.state.MiddlewareContext
import org.mozilla.fenix.R
/**
* [BrowserAction] middleware reacting in response to Save to PDF related [Action]s.
* @property context An Application context.
*/
class SaveToPDFMiddleware(
private val context: Context,
) : Middleware<BrowserState, BrowserAction> {
@OptIn(DelicateCoroutinesApi::class)
override fun invoke(
ctx: MiddlewareContext<BrowserState, BrowserAction>,
next: (BrowserAction) -> Unit,
action: BrowserAction,
) {
if (action is EngineAction.SaveToPdfExceptionAction) {
// See https://github.com/mozilla-mobile/fenix/issues/27649 for more details,
// why a Toast is used here.
GlobalScope.launch(Dispatchers.Main) {
Toast.makeText(context, R.string.unable_to_save_to_pdf_error, LENGTH_LONG).show()
}
} else {
next(action)
}
}
}

View File

@ -1028,6 +1028,8 @@
<string name="share_button_content_description">Share</string>
<!-- Text for the Save to PDF feature in the share menu -->
<string name="share_save_to_pdf">Save as PDF</string>
<!-- Text for error message when generating a PDF file Text for error message when generating a PDF file. -->
<string name="unable_to_save_to_pdf_error">Unable to generate PDF</string>
<!-- Sub-header in the dialog to share a link to another sync device -->
<string name="share_device_subheader">Send to device</string>
<!-- Sub-header in the dialog to share a link to an app from the full list -->