Skip to main content
Welcome guest. | Register | Login | Post

Easy Standalone Linux Applications

8 replies [Last post]
supermike's picture
Offline
Joined: 2006-02-17

Previously in this forum, about 6 months ago, I talked about how to combine XUL, thttpd, ngs-js (or your favorite CGI command-line language like Perl, Python, or PHP), and perhaps SQLite -- all to create Linux standalone applications (instead of web apps).

Well, tonight, I have learned the poorly documented technique for building robust standalone Linux applications with just XUL and perhaps SQLite. There's no longer a need to have a web server (even a tiny, embeddable one like thttpd). I'll have a short example posted here for all you novice programmers wanting to program your first Linux app, or even smart programmers who want to learn a new technique that might make application development easier for you.

Here's how it works:

1. All the end user needs on their Linux PC is Firefox 1.5 or better, and perhaps SQLite or any /usr/bin commands you might want to depend on.

2. The user doubleclicks a single executable binary file (ELF format). (Spoiler: these are made using 'makeself' command.)

3. This file then expands into /tmp and calls a startup Bash script.

4. The startup Bash script calls firefox (or equivalent) by doing:

mozilla -chrome file:/myapp.xul

5. The 'myapp.xul' can either be one single app, or it can include separate images, a SQLite database, separate CSS style sheets, and perhaps some Bash commands or separate Javascript files.

6. Myapp.XUL contains an HTML-like language inside with some special XML header information. You draw the GUI in this.

7. When buttons are clicked in the XUL interface, they can be set to call Javascript handlers in the XUL file or whatever separate Javascript files are included in this XUL file.

8. Now, Javascript on its own doesn't have any persistence (data store) or SQL database connectivity. It also can't do a lot of things that you can do from your /bin, /sbin, /usr/bin, and /usr/sbin directories. To overcome that problem, you have to use a technology called XPCOM, and you do that through Javascript.

9. XPCOM is fairly difficult to use and that's one of the big complaints. However, all you really need to learn are the XPCOM components for file i/o and process execution, intially, and learn the other components later on.

10. Firefox normally turns of XPCOM by default. But there's a special command you type (a hold over from Netscape) that unlocks XPCOM in the browser and permits your Javascript to call XPCOM components.

11. The XPCOM can then shell out to run processes and get results, or interact with files. Although there's an XPCOM component for SQLite interaction, you could always just shell out to the SQLite command to run it too, as well as MySQL or PostgreSQL -- any database you can access from command line on Linux.

Anyway, this is all a lot to go over and I want to show you how to this in the least lines of text. I'll post that on my blog in a week or so and link that in later on.

a thing's picture
Offline
Joined: 2005-12-20
XULRunner

Wouldn't it be better to use XULRunner instead of Firefox?

supermike's picture
Offline
Joined: 2006-02-17
I think I heard that

I think I heard that XULRunner is the way to go because then you can get out of the popup UNSAFE security notices that you can click Approve, Deny, Approve Always. The problem with XULRunner, however, is the 15MB download -- yikes. With firefox, they get an annoying popup that you can click Approve Always and for the life of that application for this user's profile, it won't prompt them again.

It seems like a low (or no) security risk for Mozilla to detect that I ran a custom chrome in FF and not prompt the UNSAFE warnings. But alas it appears they chose not to do so.

a thing's picture
Offline
Joined: 2005-12-20
distro inclusion

I'm sure the download won't be a problem once XULRunner is included in distros.

supermike's picture
Offline
Joined: 2006-02-17
xulrunner
a thing wrote:

I'm sure the download won't be a problem once XULRunner is included in distros.

I read on the web that Redhat Enterprise Linux now uses xulrunner for some of its control panels. Hurray! So it's well on its way to becoming a default in many distros of Linux. It's about 9MB.

supermike's picture
Offline
Joined: 2006-02-17
Got It Finished

Alright, guys, I have finally learned a tremendous amount about XUL. I've learned that xulrunner is the way to go because it lets you run client-side Javascript outside the "sandbox" so to say, giving it far more capability than it would by default. I've learned that xulrunner is very picky in how you lay out your directories in order to load your application. And I've learned how to build a standalone XUL application completely without a web server.

Frankly, I don't see why, for those people who already know HTML and Javascript, one wouldn't want to program in XUL and XPCOM because it's not much further of a step. With this you can build robust standalone or client/server applications that are either geared for a particular platform or are cross-platform (Mac, Windows, Linux). And this can even have SQL database capabilities for multiple kinds of SQL database platforms (but especially SQLite).

In fact, because of this, I'm abandoning all my future Python, PyGTK programming and switching to XUL applications.

So do you want to get started too? Are you a newbie programmer who uses HTML and Javascript and want to learn something cool? Or are you a novice or advanced programmer and want to make applications much faster, especially for Linux? Great, check out this sample project here. It's enough to get you started.

http://code.google.com/p/simplexul/

libervisco's picture
Offline
Joined: 2006-05-04
This seems like some cool

This seems like some cool stuff really, like a quick highway from programming noobishness to GUI programming. Nice.

I've got CSS and HTML and I just need to learn some javascript to be ready for this. Smiling

supermike's picture
Offline
Joined: 2006-02-17
noobishness

Yeah, I'm glad you like it. I'd like to see more noobs on Linux like it as well. It might turn programmers out of them, just yet. Linux needs even more apps than it already has -- we always need even better ways of doing things. For instance, when I had a software startup, back when I still used Windows on a daily basis, a program I used routinely was Quickbooks for Small Business. Well, on Linux, there's really only Grisbi and Gnucash, or ordinary spreadsheets. Grisbi and Gnucash are nice and all, but they're no QBfSB. So I'd like to see someone build one in XUL, XPCOM, SQLite, and Javascript.

Even to seasoned programmers, learning Glade, Python, and PyGTK is a hair-raising, frustrating experience, and XUL programming can help someone move beyond that.