How to check if app (electron) is running within a snap env

What would be the easiest way to check within the app (electron) , if app is running as snap? I tried this

try {
  execSync(`snap list ${meta?.name}`,{timeout: 1000, stdio: 'ignore'})
} catch

where meta.name ist the app name, but this returns 126 in the catch() and 127 in env where no snap is installed.

Maybe no good approach.

Which one is better?

Which additional plug would i need?

TIA

How sophisticated do you need? You could just check getenv(“SNAP”)

ty vm. Meanwhile I got a solution (the same with checking env var SNAP_APP_NAME ie).

Sry, for asking. I m pretty new to snappy

1 Like