Repository navigation
feat(client/android): add Android TV support #2864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
666351b
fc653d1
c53c193
c1246af
cd26068
207f26c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ android { | |
| versionCode 1 | ||
| versionName "1.0" | ||
| } | ||
|
|
||
| buildTypes { | ||
| release { | ||
| minifyEnabled false | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,11 @@ export class AppRoot extends mixinBehaviors( | |
| [AppLocalizeBehavior], | ||
| PolymerElement | ||
| ) { | ||
| constructor() { | ||
| super(); | ||
| this.handleTvDeviceReady = this.handleTvDeviceReady.bind(this); | ||
|
vad612 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| static get template() { | ||
| return html` | ||
| <style> | ||
|
|
@@ -649,12 +654,62 @@ export class AppRoot extends mixinBehaviors( | |
| } | ||
|
|
||
| if (typeof cordova === 'undefined') { | ||
| // If cordova is not defined, we're running in Electron. | ||
| this.platform = 'Electron'; | ||
| // Capacitor exposes its platform on the shared global. Keep the shell | ||
| // host-agnostic so Android TV can enable navigation in either host. | ||
| this.platform = globalThis.Capacitor?.getPlatform?.() || 'Electron'; | ||
| } else { | ||
| // Don't use cordova?.platformId, ReferenceError will be thrown | ||
| this.platform = globalThis.cordova.platformId; | ||
| } | ||
|
|
||
| this.installTvNavigationIfNeeded(); | ||
| } | ||
|
|
||
| connectedCallback() { | ||
| super.connectedCallback(); | ||
| globalThis.document.addEventListener( | ||
| 'outline-android-tv-device-ready', | ||
|
vad612 marked this conversation as resolved.
Outdated
|
||
| this.handleTvDeviceReady | ||
| ); | ||
| this.installTvNavigationIfNeeded(); | ||
| } | ||
|
|
||
| handleTvDeviceReady() { | ||
|
vad612 marked this conversation as resolved.
Outdated
|
||
| this.installTvNavigationIfNeeded(); | ||
| } | ||
|
|
||
| installTvNavigationIfNeeded() { | ||
| if ( | ||
|
vad612 marked this conversation as resolved.
|
||
| !globalThis.window.outlineTvDevice || | ||
| this.tvNavigationLoad || | ||
|
vad612 marked this conversation as resolved.
Outdated
|
||
| this.removeTvNavigation | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| const navigationLoad = import('./tv-navigation.js'); | ||
| this.tvNavigationLoad = navigationLoad; | ||
| navigationLoad | ||
| .then(({installTvNavigation}) => { | ||
|
vad612 marked this conversation as resolved.
Outdated
|
||
| if (this.tvNavigationLoad !== navigationLoad || !this.isConnected) { | ||
| return; | ||
| } | ||
| this.removeTvNavigation = installTvNavigation(this.shadowRoot); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does installTvNavigation do? Can't we always install it? Please explain the tradeoff.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It installs D-pad, activation, Back, and focus handlers and returns a cleanup function. Enabling those handlers on phones or desktop would interfere with normal keyboard navigation, so installation is limited to Android TV |
||
| }) | ||
| .catch(error => { | ||
| console.error('Failed to install Android TV navigation', error); | ||
| }); | ||
| } | ||
|
|
||
| disconnectedCallback() { | ||
| globalThis.document.removeEventListener( | ||
| 'outline-android-tv-device-ready', | ||
|
vad612 marked this conversation as resolved.
Outdated
|
||
| this.handleTvDeviceReady | ||
| ); | ||
| this.tvNavigationLoad = undefined; | ||
| this.removeTvNavigation?.(); | ||
| this.removeTvNavigation = undefined; | ||
| super.disconnectedCallback(); | ||
| } | ||
|
|
||
| setLanguage(languageCode) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.