public
Description: Random album-based playlist generation for your iPod/iPhone
Homepage: http://steelskies.com
Clone URL: git://github.com/jdelStrother/nanofibre.git
Search Repo:
Changing the daemon-launch mechanism

To be perfectly honest, I don't remember why this is changed.  I changed 
it over a year ago, and have been running that code ever since, so that 
must mean it's good.... right?
I know I did have problems with launchd occasionally deciding not to 
launch NanoFibre under Tiger... maybe this was a workaround for that?
jdelStrother (author)
Wed May 28 14:01:21 -0700 2008
commit  4178facfbacd9fb7641f3696a3c303a26752e3ab
tree    712b053594ad1660e643fad3c76f2d0311c6d179
parent  a62a866023aaeead87e6bbed15102bddd84255a0
...
9
10
11
 
 
12
13
14
...
23
24
25
26
27
28
29
30
31
32
33
34
35
 
 
 
 
 
 
36
37
 
 
 
 
 
38
39
40
 
 
41
42
...
9
10
11
12
13
14
15
16
...
25
26
27
 
 
 
 
 
 
 
 
 
 
28
29
30
31
32
33
34
 
35
36
37
38
39
40
41
42
43
44
45
46
0
@@ -9,6 +9,8 @@
0
 
0
 #import <Carbon/Carbon.h>
0
 #import <Cocoa/Cocoa.h>
0
+#import "MusicLibrary.h"
0
+#import <unistd.h>
0
 
0
 int main(int argc, char *argv[])
0
 {
0
@@ -23,20 +25,22 @@ int main(int argc, char *argv[])
0
     return 1;
0
   }
0
   
0
- LSApplicationParameters appParams;
0
- appParams.version = 0;
0
- appParams.flags = kLSLaunchAsync | kLSLaunchDontSwitch | kLSLaunchDontAddToRecents | kLSLaunchAndHide;
0
- appParams.application = &appRef;
0
- appParams.asyncLaunchRefCon = NULL;
0
- //Tell the app that we want to run in daemon mode. We're using the environment vars to do this, because...
0
- appParams.environment = (CFDictionaryRef)[NSDictionary dictionaryWithObject:@"yes" forKey:@"fibreDaemon"];
0
- // ..."This field is ignored in Mac OS X v10.4". Cheers guys.
0
- appParams.argv = NULL;
0
- appParams.initialEvent = NULL;
0
+ CFURLRef url = CFURLCreateFromFSRef(kCFAllocatorDefault, &appRef);
0
+ if (!url)
0
+ {
0
+ NSLog(@"Couldn't convert fsref to pathname");
0
+ return 1;
0
+ }
0
   
0
- LSOpenApplication(&appParams, NULL);
0
+ NSString* pathName = (NSString *)CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
0
+ CFRelease(url);
0
+
0
+ NSString* executable = [pathName stringByAppendingString:@"/Contents/MacOS/NanoFibre"];
0
+ system([[NSString stringWithFormat:@"fibreDaemon=yes \"%@\"", executable] cStringUsingEncoding:NSUTF8StringEncoding]);
0
   
0
   [pool release];
0
   
0
+ sleep(60); //LaunchD is dumb and kills our daemon if it doesn't stay running for 60 seconds (TODO: Even in Leopard?)
0
+
0
   return 0;
0
 }

Comments

    No one has commented yet.