XULRunner入门

这一节通过使用XULRunner构建一个基本的桌面应用来探讨Mozilla平台。已知的Firefox(“火狐”Web浏览器)、Thunderbird(“雷鸟”Email客户端)和其它多种类应用程序都是使用这个平台编写完成的,可以坚信一点Mozilla平台可以被用来构建基本的应用程序。另有一个名为Creating XULRunner Apps with the Mozilla Build System的章节包含了更加完整的内容用于构建XULRunner应用程序。如果你需要修改XULRunner本身或是将XULRunner整合到外部二进制程序中,那么你需要阅读这个章节。

你能够在MDC里的XULRunner主页中找到下载连接。由于我们并不创建任何的二进制XPCOM组件,所以仅需要下载并安装XULRunner运行时包而不是SDK。

针对WIndows版本下载得到的是一个ZIP文件而并不是真正的安装程序。作为一个开发者我更喜欢这种简单解压缩就可以完成安装的方式。我假设它不会挂接到我的Windows系统上而这是件好事。这同时也意味着XULRunner是“便携式”的,所以如果你将应用开发成一种“便携式”的形式,那么你将可以将程序放到闪存存储器中或在云端同步。

Mac版本的XULRunner被发布成tar.bz2格式的归档文件。你可以解压缩到任何你喜欢的位置,但在本文档中的多个位置都假设了你已经将解压缩得到的文件放置在了/Library/Frameworks目录中。

到从版本11.10开始在Ubuntu桌面系统及它的各种变体版本中(Xubuntu,Kubuntu),XULRunner已经不再被维护并且不存在于Ubuntu的软件仓库中了。因此不管你是想手动编译XULRunner或是从Mozilla's FTP服务器上下载发布版本。一种方法就是在每次你想安装新版本时运行以下脚本:

FIREFOX_VERSION=`grep -Po  "\d{2}\.\d+" /usr/lib/firefox/platform.ini`

ARCH=`uname -p`

XURL=https://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/$FIREFOX_VERSION/runtimes/xulrunner-$FIREFOX_VERSION.en-US.linux-$ARCH.tar.bz2

cd /opt

sudo sh -c "wget -O- $XURL | tar -xj"

sudo ln -s /opt/xulrunner/xulrunner /usr/bin/xulrunner

sudo ln -s /opt/xulrunner/xpcshell /usr/bin/xpcshell

你也应该保存此脚本以便使用。注意:如果你使用的Firefox是构建于Ubuntuzilla仓库的,请将/usr/lib/firefox/platform.ini替换为/opt/firefox/platform.ini。

在Windows系统中将压缩文件解压缩到一个合理的位置。我将其解压缩到了一个新创建的目录中C:\program files\xulrunner。

在Mac系统中将tar.bz2文件解压缩到名为XUL.Framework的目录中。将此目录拷贝到/Library/Frameworks,或是其它你喜欢的位置。

在Linux系统中如果你使用的是预发布(Pre-release)的XULRunner的话,你仅需要解包归档文件即可。

Optionally, if you've downloaded the compressed archive of XULRunner and would like to install it on your system you can do so by running作为可选的步骤,如果你已经下载了XULRunner的压缩文档并想将其安装到你的系统中,你可以运行以下命令来做到这一点

xulrunner --register-global

作为管理名以上命令会将XULRunner注册给本机上的所有用户。仅注册给当前用户可以运行以下命令

xulrunner --register-user

不管你是否执行了安装过程XULRunner都会正常工作。这纯粹是为了方便。

In all systems you should unzip theomni.jafile into some example directory and take a look at all the awesome! First change the file extension to zip and then use your normal filesystem's decompression tool to open it up. The contents of omni.ja are available to XULRunner applications and are what make it possible to build amazing applications easily!

是时候了,我们做一个简单的没有什么功能的应用程序。如果你愿意你可以称它为“Hello World”。所有以下你看到的你都可以在MDC的XULRunner文档中找到更细节的内容。

Hint: Skip ahead and download the sample application, you can experiment with it while following this tutorial. You can download the sample application from https://github.com/matthewkastor/XULRunner-Examples. Please continue reading to learn the "what", "why" and "how" parts of building a XULRunner application.

在Windows中我新创建了root目录在c:\program files\myapp,但你可以将其创建在任何你喜欢的地方,使用任意一种你喜欢的OS。Windows、Mac和Linux使用了相同的目录结构。这里列出了子目录的结构:

+ myapp/

|

+-+ chrome/

| |

| +-+ content/

| | |

| | +-- main.xul

| | |

| | +-- main.js

| |

| +-- chrome.manifest

|

+-+ defaults/

| |

| +-+ preferences/

| |

| +-- prefs.js

|

+-- application.ini

|

+-- chrome.manifest

注意在目录结构中有5个文件:application.ini、chrome.manifest (2个)、 prefs.js和main.xul。/chrome/chrome.manifest文件是可选的,但可能对向下兼容是有用的。请看以下记述内容。

