adium 4470:98db29e0ac7b: Changed AAR main to use @autoreleasepool.
commits at adium.im
commits at adium.im
Sun Jan 8 02:30:58 UTC 2012
details: http://hg.adium.im/adium/rev/98db29e0ac7b
revision: 4470:98db29e0ac7b
branch: (none)
author: Peter Hosey <hg at boredzo.org>
date: Sat Jan 07 17:48:06 2012 -0800
Changed AAR main to use @autoreleasepool.
Subject: adium 4471:5d52dabbebe4: Restored the ability of AdiumApplescriptRunner to run scripts from the command line, and committed a new build from the fixed sources. Fixes breakage of disk image background and custom icons added in [68df2b3513ec].
details: http://hg.adium.im/adium/rev/5d52dabbebe4
revision: 4471:5d52dabbebe4
branch: (none)
author: Peter Hosey <hg at boredzo.org>
date: Sat Jan 07 18:30:48 2012 -0800
Restored the ability of AdiumApplescriptRunner to run scripts from the command line, and committed a new build from the fixed sources. Fixes breakage of disk image background and custom icons added in [68df2b3513ec].
diffs (136 lines):
diff -r 68df2b3513ec -r 5d52dabbebe4 Release/AdiumApplescriptRunner
Binary file Release/AdiumApplescriptRunner has changed
diff -r 68df2b3513ec -r 5d52dabbebe4 Source/ApplescriptRunner.m
--- a/Source/ApplescriptRunner.m Sat Jan 07 15:00:47 2012 -0800
+++ b/Source/ApplescriptRunner.m Sat Jan 07 18:30:48 2012 -0800
@@ -29,6 +29,7 @@
@end
@interface AIApplescriptRunner ()
+- (void)beginObservingForDistributedNotifications;
- (void)respondIfReady:(NSNotification *)inNotification;
- (void)executeScript:(NSNotification *)inNotification;
- (void)quit:(NSNotification *)inNotification;
@@ -38,30 +39,40 @@
- (id)init
{
if ((self = [super init])) {
- NSDistributedNotificationCenter *distributedNotificationCenter = [NSDistributedNotificationCenter defaultCenter];
- [distributedNotificationCenter addObserver:self
- selector:@selector(respondIfReady:)
- name:@"AdiumApplescriptRunner_RespondIfReady"
- object:nil];
+ NSNotificationCenter *localNotificationCenter = [NSNotificationCenter defaultCenter];
- [distributedNotificationCenter addObserver:self
- selector:@selector(executeScript:)
- name:@"AdiumApplescriptRunner_ExecuteScript"
- object:nil];
-
- [distributedNotificationCenter addObserver:self
- selector:@selector(quit:)
- name:@"AdiumApplescriptRunner_Quit"
- object:nil];
-
- [self applescriptRunnerIsReady];
-
- [self resetAutomaticQuitTimer];
+ [localNotificationCenter addObserver:self
+ selector:@selector(executeScript:)
+ name:@"AdiumApplescriptRunner_ExecuteScript"
+ object:nil];
}
return self;
}
+- (void)beginObservingForDistributedNotifications
+{
+ NSDistributedNotificationCenter *distributedNotificationCenter = [NSDistributedNotificationCenter defaultCenter];
+
+ [distributedNotificationCenter addObserver:self
+ selector:@selector(respondIfReady:)
+ name:@"AdiumApplescriptRunner_RespondIfReady"
+ object:nil];
+
+ [distributedNotificationCenter addObserver:self
+ selector:@selector(executeScript:)
+ name:@"AdiumApplescriptRunner_ExecuteScript"
+ object:nil];
+
+ [distributedNotificationCenter addObserver:self
+ selector:@selector(quit:)
+ name:@"AdiumApplescriptRunner_Quit"
+ object:nil];
+
+ [self applescriptRunnerIsReady];
+
+ [self resetAutomaticQuitTimer];
+}
/*!
* @brief Inform observers on the NSDistributedNotificationCenter that the applesript runner is ready
*/
@@ -206,15 +217,54 @@
int main(int argc, const char *argv[])
{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- AIApplescriptRunner *applescriptRunner;
-
- applescriptRunner = [[AIApplescriptRunner alloc] init];
+ @autoreleasepool {
+ AIApplescriptRunner *applescriptRunner;
+ NSProcessInfo *processInfo;
+ NSArray *processArguments;
+ NSEnumerator *processArgumentsEnum;
+ NSString *scriptPath;
- [[NSRunLoop currentRunLoop] run];
-
- [applescriptRunner quit:nil];
- [applescriptRunner release];
+ applescriptRunner = [[AIApplescriptRunner alloc] init];
- [pool release];
+ processInfo = [NSProcessInfo processInfo];
+ processArguments = [processInfo arguments];
+ processArgumentsEnum = [processArguments objectEnumerator];
+
+ (void)[processArgumentsEnum nextObject]; //The first argument is the command name. We don't need that.
+
+ scriptPath = [processArgumentsEnum nextObject];
+ if (!scriptPath) {
+ [applescriptRunner beginObservingForDistributedNotifications];
+
+ //Run in the background for up to SECONDS_INACTIVITY_BEFORE_AUTOMATIC_QUIT seconds, waiting for Adium to give us a script to run.
+ [[NSRunLoop currentRunLoop] run];
+
+ [applescriptRunner quit:nil];
+ } else {
+ //Run the appointed script and then bail.
+ NSString *functionName = [processArgumentsEnum nextObject];
+ NSArray *scriptArgumentArray = nil;
+ NSDictionary *userInfo;
+ NSNotification *notification;
+
+ if (functionName) {
+ NSMutableArray *collectedArgs = [NSMutableArray array];
+ for (NSString *arg in processArgumentsEnum) {
+ [collectedArgs addObject:arg];
+ }
+ scriptArgumentArray = collectedArgs;
+ }
+
+ userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+ scriptPath, @"path",
+ functionName, @"function",
+ scriptArgumentArray, @"arguments",
+ nil];
+
+ notification = [NSNotification notificationWithName:@"AdiumApplescriptRunner_ExecuteScript" object:nil userInfo:userInfo];
+ [[NSNotificationCenter defaultCenter] postNotification:notification];
+ }
+
+ [applescriptRunner release];
+ }
}
More information about the commits
mailing list