on windowSplashShow_(sender)
activate me
pWindowMain's orderOut:me
pWindowSplash's makeKeyAndOrderFront:me
my performSelector:"windowSplashClose" withObject:(missing value) afterDelay:2
end windowSplashShow_:
on windowSplashClose()
pWindowSplash's orderOut:me
pWindowMain's makeKeyAndOrderFront:me
end windowSplashClose
The handler windowSplashShow is called at startup inside the applicationDidFinishLaunching in this way:
on applicationDidFinishLaunching:notification
initialize()
updateInterface_(me)
windowSplashShow_(me)
verifyPrivileges()
end applicationDidFinishLaunching:
I “discovered” that after calling the windowSplashShow_, the execution of code continue immediately with verifyPrivileges handler. Without waiting the amount of seconds defined.
I my mind when code call windowSplashShow_ the handler wait the delay defined and only after this the window is closed.
After again the verifyPrivileges routine is called.
As usually, many thanks for clarification and confirmation.
So a workaround is to use do shell script sleep X instead of performSelector
Exists an equivalent do shell script sleep in Cocoa (in ASS we used delay X) to wait execution of the code?
think asynchronously or in terms of handlers.
Put the verifyPrivileges() call in the windowSplashClose() handler
on windowSplashShow:sender
activate me
pWindowMain's orderOut:me
pWindowSplash's makeKeyAndOrderFront:me
my performSelector:"windowSplashClose" withObject:(missing value) afterDelay:2
end windowSplashShow:
on windowSplashClose()
pWindowSplash's orderOut:me
pWindowMain's makeKeyAndOrderFront:me
verifyPrivileges()
end windowSplashClose
on applicationDidFinishLaunching:notification
initialize()
updateInterface_(me)
windowSplashShow_(me)
end applicationDidFinishLaunching:
I understand that now I have to move verifyPrivileges() inside the windowSplashClose() because performSelector works as sheet window where execution of code don’t stop but continue.
My mind is again on ASS where for this case I used delay that (correct me if I’m wrong) like do shell sleep, freeze the execution for x second and continue with next handler.
In my case the showSplash/close splash is also called when user choose “About this app…” in addition to startup.
What I would like to do is to have only verify privileges at startup.
Basically the app is launched, a splash appear for few seconds and after splash close, permission via network to use the app are verified. If the user is not enabled a modal dialog appear and after OK the app terminate.
Is more simple to manage (but this is my opinion), to have a sleep after an handler and continue with next handler instead of put a particular handler inside another “generic” handler like close.
Probably using Cocoa “scripter” like me need to understand much more about some Cocoa mechanism.
You can probably use a sleepForTimeInterval: without any problems in that particular case, although you should use modal windows rather than makeKeyAndOrderFront:.
The problem with sleeping is that your interface can’t do anything at all while you have stopped the main thread. That means if the user starts banging keys or something, there’s a chance that the number of pending events will build up too much, and result in the spinning beachball cursor. You don’t want that.