How to get the current "screen" information

Posted on
  • Hi folks,

    I'm trying to figure out if there's a way to access information about the current "screen" that the Bangle is on. I would like my widget to listen to a button press only when the Bangle is on its default screen/clock face (and NOT when I'm in the Launcher or in a different App) and I'm having trouble accessing that information.

    Is that currently possible at all? I've looked through the Espruino/Banglejs API reference documentation but I might be using the wrong keywords when looking for a solution. If that is currently not possible, could you please point me in the direction of the source code where I could implement this functionality?

    Any help would be much appreciated!

  • Hi,

    There isn't a way of doing this in 2v08 (short of modifying every app to make it declare what it is).

    However I have just added something I have been meaning to do for a while, which is to make the load(filename) function write the file that has just been loaded into a variable. So if you load a cutting edge build, you can now do:

    function getAppType() {
      if (!global.__FILE__) return "clock";
      if (!__FILE__.endsWith(".app.js")) return "app";
      var j = require("Storage").readJSON(__FILE__.sliĀ­ce(0,-7)+".info",1);
      return (j&&j.type)||"app";
    }
    

    So __FILE__ will be the file that has been loaded, however in the default app case (eg load() or long-press BTN3) it'll just be undefined, since no file was supplied.

    So actually if you just want to run this only for the default clock, you can check global.__FILE__===undefined. However in that case if you then explicitly run it from the launcher, __FILE__ will end up getting set.

  • Hi Gordon,

    That is exactly what I'm looking for! Thanks for getting this implemented, I'll have a play around once I get the chance.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to get the current "screen" information

Posted by Avatar for jurelik @jurelik

Actions