-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathCPCodePilotPlugin.m
106 lines (84 loc) · 2.83 KB
/
CPCodePilotPlugin.m
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// CPCodePilotPlugin.m
// CodePilot
//
// Created by Zbigniew Sobiecki on 2/18/10.
// Copyright 2010 Macoscope. All rights reserved.
//
#import "CPCodePilotPlugin.h"
#import "CPCodePilotWindowDelegate.h"
#import "CPXcodeWrapper.h"
#import "CPPluginInstaller.h"
#include <sys/stat.h>
@implementation CPCodePilotPlugin
+ (void)pluginDidLoad:(id)arg1
{
}
+ (void)load
{
// Avoid instantiating plugin if no Xcode is launched.
// Loading the plugin from xcodebuild command caused a crash because the plugin tries to load a window for itself
NSString *currentApplicationName = [[NSBundle mainBundle] infoDictionary][@"CFBundleName"];
if ([currentApplicationName isEqual:@"Xcode"]) {
LOG(@"CODE PILOT: CURRENT_XCODE_VERSION: %@ CURRENT_XCODE_REVISION: %@", CURRENT_XCODE_VERSION, CURRENT_XCODE_REVISION);
// just instantiate the singleton
(void)[CPCodePilotPlugin sharedInstance];
}
}
- (id)init
{
self = [super init];
if (self) {
self.isUserLevelDebugOn = [[NSUserDefaults standardUserDefaults] boolForKey:DEFAULTS_USER_LEVEL_DEBUG_KEY];
[self checkForFirstRun];
self.xcWrapper = [CPXcodeWrapper new];
self.windowDelegate = [[CPCodePilotWindowDelegate alloc] initWithXcodeWrapper:self.xcWrapper];
// we want to start real installation once the app is fully launched
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidFinishLaunching:)
name:NSApplicationDidFinishLaunchingNotification
object:nil];
LOG(@"%@ %@ Plugin loaded.", PRODUCT_NAME, PRODUCT_CURRENT_VERSION);
}
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
self.installer = [[CPPluginInstaller alloc] init];
[self.installer installPlugin:self];
if (self.firstRunEver) {
[self.windowDelegate openFirstRunWindow];
}
}
- (void)openCodePilotWindow
{
LOGCALL;
if (self.windowDelegate.ourWindowIsOpen) {
[self.windowDelegate hideWindow];
}
[self.xcWrapper reloadXcodeState];
[self.windowDelegate openWindow];
}
- (void)checkForFirstRun
{
self.thisVersionFirstRun = YES;
self.firstRunEver = YES;
NSString *lastVersionId = [[NSUserDefaults standardUserDefaults] objectForKey:DEFAULTS_LAST_VERSION_RUN_KEY];
if (!IsEmpty(lastVersionId)) {
self.firstRunEver = NO;
if ([lastVersionId isEqualToString:PRODUCT_CURRENT_VERSION]) {
self.thisVersionFirstRun = NO;
}
}
[[NSUserDefaults standardUserDefaults] setObject:PRODUCT_CURRENT_VERSION forKey:DEFAULTS_LAST_VERSION_RUN_KEY];
}
+ (instancetype)sharedInstance
{
static id sharedInstance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[CPCodePilotPlugin alloc] init];
});
return sharedInstance;
}
@end