From http://www.jwz.org/xscreensaver/xscreensaver-5.24.tar.gz
[xscreensaver] / OSX / Updater.m
1 /* xscreensaver, Copyright (c) 2013 Jamie Zawinski <jwz@jwz.org>
2  *
3  * Permission to use, copy, modify, distribute, and sell this software and its
4  * documentation for any purpose is hereby granted without fee, provided that
5  * the above copyright notice appear in all copies and that both that
6  * copyright notice and this permission notice appear in supporting
7  * documentation.  No representations are made about the suitability of this
8  * software for any purpose.  It is provided "as is" without express or 
9  * implied warranty.
10  *
11  * XScreenSaverUpdater.app -- downloads and installs XScreenSaver updates
12  * via Sparkle.framework.
13  *
14  * Created: 7-Dec-2013
15  *
16  * NOTE: This does not work with Sparkle 1.5b6 -- it requires the "HEAD"
17  *       version 4-Dec-2013 or later.
18  */
19
20 #import "Updater.h"
21 #import "Sparkle/SUUpdater.h"
22
23 @implementation XScreenSaverUpdater : NSObject
24
25 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
26 {
27   SUUpdater *updater = [SUUpdater updaterForBundle:
28                                     [NSBundle bundleForClass:[self class]]];
29   NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
30   [defs registerDefaults:UPDATER_DEFAULTS];
31
32   // Launch the updater thread.
33   [updater checkForUpdatesInBackground];
34
35   // Now we need to wait for the Sparkle thread to finish before we can
36   // exit, so just poll waiting for it.
37   [NSTimer scheduledTimerWithTimeInterval:1
38            target:self
39            selector:@selector(exitWhenDone:)
40            userInfo:updater
41            repeats:YES];
42 }
43
44 - (void) exitWhenDone:(NSTimer *)timer
45 {
46   SUUpdater *updater = [timer userInfo];
47   if (![updater updateInProgress])
48     [[NSApplication sharedApplication] terminate:self];
49 }
50
51 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app
52 {
53   return YES;
54 }
55
56 @end