-
Notifications
You must be signed in to change notification settings - Fork 330
Bug 1877278 - AC Translations Check for if the Engine is Supported #5544
Conversation
@@ -39,8 +41,52 @@ class TranslationsMiddleware( | |||
) { | |||
// Pre process actions | |||
when (action) { | |||
// Initially adding the tab | |||
is TabListAction.AddTabAction -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bug is checking and adding to the store for if the engine is supported. (We won't show entryways into the feature if the engine isn't supported.)
Between AddTabAction
(new tab), RestoreAction
(reopening after a shutdown), and SelectTabAction
(reopening after a shutdown and changing tabs), all the possibilities seem to be covered to ensure isEngineSupported
is set on each tab.
We had a conversation about this style flow over here. Please let me know if you have suggestions or ideas!
1873672 will probably use these same actions to initialize the rest of the translations data needs. I'd like to get a stronger sense of how well it works for this case alone first, however we go about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, @MatthewTighe and @gabrielluong, what do you think about this? Is there anything else I should consider or do you think it is good to start testing this option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the amount of research you did, I feel like this is good enough. I don't really have enough context on these actions to provide a better suggestion.
My understanding of what we are trying to achieve here is to make sure all the tabs have this engine supported property set. The only alternative I could see is calling this on-demand for the individual tab that is displayed instead of doing this for all the tabs. If I recall correctly, this alternative was what you first tried to do initially. Did we decide against this?
Do you have a sense of whether or not this operation is expensive? For instance, what happens if an user tries to add/restore 50, 100 or 1000 tabs? This might be worth testing with the debug tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check if the engine is supported per tab?
I was re-reading the description for one of the properties below:
@Property isEngineSupported If the engine supports translations on this device.
and was wondering if we could just set this only once since this seem to indicate whether or not the engine supports translations on the device, which seems like a global state and not based on per tab, but on the user's device. Does the translation engine settings need to fetched per tab or do we only need to know if the engine is ready?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this question about whether the state is global. though it is useful on the one hand to have all the translation state encapsulated in TranslationState
, any global state could definitely move to the top-level browser state or even a BrowserState.translationState
. If you went the latter route, the current TranslationState
may make more sense as SessionTranslationState
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look!
Do we need to check if the engine is supported per tab?
Not necessarily, this won't change once found.
Does the translation engine settings need to fetched per tab or do we only need to know if the engine is ready?
This isEngineSupported
could be a global setting. 100% it is based on the users device and my understanding is it won't change, so once we know, we know. (Only exception might be something like a possible firmware update, but I think that would be an extreme example and generally not easily changed - more details.)
The engine automatically becoming ready is fully managed by Gecko AFAIK currently. They are also managing the new single process 1815339.
LMK how we normally handle something like this and I can refactor for sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you went the latter route, the current TranslationState may make more sense as SessionTranslationState
That could be interesting because supported languages are also not directly tied to the current tab. I'd say download state would probably make sense there too.
(I think there could also be an argument made for the never translate site and languages global settings to be on the global state, but they have a lot of coupling with the page settings, so they probably shouldn't be on a global state and stay tied to one for tabs/sessions.)
Do you have an example of something similar to this I could pattern off of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just looking through BrowserState
, there is global extension state and then tab-specific extension state in TabSessionState
. I'm not really familiar with extensions, but I would be happy to chat through any implementation details if you'd like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks! I'll try following it and see where I end up. (Interestingly, I had to follow a lot of extensions patterns on the GeckoView side as well, so that makes sense too!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look! I followed how WebExtensions managed this as a general pattern to follow and it seems like a better pattern overall and reduces a lot of the weird tab actions. I'm still going to have to figure this out for initializing tabs, but I think the Init
action is perfect for this case and have some new ideas to look into for the tab cases.
fenix/app/src/test/java/org/mozilla/fenix/telemetry/TelemetryMiddlewareTest.kt
Show resolved
Hide resolved
...ser/state/src/main/java/mozilla/components/browser/state/reducer/TranslationsStateReducer.kt
Outdated
Show resolved
Hide resolved
...ponents/browser/state/src/main/java/mozilla/components/browser/state/action/BrowserAction.kt
Outdated
Show resolved
Hide resolved
...e/src/main/java/mozilla/components/browser/state/engine/middleware/TranslationsMiddleware.kt
Outdated
Show resolved
Hide resolved
@@ -39,8 +41,52 @@ class TranslationsMiddleware( | |||
) { | |||
// Pre process actions | |||
when (action) { | |||
// Initially adding the tab | |||
is TabListAction.AddTabAction -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the amount of research you did, I feel like this is good enough. I don't really have enough context on these actions to provide a better suggestion.
My understanding of what we are trying to achieve here is to make sure all the tabs have this engine supported property set. The only alternative I could see is calling this on-demand for the individual tab that is displayed instead of doing this for all the tabs. If I recall correctly, this alternative was what you first tried to do initially. Did we decide against this?
Do you have a sense of whether or not this operation is expensive? For instance, what happens if an user tries to add/restore 50, 100 or 1000 tabs? This might be worth testing with the debug tools.
@@ -39,8 +41,52 @@ class TranslationsMiddleware( | |||
) { | |||
// Pre process actions | |||
when (action) { | |||
// Initially adding the tab | |||
is TabListAction.AddTabAction -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this question about whether the state is global. though it is useful on the one hand to have all the translation state encapsulated in TranslationState
, any global state could definitely move to the top-level browser state or even a BrowserState.translationState
. If you went the latter route, the current TranslationState
may make more sense as SessionTranslationState
TranslationOperation.FETCH_IS_ENGINE_SUPPORTED -> { | ||
scope.launch { | ||
requestEngineSupport(context, action.tabId) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only seeing that this operation is only really dispatched from this middleware, and only really used in this middleware outside of resetting the error state. I'm wondering if we need the additional operation/action dispatch, or if we can just call requestEngineSupport
directly from things like AddTabAction
.
If the isEngineSupported
is global state as per the questions above, could we even maybe use BrowserAction.Init
? I do seem to remember that you looked into that but can't recall the details
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated the pattern!
I can use BrowserAction.Init
now with the tab independent state. The earlier issue was I needed a tabId to set on, if I set per tab. I still might have to figure out alternatives for tab initialization, but BrowserAction.Init
seems much more stable for this patch.
This pull request has conflicts when rebasing. Could you fix it @ohall-m? 🙏 |
@@ -54,4 +55,5 @@ data class BrowserState( | |||
val showExtensionsProcessDisabledPrompt: Boolean = false, | |||
val extensionsProcessDisabled: Boolean = false, | |||
val awesomeBarState: AwesomeBarState = AwesomeBarState(), | |||
val translationEngine: TranslationsBrowserState = TranslationsBrowserState(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had trouble deciding with the naming here, please LMK if you have ideas!
* Indicates an app level translations error occurred and to set the error on | ||
* [BrowserState.translationEngine]. | ||
* | ||
* @property error The error that occurred. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @property error The error that occurred. | |
* @property error The [TranslationError] that occurred. |
We could reference the class where possible if the naming and wording just makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good idea, updated!
@@ -35,6 +35,7 @@ import java.util.Locale | |||
* on application startup e.g. as an indicator that tabs have been restored. | |||
* @property locale The current locale of the app. Will be null when following the system default. | |||
* @property awesomeBarState Holds state for interactions with the [AwesomeBar]. | |||
* @property translationEngine Holds state for translations that apply to the entire browser. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @property translationEngine Holds state for translations that apply to the entire browser. | |
* @property translationEngine Holds translation state that applies to the browser. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ty, updated
@@ -54,4 +55,5 @@ data class BrowserState( | |||
val showExtensionsProcessDisabledPrompt: Boolean = false, | |||
val extensionsProcessDisabled: Boolean = false, | |||
val awesomeBarState: AwesomeBarState = AwesomeBarState(), | |||
val translationEngine: TranslationsBrowserState = TranslationsBrowserState(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val translationEngine: TranslationsBrowserState = TranslationsBrowserState(), | |
val translationsEngineState: TranslationsEngineState = TranslationsEngineState(), |
wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh, should have mentioned, the name of the class that the engine reports the tab state on is TranslationEngineState
(singular).
Currently have:
- TranslationsState - This is the session one.
- TranslationEngineState - This is information GeckoView reports about the session that is set on the session state.
For this one, I really struggled to find a new name:
TranslationsBrowserEngineState
? TranslationsAppState
? TranslationsEngineStatus
? I keep struggling on this one to avoid a naming collision or something that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe TranslationsState
should become TabTanslationsState
or TranslationsSessionState
. Otherwise, TranslationsBrowState
is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll leave TranslationsBrowserState
for now, thanks for taking a look!
Agreed, I'll add a code health bug to refactor TranslationsState
-> TranslationsSessionState
. I think that'll help keep things more clear. Filed the session refactor naming to bug 1880352.
/** | ||
* Value type that represents the state of the translations engine within a [BrowserState]. | ||
* | ||
* @property isEngineSupported The translations engine supports the device architecture. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @property isEngineSupported The translations engine supports the device architecture. | |
* @property isEngineSupported Whether the translations engine supports the device architecture. |
Just extra wording to indicate it is a boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ty, nice wording
* Value type that represents the state of the translations engine within a [BrowserState]. | ||
* | ||
* @property isEngineSupported The translations engine supports the device architecture. | ||
* @property engineError If the translations engine has a global error state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @property engineError If the translations engine has a global error state. | |
* @property engineError Holds the error state of the translations engine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, ty!
/** | ||
* Could not determine if the translations engine works on the device architecture. | ||
* | ||
* @param cause The original throwable before it was converted into this error state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param cause The original throwable before it was converted into this error state. | |
* @param cause The original [Throwable] before it was converted into this error state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, ty!
This patch supports the workflow for checking if the device architecture supports translations. This patch adds: * New `TranslationsBrowserState` to hold global translations engine state * New `SetEngineSupportedAction` to set the isEngineSupported value on `TranslationsBrowserState` * New `EngineExceptionAction` to set errors on `TranslationsBrowserState`
@Mergifyio refresh |
✅ Pull request refreshed |
This patch supports the workflow for checking if the device architecture supports translations.
This patch adds:
TranslationsBrowserState
to hold global translations engine stateSetEngineSupportedAction
to set the isEngineSupported value onTranslationsBrowserState
EngineExceptionAction
to set errors onTranslationsBrowserState
Pull Request checklist
After merge
To download an APK when reviewing a PR (after all CI tasks finished running):
Checks
at the top of the PR page.firefoxci-taskcluster
group on the left to expand all tasks.build-apk-{fenix,focus,klar}-debug
task you're interested in.View task in Taskcluster
in the newDETAILS
section.GitHub Automation
https://bugzilla.mozilla.org/show_bug.cgi?id=1877278