Note: In XULRunner 2.0, the chrome.manifest is now used to register XPCOM components in addition to its previous uses. Part of this change means the /chrome/chrome.manifest is no longer considered the "root" manifest. XULRunner will not check that folder location for a root-level chrome.manifest. You need to move your existing chrome.manifest to the application root folder, remembering to update the relative paths within the file. You could also just create a new application root-level manifest that includes the /chrome/chrome.manifest, which is what this tutorial will do.

application.ini 文件为你的应用扮演着XULRunner入口点的角色。它指定了你的应用打算如何使用XULRunner平台以及配置一些信息以告诉XULRunner如何运行你的程序。下面是我的文件内容:

[App]

Vendor=XULTest

Name=myapp

Version=1.0

BuildID=20100901

ID=xulapp@xultest.org

[Gecko]

MinVersion=1.8

MaxVersion=200.*

Note: MinVersion 和MaxVersion字段指示了你的应用所兼容的Gecko版本的范围;确保你设置了它们而且你所使用的XULRunner的版本也是在这个范围之内,否则你的应用将不能工作。

Note: 确保你的应用名称是小写的,并且长度大于3个字符。

The chrome manifest file is used by XULRunner to define specific URIs which in turn are used to locate application resources. This will become clearer when we see how the “chrome://” URI is used. Application chrome can be in a single or a few JAR files or uncompressed as folders and files. I am using the uncompressed method for now. Here is the chrome/chrome.manifest:

content myapp content/

As mentioned in Step 3, the default location of the chrome.manifest has changed in XULRunner 2.0, so we also need a simple chrome.manifest in the application root which will include the the manifest in our chrome root. Here is the application root chrome.manifest:

manifest chrome/chrome.manifest

The prefs.js file tells XULRunner the name of the XUL file to use as the main window. Here is mine:

pref("toolkit.defaultChromeURI", "chrome://myapp/content/main.xul");

/* debugging prefs, disable these before you deploy your application! */

pref("browser.dom.window.dump.enabled", true);

pref("javascript.options.showInConsole", true);

pref("javascript.options.strict", true);

pref("nglayout.debug.disable_xul_cache", true);

pref("nglayout.debug.disable_xul_fastload", true);

XULRunner specific preferences include:

Specifies the default window to open when the application is launched.

Specifies the features passed to

Allows configuring the application to allow only one instance at a time.

The toolkit preferences are described in further detail in XULRunner:Specifying Startup Chrome Window.

The debugging preferences are discussed in Debugging a XULRunner Application

Finally, we need to create a simple XUL window, which is described in the file main.xul. Nothing fancy here, just the minimum we need to make a window. No menus or anything.

main.xul:

This is a simple XULRunner application. XUL is simple to use and quite powerful and can even be used on mobile devices.

Note: Make sure there is no extra whitespace at the beginning of the XML/XUL file

The application also has a JavaScript file. Most XUL applications will include some external JavaScript, so the sample application does too, just to show how to include it into the XUL file.

main.js:

function showMore() {

document.getElementById("more-text").hidden = false;

}

For more information about XUL see: XUL.

For information about mixing HTML elements into your XUL read Adding HTML Elements.

The moment of truth. We need to get XULRunner to launch the bare-bones application.

From a Windows command prompt opened to the myapp folder, we should be able to execute this:

C:\path\to\xulrunner.exe application.ini

Of course, if you opted to install xulrunner then you could simply do

​%ProgramFiles%\xulrunner.exe application.ini

or on 64 bit systems

​%ProgramFiles(x86)%\xulrunner.exe application.ini

Note: you can also install your application when you're finished debugging it. See XUL Application Packaging for details.

On the Mac, before you can run a XULRunner application with everything intact, you must install it using the --install-app xulrunner commandline flag. Installing the application creates an OS X application bundle:

/Library/Frameworks/XUL.framework/xulrunner-bin --install-app ///myapp.zip

Once installed, you can run the application:

/Library/Frameworks/XUL.framework/xulrunner-bin "/Applications/Finkle/TestApp.app/Contents/Resources/application.ini"

You may run it without installing (but with the menu bar and dock icon missing) in OS X by typing:

/Library/Frameworks/XUL.framework/xulrunner-bin "//TestApp/application.ini"

Note: The full path is required or a "Error: couldn't parse application.ini."-message will be returned.

This might also be simplified using a very simple shell script (i call mine "run.sh"):

#!/bin/sh

/Library/Frameworks/XUL.framework/xulrunner-bin `pwd`/application.ini

On Ubuntu, you can run the application from a terminal. First change into the \myapp folder, then start the application by:

xulrunner application.ini

You should now see a window that looks something like this. This particular screenshot is from Ubuntu 10.

With Firefox 3 and later, you can tell the Firefox executable to run a XUL application from the command line. The XUL application will run instead of the Firefox browser that normally starts. This is similar to starting a XUL app using XULRunner. See Using Firefox to run XULRunner applications. This does not work if Firefox itself was installed as a XUL app - you need to use the installed XULRunner directly.

