1 /* xscreensaver, Copyright (c) 2013 Jamie Zawinski <jwz@jwz.org>
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
11 * XScreenSaverUpdater.app -- downloads and installs XScreenSaver updates
12 * via Sparkle.framework.
16 * NOTE: This does not work with Sparkle 1.5b6 -- it requires the "HEAD"
17 * version 4-Dec-2013 or later.
21 #import "Sparkle/SUUpdater.h"
23 @implementation XScreenSaverUpdater : NSObject
25 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
27 SUUpdater *updater = [SUUpdater updaterForBundle:
28 [NSBundle bundleForClass:[self class]]];
29 NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
30 [defs registerDefaults:UPDATER_DEFAULTS];
32 [updater setDelegate:self];
34 // Launch the updater thread.
35 [updater checkForUpdatesInBackground];
37 // Now we need to wait for the Sparkle thread to finish before we can
38 // exit, so just poll waiting for it.
39 [NSTimer scheduledTimerWithTimeInterval:1
41 selector:@selector(exitWhenDone:)
46 // Delegate method that lets us append extra info to the system-info URL.
48 - (NSArray *) feedParametersForUpdater:(SUUpdater *)updater
49 sendingSystemProfile:(BOOL)sending
51 // Get the name of the saver that invoked us, and include that in the
53 NSString *saver = [[[NSProcessInfo
54 processInfo]environment]objectForKey:
55 @"XSCREENSAVER_CLASSPATH"];
56 if (! saver) return nil;
57 NSString *head = @"org.jwz.xscreensaver.";
58 if ([saver hasPrefix:head])
59 saver = [saver substringFromIndex:[head length]];
61 return @[ @{ @"key": @"saver",
63 @"displayKey": @"Current Saver",
64 @"displayValue": saver
70 - (void) exitWhenDone:(NSTimer *)timer
72 SUUpdater *updater = [timer userInfo];
73 if (![updater updateInProgress])
74 [[NSApplication sharedApplication] terminate:self];
77 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app