AnsweredAssumed Answered

How can app an detect if it is running inside AppPlayer

Question asked by paul.haakma on Jan 16, 2020
Latest reply on Jan 28, 2020 by ESoekianto-esristaff

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
        }

Outcomes