Event order

My app when it starts shows a launcher window, with a variety of ‘get started’ options.
If the app is launched by double clicking a document, I dont want that window to show.

For years, this has been achieved by setting a variable in the OpenDocument event : dontshowlauncher = true

And in open:

[code]If dontshowlauncher then

else
//show the launcher
end if
[/code]

But recently , it seems that the event order has reversed.
Open fires first, followed by OpenDocument.
So the variable isnt set and I get both a document and a launcher.

Any ideas about how to handle this when events occur in this way?
(Opendocument is tricky to debug!!)

As far as I know the App Open event always was triggered first (and before the OpenDocument event).

BTW I have several apps using OpenDocument and they still are working as expected.

Codes been there for several years… it really did used to work.

It makes sense that open should fire first, just looking for a way to avoid the launcher if an opendocument is ‘in the queue’

[quote=229587:@Jeff Tullin]My app when it starts shows a launcher window, with a variety of ‘get started’ options.
If the app is launched by double clicking a document, I dont want that window to show.
…/…
Any ideas about how to handle this when events occur in this way?
(Opendocument is tricky to debug!!)[/quote]

First I would do is to place a System.debuglog in every one of the startup event and in OpenDocument to check in Console the exact order in which they fire (Console will show messages for built executables so you can double click on documents). Then when you are certain of what is going on, you can work around the issue. One way of dealing with it if OpenDocument fires after Window.Open is to set the window as not visible, and turn it or not visible in OpenDocument, or use a timer if OpenDocument has not been fired to show it.

Thanks for the idea Michel.
I’ll experiment with that.

And you think this will alway be that order in the future ?

My sentiments too, Emile.

For now, I have changed a button on the launch from ‘Quit’ to ‘Cancel’
Personally, I dislike the way that Mac apps can close all the windows and still be open, but at least this allows the user to discard.
Im working on other ideas.

Just had a thought.
Ive made the launcher a property of the app.
In open I set
mLauncher = new frmLaunch

In the Opendocument event, if the property is not null, I’ll close it and set it to nil.
That should do it, (even if a pointless window appears for a moment or two).

Nope. Reason why I suggested using an invisible start window and the use of a timer, so if for some reason order changes, after a reasonable amount of time, the timer will show the window.

Time and again have I seen here people trying to rely on order of events, and be reminded by Xojo that one should not, or at least arrange in case that order changed. That is what event programming is all about, after all.

This disturb some Windows users too.

I will not encourage this use, but I recall a preference somewhere (but where ?) that allows to quit the application when no more window is open (when the user close the last window).

I found it: Application.AutoQuit.

I would set the app to show no window and merely set variables in the events. Then I would start a Timer, as Michel suggested. Since the Timer code will run after all other events have finished, there is no question about the order. All that can be known at startup will be known and you can proceed accordingly. If you set the Period to something really low, like 20, the user won’t even know there was a gap.

And since I keep many apps running all day long, I appreciate the feature of being able to run them windowless. Unless it’s a one-window utility, give your users a preference for auto quit rather than forcing it on them.

Use the App.NewDocument event to know when the user just launched the app without a file. ie, use NewDocument to show your launcher and OpenDocument to load the file without a launcher.

Looks like thats the simplest solution. Thanks