There are many things you can do with XULRunner. Before you get too far into things you might want to read the XULRunner tips article. Also, throughout this tutorial you've been introduced to various bits of the Toolkit API and it may help you to get familiar with it. Once you've got an application that's ready for the world you'll love our article titled Deploying XULRunner.

For now, click the "next" link to learn about windows and menus in XULRunner!

Original Document Information

Author: Mark Finkle, October 2, 2006

xulrunner html5,XULRunner入门相关推荐

  1. 02.Web大前端时代之:HTML5+CSS3入门系列~H5结构元素

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 1.结构元素 可以理解为语义话标记,比如:以前这么写&l ...

  2. HTML5从入门到精通(明日科技) 中文pdf扫描版

    HTML5从入门到精通(明日科技) 中文pdf扫描版

  3. easyui表单网格列错位_《HTML5从入门到精通》——第3章 HTML表格与表单

    <HTML5从入门到精通> ◎千锋教育高教产品研发部/编著 (清华大学出版社出版) 目 录 第3章 HTML表格与表单................................... ...

  4. 《html5 从入门到精通》读书笔记(一)

    今天看了<html5 从入门到精通>这本书,感觉阅读下来很舒心,不像阅读其他书籍很揪心.html增加的知识点,我觉得非常有价值,看完几章记录了一些内容,不但能巩固,也为下次遗忘知识点做好准 ...

  5. 04. Web大前端时代之:HTML5+CSS3入门系列~HTML5 表单

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 一.input新增类型: 1.tel:输入类型用于应该包 ...

  6. html5 canvas实际应用,Html5 Canvas入门及经典应用

    Html5 Canvas入门及经典应用 时间:2019-02-15     来源:华清远见 canvas想必对于前端的工程师都不陌生了,它是 HTML5 新增的「画布」元素,是HTML5 的一大亮点, ...

  7. html5从基础到入门,Html5从入门到精通系列2:Html5基础

    Html5从入门到精通系列2:Html5基础 (2015-04-04 11:36:53) 标签: html5 html5教程 html5视频教程 html5从入门到精通 2-1.1.HTML5简介.M ...

  8. HTML5从入门到精通(千锋教育)免费电子版+PDF下载

    本书是HTML5初学者极好的入门教材之一,内容通俗易懂.由浅入深.循序渐进.本书内容覆盖全面.讲解详细,其中包括标签语义化.标签使用规范.选择器类型.盒模型.标签分类.样式重置.CSS优化.Photo ...

  9. HTML5菜鸟入门指导:简介、平台搭建、示例演示

    HTML5菜鸟入门指导:简介.平台搭建.示例演示 一.HTML5简介 1.  了解HTML (1).什么是HTML? HTML是用来描述网页的一种语言: HTML指超文本标记语言(Hyper Text ...

最新文章

  1. textureview 旋转90度后平铺_轮滑知识 | 单排轮滑的旋转技巧
  2. [Codeforces513E2]Subarray Cuts
  3. jquery send(data) 对data的处理
  4. android自定义底部中间突出导航栏,Android选中突出背景效果的底部导航栏功能
  5. Redis 缓存过期(maxmemory) 配置/算法 详解
  6. 洛谷P2732 商店购物 Shopping Offers
  7. KeyBlaze for mac(专业打字练习软件)激活版
  8. 【翻译】Motion Blur for mobile devices in Unity
  9. 新科高德发布2009.03版电子眼升级数据升级方法: 1. 新科2440方案机器内
  10. jdk1.8中使用aspectjweaver报错 Invalid byte tag in constant pool 18
  11. 晚上的笔记:p2p vod
  12. CSS动画:梦幻西游
  13. 两个非常不错的在线pdf转epub的网站,没有上传大小限制
  14. (四)激活函数与loss梯度
  15. PacBio hdf5 格式 向 FASTA格式转换
  16. stm32 智能避障小车(二)之sg90
  17. linux不能显示文本文件内容的命令,Linux之文本文件查看命令
  18. ​LeetCode刷题实战488:祖玛游戏
  19. 太极阳支持的Android版本,三星 Android 7.0 无法使用太极阳
  20. 学习方法——TRIZ创新理论中的40个发明原则(一)

热门文章

  1. yum php devel_yum源里找不到 php54w-devel,求可用yum源
  2. tensorflow 显存 训练_【他山之石】训练时显存优化技术——OP合并与gradient checkpoint...
  3. 表格大小设置_系统地学习Excel第18课,设置单元格字体格式
  4. ajax传递excel后台接收,前端上传EXCEL文件,后台servlet怎么获取EXCEL中的数据
  5. java搭配oracle,Java联接Oracle(高级篇)
  6. 09945 oracle 解决方法_ORACLE rman与RMAN-00054ORA-09945
  7. IPV6地址校验(java)
  8. 笔记-信息化与系统集成技术-人工智能的特点
  9. 笔记-信息系统安全管理-信息系统的安全属性
  10. 笔记-高项案例题-2014年上-计算题