forked from pieter/gitx
/
gitx.mm
51 lines (44 loc) · 1.29 KB
/
gitx.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// gitx.mm
// GitX
//
// Created by Ciarán Walsh on 15/08/2008.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "PBCLIProxy.h"
NSDistantObject* connect()
{
id proxy = [NSConnection rootProxyForConnectionWithRegisteredName:ConnectionName host:nil];
[proxy setProtocolForProxy:@protocol(GitXCliToolProtocol)];
return proxy;
}
int main(int argc, const char* argv)
{
// Attempt to connect to the app
id proxy = connect();
if (!proxy) {
// If the connection failed, try to launch the app
[[NSWorkspace sharedWorkspace] launchApplication:@"GitX"];
// Now attempt to connect, allowing the app time to startup
for (int attempt = 0; proxy == nil && attempt < 50; ++attempt){
if (proxy = connect())
break;
usleep(15000);
}
}
if (!proxy) {
fprintf(stderr, "Couldn't connect to app server!\n");
exit(1);
}
if ([[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"]) {
NSURL* url = [NSURL fileURLWithPath:[[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"]];
NSError* error = nil;
if (![proxy openRepository:url error:&error]) {
fprintf(stderr, "Error opening repository at %s", [[url path] UTF8String]);
if (error) {
fprintf(stderr, ": %s", [[error localizedFailureReason] UTF8String]);
}
fprintf(stderr, "\n");
}
}
}