xulrunner html5,XULRunner入门
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入门的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机应用技术自考知识点,自考计算机应用
- 下一篇: 计算机网络技术与计算机应用技术,计算机网