SmartTwitchTV icon indicating copy to clipboard operation
SmartTwitchTV copied to clipboard

Handle URLs

Open Shagon94 opened this issue 2 years ago • 10 comments

Is your feature request related to a problem? Please describe.

IT would be nice if the app had supported URLs - that in turn would allow for a nice home-assistant integration - allowing the app to be turned via another app.

Describe the solution you'd like

Something like:

        <!-- Accepts URIs that begin with "smarttwitchtv://open” -->
        <data android:scheme="smarttwitchtv"
              android:host="open" />

Describe alternatives you've considered

None

Additional context

In home-assistant you can open apps, so for example to turn on plex or youtube:

     - show_name: true
        show_icon: true
        type: button
        icon: mdi:youtube
        tap_action:
          action: call-service
          service: remote.turn_on
          data:
            activity: vnd.youtube://
          target:
            entity_id: remote.atvremote
        hold_action:
          action: none
      - show_name: true
        show_icon: true
        type: button
        icon: mdi:plex
        tap_action:
          action: call-service
          service: remote.turn_on
          data:
            activity: plex://
          target:
            entity_id: remote.atvremote
        hold_action:
          action: none

I basically reference plex:// to open plex and vnd.youtube:// to open youtube. Having this would allow for even more features - such as allowing SmartTV Client for Twitch to open the URL from the launcher directory to the activity.

Shagon94 avatar Aug 01 '23 14:08 Shagon94

I'll take a look and add on future update.

fgl27 avatar Aug 01 '23 16:08 fgl27

I'd like to have this feature as well for a home-assistant integration. I have some experience developing android apps and might be able to develop the android side for this. @fgl27 any pointers about what would need to be changed, how to pass the url data to the webview?

SebRut avatar Sep 22 '24 08:09 SebRut

You can send the url to js calling a new method here

https://github.com/fgl27/SmartTwitchTV/blob/13551871e787dcd8a2b59d57fff059ab0a8b25be/app/specific/Main.js#L193

If you go to the java code you can see examples of smartTwitchTV calls.

fgl27 avatar Sep 22 '24 12:09 fgl27

If you wanna to test a js method you can follow this

https://github.com/fgl27/SmartTwitchTV?tab=readme-ov-file#inside-the-apk

fgl27 avatar Sep 22 '24 12:09 fgl27

Seems like I'm not able to build the app without requiring bigger changes. Seems like https://github.com/GCX-HCI/tray is deprecated and not available from repositories anymore.

SebRut avatar Sep 23 '24 18:09 SebRut

Are you sure? Can see the errors?

I build just fine

fgl27 avatar Sep 23 '24 19:09 fgl27

This is the error im getting:

Configuration cache state could not be cached: field `__librarySourceSets__` of task `:app:mapDebugSourceSetPaths` of type `com.android.build.gradle.tasks.MapSourceSetPathsTask`: error writing value of type 'org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection'
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find net.grandcentrix.tray:tray:0.12.0.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/net/grandcentrix/tray/tray/0.12.0/tray-0.12.0.pom
       - https://repo.maven.apache.org/maven2/net/grandcentrix/tray/tray/0.12.0/tray-0.12.0.pom
       - https://plugins.gradle.org/m2/net/grandcentrix/tray/tray/0.12.0/tray-0.12.0.pom
       - https://oss.sonatype.org/content/repositories/snapshots/net/grandcentrix/tray/tray/0.12.0/tray-0.12.0.pom
     Required by:
         project :app

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

If you're using the same machine regularly the library might still be in local gradle cache. You could try ./gradlew :app:assembleDebug --refresh-dependencies to trigger a build with redownloaded dependencies.

Checking https://mvnrepository.com/artifact/net.grandcentrix.tray/tray/0.12.0 also indicates that the dependency is not present in any of the usual repositories.

SebRut avatar Sep 23 '24 19:09 SebRut

I fix that also check this as that is the next error

https://github.com/fgl27/SmartTwitchTV/commit/b421b6a504a922da1e0bfd53a29610801c84ff29

fgl27 avatar Sep 23 '24 20:09 fgl27

@fgl27 I'm able to build and run the app now (after commenting out the Firebase/Crashlytics stuff in PlayerActivity too) and can parse deeplink intents. But tbh I'm a bit lost in how to use the extracted data. It seems like "starting a stream" from the deeplink info for example could happen here https://github.com/fgl27/SmartTwitchTV/blob/master/apk/app/src/main/java/com/fgl27/twitch/PlayerActivity.java#L1520 . But in my understanding the web app more or less always expects some web state to exist when performing actions, so that there's no easy "open this channels page in the web app" command yet. Am I missing something or are there any pointers on what could be called in the web app side of the app?

SebRut avatar Sep 26 '24 03:09 SebRut

The app can receive an intent when it is not running, in that scenario it saves the intent, so when the app opens it can send that intent to the webview... seems odd as the intent opens the app, but when it does the webview or PlayerActivity are not yet running.

We already have intents from the home screen

https://github.com/fgl27/SmartTwitchTV/blob/25a592bee5fa96451adfc93ddf04b023cdc15d42/apk/app/src/main/java/com/fgl27/twitch/channels/ChannelsUtils.java#L280

To mod this you will need

  • Add an extra to the intent… new Gson().toJson(new PreviewObj("URL_FROM_INTENT", "URL", 0))
  • Make sure the action is defined and can be properly filtered
  • New boolean similar to isChannelIntent but isURLIntent for the action
  • Update some boolean checks to make sure the intent is saved and retrievable by the web implementation

Here I will add the new type handle to deal with all the URL https://github.com/fgl27/SmartTwitchTV/blob/25a592bee5fa96451adfc93ddf04b023cdc15d42/app/specific/Main.js#L3184C27-L3184C31

Make sure once you are done to share with me all possible URLs… Channel, VOD, live, video wherever there is. If it is needed to evaluate if it is live or just channel, all of that will be done by that new intent JS code.

is a little confusing but the app is not ready to receive a random intent, once this is done I can improve to make things easier to understand and make the handle of multiple intents simpler, but you make something I check and improve.

fgl27 avatar Sep 26 '24 12:09 fgl27

I saw the merge #227 but testing it does not work. Has this still not been implemented?

Trying to get this to work with Home Assistant so I can launch straight to a specific stream.

skylord123 avatar Oct 06 '25 22:10 skylord123

That is not done yet, you can only launch the application.

fgl27 avatar Oct 07 '25 14:10 fgl27