Deze vertaling is niet volledig. Help dit artikel te vertalen vanuit het Engels.
Met de Firefox OS desktop client, ook wel de B2G desktop client genoemd, kunt u Gaia en Web apps in een Gecko-gebaseerde omgeving wat lijkt op een echt apperaat. 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 your 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.
Note: The easiest way to use the Firefox OS desktop client is to use the Firefox OS Simulator. It does not require you to build the desktop client yourself.
Download a nightly build
Note: Firefox OS version 1.0 is based on a branch of Gecko 18. There are also nightly builds based on mozilla-central
here:
https://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/latest-mozilla-central/
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. This lets you bypass having to build it yourself. In addition, you don't have to download Gaia on your own either.
Be sure to install the application in a writeable location; the application needs to be able to update included the Gaia profile.
You can now skip ahead to Running the desktop client, unless you actually want to build it for yourself.
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 https://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:
. "$topsrcdir/b2g/config/mozconfigs/common" 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).
Downloading Gaia
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.
To download Gaia for the first time, let's clone the source code repository on GitHub:
git clone https://github.com/mozilla-b2g/gaia cd 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 (run in the gaia
directory) will take care of that:
make
This should create a profile
directory below the gaia
directory. The new profile contains a customized extension and other configuration needed to make B2G run properly.
Running the desktop client
Once you've built the client and downloaded Gaia (or downloaded and installed the nightly desktop application), you're ready to fire up the Firefox OS desktop client.
Running on Linux
To run the desktop client on Linux using the embedded Gaia profile, just run the b2g
executable. If you want to specify a different Gaia profile, you need to bypass the b2g
wrapper program and run the b2g-bin
binary. The binary is in the archive you downloaded earlier or in the ../build/dist/bin
directory if you built the client yourself.
.../b2g-bin -profile gaia/profile
You may experience annoying rendering problems. To avoid them, add the following line to your gaia/profile/user.js
file:
user_pref("layers.acceleration.disabled", true);
Running on Mac
If you downloaded the nightly build, you can simply launch it from the Finder as usual. Any console output is visible by running the standard Console utility program included with your Mac.
If you want to specify a different Gaia profile, you need to bypass the b2g
wrapper program and run the b2g-bin
binary. The command line is slightly more complicated due to the location of the b2g-bin
binary and the need for absolute paths when specifying the profile directory:
.../B2G.app/Contents/MacOS/b2g-bin -profile /full/path/to/gaia/profile
Running on Windows
Running the nightly build on Windows is as simple as launching b2g.exe
. If you want to customize the execution, you can do so by running the b2g-bin.exe
executable instead; this bypasses the wrapper program that automatically uses the bundled Gaia.
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-bin -jsconsole -profile /path/to/your/profile
Note: On production builds of Firefox OS, console logging (such as by console.log()
) is disabled by default. In order to enable it, open the Settings app and navigate down through Device Information->More Information->Developer, then toggle on the "Console Enabled" preference.
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-bin -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 in Settings application. 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.
- ESC key performs the same function as the "back" button.
- Home key performs the same function as the "home" button; if you're on a Mac, Home key is available as Fn+← (Fn + Left Arrow).
- End key performs the same function as the "power" button; if you're on a Mac, End key is available as Fn+→ (Fn + Right Arrow).
- Page Up and Page Down keys perform the same function as "Volume Up" and "Volume Down" buttons respectively; if you're on a Mac, Page Up key is available as Fn+↑ (Fn + Up Arrow) and Page Down key is available as Fn+↓ (Fn + Down Arrow).
- Long press to Home key opens the "Card View"; if you're on Mac, Cmd+Fn+← (Cmd + Fn + Left Arrow) opens the "Card View".
Next steps
Now that you have a desktop build of Boot to Gecko running, you can do testing, development, and other work in it: