sparkle-project / Sparkle

A software update framework for macOS
https://sparkle-project.org
Other
7.46k stars 1.05k forks source link

How do I implement shouldPostponeRelaunchForUpdate #850

Closed mick-ntrepid closed 8 years ago

mick-ntrepid commented 8 years ago

The docs for the 'postponeRelaunch' method are somewhat confusing (at least to me):

// Return YES to delay the relaunch until you do some processing. // Invoke the provided NSInvocation to continue the relaunch.

This is some simple example code which doesn't work as expected:

-(BOOL)updater:(SUUpdater )updater shouldPostponeRelaunchForUpdate:(SUAppcastItem )update untilInvoking:(NSInvocation *)invocation {

[invocation setSelector:@selector(myTestMethod)];
[invocation setTarget:self];

[invocation invoke];

return YES;

}

I'm not sure how the shouldPostpone delegate should be implemented - some simple sample code would be greatly appreciated.

-Mick mick.oyer@ntrepidcorp.com

kornelski commented 8 years ago

You only need to call [invocation invoke]. Changing its selector will break it.

mick-ntrepid commented 8 years ago

Thanks for the response - sorry, still confused.

How do I set the invocation to call a specific method? In my example, I'm trying to call 'myTestMethod'. I need to execute some code after the update is completed and before relaunch.

kornelski commented 8 years ago

You must not set up a call. It's already set up for you. You only invoke it after you've done whatever else you needed to do. You call methods in your own program as usual.

mick-ntrepid commented 8 years ago

Still not getting it ... What gets called? Confused about the 'untilInvoking' piece of the method. I assume I have to tell it what I want it to do? Is there anything I need to set up inside the method? Right now I just call [invocation invoke] and return YES, Works, but doesn't do anything.

thanks.

mick-ntrepid commented 8 years ago

OK, think I understand it ...

In the shouldPostpone method, I include any processing I want done - THEN I call invocation invoke and finally return YES.

kornelski commented 8 years ago

Yes.

(or you can store the invocation elsewhere, return yes, then call invoke anytime later. It behaves like callback in nodejs).

mick-ntrepid commented 8 years ago

Right - eventually I'm going to need an NSWindow, so I can store the invocation and call it from a button in the Window. Thx for the help.