Packaging XUL Apps
I just found that if you use this in your Javascript in order to enable XPCOM components:
netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");
...your browser will pop up an UNSAFE warning.
So how do you stop it? Well, unfortunately it means you must use the 'xulrunner' application, which you can download here:
http://developer.mozilla.org/en/docs/XULRunner
(Look for Linux link.)
This, unfortunately, adds 8.9MB to your application distribution and I wish that Ubuntu would ship with it by default because it's so important for newbies in developing apps. I also wish that you could just do 'apt-get install xulrunner', but I don't have that option.
Okay, so xulrunner can run your XUL application, but it's not that easy yet. You need to do it like so:
1. Create a directory structure like the following, and yes, I know it's crazy:
- application.ini (a text file we will edit in a moment)
- chrome (folder)
- content (folder)
- sample (folder)
- sample.css (a CSS file for the "skin" of your app)
- sample.js (a javascript file for what you hook up your XUL events to)
- sample.xul (the GUI of the application
- chrome.manifest (a text file we will edit in a moment)
- defaults (folder)
- preferences (folder)
prefs.js (a special kind of Javascript file we will edit in a moment)
2. Previously, I have mentioned how you build your sample .xul, .js, and .css files, so I won't go over those again. However, there is a special file you need called application.ini. Edit it so it looks like so:
Code:
[App]
Name=sample
BuildID=0
[Gecko]
MinVersion=1.5
...changing 'sample' above to whatever you want to name your application.
3. Next, find your prefs.js text file that you created and put this into it:
Code:
pref('toolkit.defaultChromeURI', 'chrome://sample/content/sample.xul');
...changing all the 'sample' keywords above to what you want to name your app.
4. Next, find your chrome.manifest text file that you created and put this into it:
Code:
content sample file:content/sample/
...changing all the 'sample' keywords above to what you want to name your app.
5. In your XUL file, you'll need a different way to address your Javascript. Do it like this right after your last xmlns line, starting a new line:
Code:
<html:script src='chrome://sample/content/sample.js' />
...changing all the 'sample' keywords above to what you want to name your app.
6. In your XUL file, to load the CSS, I think I learned that you don't need a path to it. I load my CSS like so:
Code:
<?xml-stylesheet href="sample.css" type="text/css"?>
...right after the line about global skin and right before the window tag.
7. So, with all this preparation done, you need to download and install your XUL Runner app. I just uncompress it into /usr/share as /usr/share/xulrunner and then do this:
Code:
$ sudo ln -s /usr/share/xulrunner /usr/bin/xulrunner
8. And now, FINALLY (phew!), to call for instance a 'sample' folder that contains my app, which I might have placed inside /usr/share as /usr/share/sample, I would call it like so:
Code:
$ xulrunner /usr/share/sample/application.ini
...and up pops your window for your application. Moreover, when you do something that activates your Javascript and if that Javascript calls an XPCOM object, it will no longer prompt you about things being unsafe or not. It will just run.
Commentary: I guess I can fault the Mozilla devs who came up with this crazy way to call an XUL app through xulrunner. If it were me, I would just prefer to throw everything into one directory and call it with 'xulrunner <directory>/sample.xul', but this is the way it is.
So, now that you know this, here's some more advice. There's a tool you can find on the web called 'makeself' that can combine all of this into one Linux executable and have it call your Bash script. The only thing it doesn't come with is 'xulrunner'. Now, if you prefer to bundle your app with 'xulrunner', and you have read the license agreement for it and are in compliance, then you can use makeself to throw everything together including xulrunner. This could potentially make your application somewhere between 9MB and 15MB, but I guess that's not too bad -- I've seen worse. And, if distros of Linux start to ship with the 8.9MB xulrunner, or if it's easily available on 'apt', then you can reduce your application's size by that much.
Bookmarks