mozilla
Your Search Results

    Using the B2G desktop client

    The Firefox OS desktop client, also called the B2G desktop client, lets you run Gaia and web apps in a Gecko-based environment somewhat similar to an actual device. It doesn't emulate device hardware, so it's not adequate for testing device APIs, and isn't a replacement for testing on actual hardware. However, it does have a several APIs enabled that aren't available on Firefox such as the Contacts and Settings APIs. It can therefore be useful during the development of our application, or while working on the Gaia user interface itself.

    This article covers downloading or building the Firefox OS desktop client, as well as how to use it.

    Download a nightly build

    Just like Firefox Nightlies, the Firefox OS desktop client is built every day from the latest source code. The latest build is available from the Mozilla FTP server. Be sure to pick the latest version and the right archive for your operating system.

    We can now skip ahead to Running the desktop client.

    Building the desktop client

    The first thing we need to do is set up a standard Mozilla build environment. Once we have that, we can pull down the code we'll need and configure to build the Firefox OS desktop client.

    Downloading the code for the first time

    In a directory where we'd like the source code to go, let's clone the mozilla-central repository that contains all of Gecko:

     hg clone http://hg.mozilla.org/mozilla-central
    

    Updating the code

    When we do subsequent builds later, we'll want to make sure we have the latest code. Here's how to pull the latest changes:

    cd mozilla-central
    hg pull -u
    

    Create a mozconfig

    Next, we need to create a mozconfig file in the mozilla-central directory to configure the build system to build the Boot to Gecko client instead of Firefox:

    mk_add_options MOZ_OBJDIR=../build
    mk_add_options MOZ_MAKE_FLAGS="-j9 -s"
    
    ac_add_options --enable-application=b2g
    ac_add_options --disable-libjpeg-turbo
     
    # This option is required if you want to be able to run Gaia's tests
    ac_add_options --enable-tests
    
    # turn on mozTelephony/mozSms interfaces
    # Only turn this line on if you actually have a dev phone
    # you want to forward to. If you get crashes at startup,
    # make sure this line is commented.
    #ac_add_options --enable-b2g-ril

    Building

    Now we're ready to build the desktop client with the following command issued from the mozilla-central directory:

    make -f client.mk
    

    The built client will be placed in the ../build/dist directory (based on the value you specify for MOZ_OBJDIR in the mozconfig file).

    Running the desktop client

    By default the desktop client will show an empty screen because it doesn't know which web app to load initially as the system app. The collection of system apps and default apps that come with Firefox OS is called Gaia.

    Downloading Gaia

    To download Gaia for the first time, let's clone the source code repository on GitHub:

     git clone https://github.com/mozilla-b2g/gaia

    To update an already existing clone of Gaia, we can pull in the latest changes from GitHub:

    cd gaia
    git pull
    

    Generating a profile

    Next we need to set up Gaia's apps for the desktop client. This includes packaging the Gaia apps in the same way like they would be installed on the device, as well as setting up the permissions for the privileged system apps. We do this by generating a profile. The following command will take care of that: The new profile contains a customized extension and other configuration needed to make B2G run properly. So do this in the gaia directory:

    cd gaia
    make
    

    This should create a profile directory below the gaia directory.

    Running on Linux

    To run the desktop client against the Gaia profile we just generate, we simply invoke the b2g binary with the profile parameter. The binary will be located in the tarball we downloaded earlier or in the ../build/dist/bin directory if we built the client ourselves.

    .../b2g -profile gaia/profile
    

    You may experience annoying rendering problems. To avoid them, add the following line to your gaia/profile/prefs.js file:

    user_pref("layers.acceleration.disabled", true);
    

    Running on Mac

    On Mac, the command line is slightly more complicated due to the location of the b2g binary and the need for absolute paths when specifying the profile directory:

    .../B2G.app/Contents/MacOS/b2g -profile /full/path/to/gaia/profile
    

    Command line options

    There are a number of command line options you can use to adjust the runtime experience while using the desktop client. You can get a list by using the -help option. This section covers some of the particularly interesting ones.

    Specifying the screen size

    You can specify the screen size of the device you want to simulate using the --screen option:

    b2g --screen=<width>x<height>[@<dpi>]

    Where <width>, <height>, and <dpi> are fairly self-explanatory parameters: the width and height of the device's screen in pixels and the device resolution in DPI. For example:

    b2g --screen=320x480
    b2g --screen=320x480@160
    

    Optionally, you can specify certain devices by name to simulate their screen size and resolution:

    • iphone
    • ipad
    • nexus_s
    • galaxy_nexus
    • galaxy_tab
    • wildfire
    • tattoo
    • salsa
    • chacha

    Opening the JavaScript console

    You can open the JavaScript console when launching the desktop B2G client by launching it from the command line with the -jsconsole flag. After building, just do:

    .../b2g -jsconsole -profile /path/to/your/profile

    If you've installed the nightly build on a Mac, you can do the following:

    /Applications/B2G.app/Contents/MacOS/b2g -jsconsole -profile /path/to/your/profile

    Launching a specific application at startup

    You can now specify an application to be launched automatically when b2g starts up in the desktop client. This is done as soon as the rest of the system is done loading up. To do this, just use the --runapp option, which takes as a parameter the name of the application to run. For example:

     .../b2g -profile /path/to/your/gaia/profile --runapp email

    Before looking for an app to launch, the specified name is normalized by converting it to all lower case and removing all dashes and spaces. This normalized name is then compared to similarly normalized names from the manifests of available apps' manifests.

    For example, the name of the email app is currently "E-mail", but --runapp email will work because of this normalization.

    If you specify the --runapp option without an argument, or with an empty argument, the b2g client will output to your terminal a list of the known applications as well as a brief usage message.

    Note: Using the --runapp option disables the lock screen as a side effect and does not re-enable it. It's assumed that you won't use this command on a profile on which you will be testing the lock screen, or you will turn it back on manually. Feel free to contribute a patch to change this behavior if it's a problem.

    Usage tips

    This section provides a few helpful tips to using the B2G desktop client.

    • The ESC key performs the same function as the "back" button.
    • The Home key performs the same function as the "home" button; if you're on a Mac, the Home key is available as Fn+← (Fn + Left Arrow).

    Next steps

    Now that you have a desktop build of Boot to Gecko running, you can do testing, development, and other work in it:

    Метки документа и участники

    Contributors to this page: faegga
    Обновлялась последний раз: faegga,
    Скрыть боковую панель