How can app an detect if it is running inside AppPlayer

289
3
Jump to solution
01-16-2020 05:28 PM
PaulHaakma
Regular Contributor

I noticed the code below inside one of the AppStudio samples (Authentication sample in the SecureStorageHelper file) and it got me thinking, how can an app detect if it is running inside AppPlayer?

I tried dropping that code into the top level of a demo app. When running from my desktop, console logging Appframework.typeOf(parent, type) returned "RootItem". The variable isRunningInPlayer was set to false, which makes sense because the top level item ("App") didn't have a parent. If I ran that from within AppPlayer, it correctly returns isRunningInPlayer as true, but only based on the fact that the root item now actually has a parent. Because console logging out Appframework.typeOf(parent, type) in this case returned "Loader" and not "AppLoader".

Sooooo, can someone perhaps walk me through the logic in the code below? To my thinking, wouldn't it be enough just to test whether the root item has a parent?

Related question, is there a way that an app could (assuming it knew whether it was running in the app player or not) access and use the "portal" from the AppPlayer instead of it's own?

       if (parent) {
            if (AppFramework.typeOf(parent, true) === "AppLoader") {
                var portal = parent.portal
                if (portal) {
                    //console.log("#### AppStudio Player username: " + portal.username)
                    isRunningInPlayer = true
                }
            } else {
                //console.log("#### Different Player")
                isRunningInPlayer = true
            }
        } else {
            isRunningInPlayer = false
        }
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ErwinSoekianto
Esri Regular Contributor

Paul, 

You are correct, that is how you detect if an app is running inside AppStudio Player, and the correct one is AppFramework.typeOf(parent, true) === "Loader" as of AppStudio Player 4.1. 

Having a parent means that, this component is being loaded by a Loader, in this case, it is an AppStudio Player. 

Accessing parent.portal in an app that is running inside AppStudio Player should work and it was working in the previous version, but there is an issue with accessing the parent.portal in AppStudio Player 4.1, thank you for pointing it out! We are working on getting this fixed for AppStudio Player 4.2 that is scheduled for Dev Summit 2020. Feel free to submit an official bug with Esri Technical Support‌ if you want to have it tracked. 

Thank you,

Erwin.

View solution in original post

0 Kudos
3 Replies
ErwinSoekianto
Esri Regular Contributor

Paul, 

You are correct, that is how you detect if an app is running inside AppStudio Player, and the correct one is AppFramework.typeOf(parent, true) === "Loader" as of AppStudio Player 4.1. 

Having a parent means that, this component is being loaded by a Loader, in this case, it is an AppStudio Player. 

Accessing parent.portal in an app that is running inside AppStudio Player should work and it was working in the previous version, but there is an issue with accessing the parent.portal in AppStudio Player 4.1, thank you for pointing it out! We are working on getting this fixed for AppStudio Player 4.2 that is scheduled for Dev Summit 2020. Feel free to submit an official bug with Esri Technical Support‌ if you want to have it tracked. 

Thank you,

Erwin.

0 Kudos
PaulHaakma
Regular Contributor

Thanks Erwin.

As a suggestion, it would be helpful if there were properties available on that Loader object similar to parent.portal that identified the Player and runtime versions. This could help with troubleshooting in certain situations, such as being able to discern which users are on older versions of Player etc.

Cheers,

-Paul

0 Kudos
ErwinSoekianto
Esri Regular Contributor

Paul,

For the ArcGIS Runtime version, you can check by using calling ArcGISRuntimeEnvironment.version on the app, then when the app is running inside the Player, it will tell you the version of the ArcGIS Runtime that is installed on the Player. 

For the AppStudio Player version, you can check it by calling AppFramework.version on the app, that would tell the version of the AppStudio AppFramework that is installed inside the Player, which would correspond to the Player version.

Erwin

0 Kudos