@@ -139,6 +139,21 @@ - (void)awakeFromNib
139139 */
140140- (void )applicationDidFinishLaunching : (NSNotification *)notification
141141{
142+ NSDictionary *spfDict = nil ;
143+ NSArray *args = [[NSProcessInfo processInfo ] arguments ];
144+ if (args.count == 5 ) {
145+ if (([[args objectAtIndex: 1 ] isEqualToString: @" --spfData" ] && [[args objectAtIndex: 3 ] isEqualToString: @" --dataVersion" ] && [[args objectAtIndex: 4 ] isEqualToString: @" 1" ]) || ([[args objectAtIndex: 3 ] isEqualToString: @" --spfData" ] && [[args objectAtIndex: 1 ] isEqualToString: @" --dataVersion" ] && [[args objectAtIndex: 2 ] isEqualToString: @" 1" ])) {
146+ NSData * data = [[args objectAtIndex: 2 ] dataUsingEncoding: NSUTF8StringEncoding];
147+ NSError *error = nil ;
148+ spfDict = [NSPropertyListSerialization propertyListWithData: data options: 0 format: NULL error: &error];
149+ if (error) {
150+ spfDict = nil ;
151+ }
152+ }
153+ }
154+
155+ [[NSDistributedNotificationCenter defaultCenter ] addObserver: self selector: @selector (externalApplicationWantsToOpenADatabaseConnection: ) name: @" ExternalApplicationWantsToOpenADatabaseConnection" object: nil ];
156+
142157 // Set ourselves as the crash reporter delegate
143158 [[FRFeedbackReporter sharedReporter ] setDelegate: self ];
144159
@@ -151,14 +166,49 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
151166 // If no documents are open, open one
152167 if (![self frontDocument ]) {
153168 [self newWindow: self ];
154-
169+
170+ if (spfDict) {
171+ [[self frontDocument ] setState: spfDict];
172+ }
173+
155174 // Set autoconnection if appropriate
156175 if ([[NSUserDefaults standardUserDefaults ] boolForKey: SPAutoConnectToDefault]) {
157176 [[self frontDocument ] connect ];
158177 }
159178 }
160179}
161180
181+
182+ - (void )externalApplicationWantsToOpenADatabaseConnection : (NSNotification *)notification
183+ {
184+ SPWindowController *frontController = nil ;
185+
186+ for (NSWindow *aWindow in [NSApp orderedWindows ]) {
187+ if ([[aWindow windowController ] isMemberOfClass: [SPWindowController class ]]) {
188+ frontController = [aWindow windowController ];
189+ break ;
190+ }
191+ }
192+
193+ // If no window was found or the front most window has no tabs, create a new one
194+ if (!frontController || [[frontController valueForKeyPath: @" tabView" ] numberOfTabViewItems ] == 1 ) {
195+ [self newWindow: self ];
196+ // Open the spf file in a new tab if the tab bar is visible
197+ } else if ([[frontController valueForKeyPath: @" tabView" ] numberOfTabViewItems ] != 1 ) {
198+ if ([[frontController window ] isMiniaturized ]) [[frontController window ] deminiaturize: self ];
199+ [frontController addNewConnection: self ];
200+ }
201+
202+ NSDictionary *userInfo = [notification userInfo ];
203+ NSString *MAMP_SPFVersion = [userInfo objectForKey: @" dataVersion" ];
204+ if ([MAMP_SPFVersion isEqualToString: @" 1" ]) {
205+ NSDictionary *spfStructure = [userInfo objectForKey: @" spfData" ];
206+ if (spfStructure) {
207+ [[self frontDocument ] setState: spfStructure];
208+ }
209+ }
210+ }
211+
162212/* *
163213 * Menu item validation.
164214 */
0 commit comments