0

I want to provide the app version of my pebble app on its splashscreen. But how can i access it?

Is there a way to access information from the appinfo.json on the watch or in JS? I need at least the version string.

virindh
  • 3,775
  • 3
  • 24
  • 49
r-dent
  • 685
  • 8
  • 22
  • load your that json file in DOM first by ajax and then read it in js i.e. parse it and extract the property that you want and show the value where you need. – KKS Feb 21 '14 at 10:38

2 Answers2

1

The easiest way to get your app version into the C code is to modify the wscript to generate a header file containing it as part of the build process.

User pedrolane on the Pebble forums has provided his wscript as an example which you can find here: https://code.google.com/p/pebble-for-gopro/source/browse/wscript?spec=svn8634d98109cb03c30c4dab52e665c4ac548cb20a&r=8634d98109cb03c30c4dab52e665c4ac548cb20a

Here's the contents of the file. The generate_appinfo function reads in appinfo.json, grabs the versionLabel and writes it to generated/appinfo.h.

import json

top = '.'
out = 'build'

def options(ctx):
    ctx.load('pebble_sdk')

def configure(ctx):
    ctx.load('pebble_sdk')

def build(ctx):
    ctx.load('pebble_sdk')

    def generate_appinfo(task):
        src = task.inputs[0].abspath()
        tgt = task.outputs[0].abspath()

        json_data=open(src)
        data = json.load(json_data)

        f = open(tgt,'w')
        f.write('#ifndef appinfo_h\n')
        f.write('#define appinfo_h\n')
        f.write('#define VERSION_LABEL "' + data["versionLabel"] + '"\n') 
        f.write('#endif\n')
        f.close()

    ctx(
        rule   = generate_appinfo,
        source = 'appinfo.json',
        target = 'generated/appinfo.h',
    )

    ctx.pbl_program(source=ctx.path.ant_glob(['src/**/*.c','generated/**/*.c']),
                includes='generated',
                target='pebble-app.elf')

    ctx.pbl_bundle(elf='pebble-app.elf',
                   js=ctx.path.ant_glob('src/js/**/*.js'))

To use the value, include appinfo.h and use VERSION_LABEL.

matthewtole
  • 3,207
  • 22
  • 19
-1

Another hacky solution without code generation, add the following lines in your main.c :

#include "pebble_app_info.h"
extern const PebbleAppInfo __pbl_app_info;

Then you can get the version of your app like this :

__pbl_app_info.app_version.major
__pbl_app_info.app_version.minor
Gregoire
  • 117
  • 4