[Project_owners] Global variables...?

David Murray lid2000 at tpg.com.au
Mon Oct 13 20:00:06 EDT 2003

Hi everyone.

I'm trying to set it so only one copy of my app is running at a time in 
Mozilla (and I'm still pretty much a novice at this stuff). I want to 
get the big M to detect whether the app window is already open or not, 
before it goes creating a new one. Just launching the app to the same 
window ID each time doesn't work, as it effectively causes it to 
refresh, restarting it. I don't feel as if I'm making much sense... :/

Anyway, here's what I came up with (this script gets launched when an 
item is clicked on in the Window menu):

        if ((typeof(top.DSWindow) != "object") || (top.DSWindow.closed)) {
            top.DSWindow = 
window.openDialog("chrome://deepestsender/content/", "DeepestSender", 

"Hooray" I thought, then realised that if you hit Ctrl+N to open a new 
Mozilla window and try it again, the window object doesn't exist so it 
goes and runs the window.openDialog bit. I've got no idea how I can get 
around this, other than setting a preference like isRunning to true 
whenever the app gets started, and false when it exits. This seems like 
a stupid workaround though, and it'd end up causing problems if it was 
running while Mozilla crashed then got started again. So I'm out of 
ideas (I'm crap at the XPCOM stuff too so there's probably something 
there I haven't looked at).

And leading on from that, here's an extremely similar question: Is there 
any way to set some global variables in Mozilla, so they'll be shared 
between all windows and everything? I'm trying to get a little status 
bar icon going that flashes whenever someone's LiveJournal has been 
updated much like Netscape 3 and 4's way it'd check the email every now 
and again when the browser was running. The catch is theres a set time 
limit you can check otherwise it won't return a result. That's all good, 
but once again, have more than one window open and you get problems. 
Again, the only way I can think of is to set preferences, and even then, 
how would I send a command out to multiple instances of all the windows? 
I'm going to dig around the mail/news source again and try to figure out 
how they did it, but my hopes aren't high.

If you read this far, thanks for paying attention.


More information about the Project_owners mailing list