Getting a splash screen to show

  • Please don't waste my time arguing that splash screens are bad. It's all been hashed out before.

    How am I supposed to force the splash screen to be visible? It's created and shown in applicationWillFinishLaunching. The app is document based. Other modal dialogs *could* appear and go away before the splash screen appears, so order is important. If a modal dlog *does* appear beforehand (e.g. registration), then the splash screen will display. If not, something is preventing the splash screen from showing. This got me thinking it was event manager related, so I added this after showing the splash screen:

    [[NSApplication sharedApplication] nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];

    That fixed it. Well, it fixed it until I tried launching the app and letting Cocoa restore documents that were open when I quit. Again, no splash screen. Why is this so hard to do?

    --
    Steve Mills
    office: 952-818-3871
    home: 952-401-6255
    cell: 612-803-6157
  • In one application I have to display a splash screen while a poorly written framework (DAQmxBase from National Instruments) takes 6 to 11 seconds to initialize itself on the main thread.
    To do so, I display my splash screen as a non modal, top-level, centered window (use NSWindow's setLevel:NSFloatingWindowLevel to make it top-level).

    Do you require your splash screen or the registration window to be modal?

    Jean

    On 15 mai 2013, at 17:26, Steve Mills <smills...> wrote:

    > Please don't waste my time arguing that splash screens are bad. It's all been hashed out before.
    >
    > How am I supposed to force the splash screen to be visible? It's created and shown in applicationWillFinishLaunching. The app is document based. Other modal dialogs *could* appear and go away before the splash screen appears, so order is important. If a modal dlog *does* appear beforehand (e.g. registration), then the splash screen will display. If not, something is preventing the splash screen from showing. This got me thinking it was event manager related, so I added this after showing the splash screen:
    >
    > [[NSApplication sharedApplication] nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];
    >
    > That fixed it. Well, it fixed it until I tried launching the app and letting Cocoa restore documents that were open when I quit. Again, no splash screen. Why is this so hard to do?
    >
    > --
    > Steve Mills
    > office: 952-818-3871
    > home: 952-401-6255
    > cell: 612-803-6157

    -----------
    Jean Suisse
    Institut de Chimie Moléculaire de l’Université de Bourgogne
    (ICMUB) — UMR 6302
  • On May 15, 2013, at 10:40:38, Jean Suisse <jean.lists...> wrote:

    > In one application I have to display a splash screen while a poorly written framework (DAQmxBase from National Instruments) takes 6 to 11 seconds to initialize itself on the main thread.
    > To do so, I display my splash screen as a non modal, top-level, centered window (use NSWindow's setLevel:NSFloatingWindowLevel to make it top-level).
    >
    > Do you require your splash screen or the registration window to be modal?

    Only the registration dialog is modal. The splash is not modal because it uses no interaction. It just shows up, some messages get set (in debug builds only), and it goes away when we're all done getting set up. Here's the code that runs after the nib has been loaded. I'm not sure if everything is needed - I didn't write this code:

    [splashWindow setLevel:NSFloatingWindowLevel];
    [splashWindow setBackgroundColor:[NSColor clearColor]];
    [splashWindow setOpaque:NO];
    [splashWindow setHasShadow:NO];
    [splashWindow invalidateShadow];
    [splashWindow flushWindow];
    [splashWindow display];
    [splashWindow makeKeyAndOrderFront:nil];
    SetPortWindowPort((WindowRef)[splashWindow windowRef]);
    [[NSApplication sharedApplication] nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];

    The strange part is that it does NOT show if Cocoa is going to restore documents. Why would that matter?

    --
    Steve Mills
    office: 952-818-3871
    home: 952-401-6255
    cell: 612-803-6157
  • I added more nextEventMatchingMask's and the 4th one would actually cause the document to be restored, which was way too early in the init method to do that. But I found this, which seems to work much more reliably. It takes care of doing event type stuff and displays the window.

    NSModalSession  session = [[NSApplication sharedApplication] beginModalSessionForWindow:splashWindow];

    [[NSApplication sharedApplication] endModalSession:session];

    Continue doing regular init code, leaving the window onscreen…

    --
    Steve Mills
    office: 952-818-3871
    home: 952-401-6255
    cell: 612-803-6157
  • On May 15, 2013, at 8:59 AM, Steve Mills wrote:

    > [splashWindow setLevel:NSFloatingWindowLevel];
    > [splashWindow setBackgroundColor:[NSColor clearColor]];
    > [splashWindow setOpaque:NO];
    > [splashWindow setHasShadow:NO];
    > [splashWindow invalidateShadow];
    > [splashWindow flushWindow];
    > [splashWindow display];
    > [splashWindow makeKeyAndOrderFront:nil];

    Looks fine, but ditch the invalidate/flush/display is unnecessary.

    > SetPortWindowPort((WindowRef)[splashWindow windowRef]);

    Why is this here? Burn it with fire.

    > The strange part is that it does NOT show if Cocoa is going to restore documents. Why would that matter?

    Possibly because window restoration (which happens after applicationWillFinishLaunching) is hiding it? Possibly because wherever the splash window is being created, isn't being called so splashWindow is nil? Maybe it is visible, but the content is not drawing (and since  the Guessing.

    > Why is this so hard to do?

    Not much to go on here, unfortunately. It must have something to do with what else is in your project or ordering. Showing a window at launch is as trivial as it should be, so something else must be interfering.

    --
    Seth Willits
  • On May 15, 2013, at 11:56:42, Seth Willits <slists...> wrote:

    > Looks fine, but ditch the invalidate/flush/display is unnecessary.

    Thanks.

    > Why is this here? Burn it with fire.

    Like I said, I didn't write it. And yeah, radiated acid napalm will be used.

    > Not much to go on here, unfortunately. It must have something to do with what else is in your project or ordering. Showing a window at launch is as trivial as it should be, so something else must be interfering.

    Googling the problem, others have reported similar problems for document based apps. Restoring docs seems to complicate it further, out of our hands.

    --
    Steve Mills
    office: 952-818-3871
    home: 952-401-6255
    cell: 612-803-6157
  • On May 15, 2013, at 10:06 AM, Steve Mills <smills...> wrote:

    > On May 15, 2013, at 11:56:42, Seth Willits <slists...> wrote:
    >
    >> Not much to go on here, unfortunately. It must have something to do with what else is in your project or ordering. Showing a window at launch is as trivial as it should be, so something else must be interfering.
    >
    >
    > Googling the problem, others have reported similar problems for document based apps. Restoring docs seems to complicate it further, out of our hands.

    Make sure the splash window is not restorable, and make sure you're not relying on getting -applicationOpenUntitledFile:.

    --Kyle Sluder
  • On May 15, 2013, at 12:37:47, Kyle Sluder <kyle...> wrote:

    > Make sure the splash window is not restorable, and make sure you're not relying on getting -applicationOpenUntitledFile:.

    I turned the Restorable setting off earlier today, since it has no business being on for this. I didn't help. We already have an override for applicationOpenUntitledFile and it's not being called on launch when docs are being restored.

    Like I said in an earlier message, I've solved everything by beginModalSessionForWindow followed by endModalSession.

    --
    Steve Mills
    office: 952-818-3871
    home: 952-401-6255
    cell: 612-803-6157
  • On May 15, 2013, at 10:48 AM, Steve Mills wrote:

    > Like I said in an earlier message, I've solved everything by beginModalSessionForWindow followed by endModalSession.

    Calling beginModalSessionForWindow and endModalSession back to back to "fix" this issue is a hack, not solution. You'd really be better served by trying to find and solve the real cause. With things like Carbon port function and random invalidate/flush/display around, it wouldn't be a surprise if there are other issues as well being caused by the same thing.

    --
    Seth Willits
  • On 15 mai 2013, at 17:59, Steve Mills wrote:

    > On May 15, 2013, at 10:40:38, Jean Suisse wrote:
    >
    >> In one application I have to display a splash screen while a poorly written framework (DAQmxBase from National Instruments) takes 6 to 11 seconds to initialize itself on the main thread.
    >> To do so, I display my splash screen as a non modal, top-level, centered window (use NSWindow's setLevel:NSFloatingWindowLevel to make it top-level).
    >>
    >> Do you require your splash screen or the registration window to be modal?
    >
    > Only the registration dialog is modal. The splash is not modal because it uses no interaction. It just shows up, some messages get set (in debug builds only), and it goes away when we're all done getting set up. Here's the code that runs after the nib has been loaded. I'm not sure if everything is needed - I didn't write this code:
    >
    > [splashWindow setLevel:NSFloatingWindowLevel];

    That I use.

    > [splashWindow setBackgroundColor:[NSColor clearColor]];
    > [splashWindow setOpaque:NO];
    > [splashWindow setHasShadow:NO];
    > [splashWindow invalidateShadow];
    > [splashWindow flushWindow];
    > [splashWindow display];
    > [splashWindow makeKeyAndOrderFront:nil];

    That I don't call. I just use  NSWindowController's initWithWindowNibName:

    > SetPortWindowPort((WindowRef)[splashWindow windowRef]);
    > [[NSApplication sharedApplication] nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:NO];

    That looks weird.

    > The strange part is that it does NOT show if Cocoa is going to restore documents. Why would that matter?

    I don't know. Something else is going on. Do you require the registration dialog to be modal? Looks like making the dialog non modal or showing it up later would solve the issue.

    Jean

    -----------
    Jean Suisse
    Institut de Chimie Moléculaire de l’Université de Bourgogne
    (ICMUB) — UMR 6302
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today