diff --git a/Frameworks/DocumentWindow/src/FileTypeDialog.mm b/Frameworks/DocumentWindow/src/FileTypeDialog.mm index cd21ce78..a1398633 100644 --- a/Frameworks/DocumentWindow/src/FileTypeDialog.mm +++ b/Frameworks/DocumentWindow/src/FileTypeDialog.mm @@ -205,15 +205,22 @@ static bool is_installed (oak::uuid_t const& uuid) { if(bundleUUID == (*bundle)->uuid()) { - [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkIfBundleIsInstalled:) userInfo:[grammar objectForKey:@"uuid"] repeats:YES]; - [[BundlesManager sharedInstance] installBundle:*bundle completionHandler:nil]; [installingBundleActivityTextField bind:NSValueBinding toObject:[BundlesManager sharedInstance] withKeyPath:@"activityText" options:nil]; [installingBundleProgressIndicator bind:NSValueBinding toObject:[BundlesManager sharedInstance] withKeyPath:@"progress" options:nil]; [installingBundleProgressIndicator bind:NSIsIndeterminateBinding toObject:[BundlesManager sharedInstance] withKeyPath:@"determinateProgress" options:@{ NSValueTransformerNameBindingOption: @"NSNegateBoolean" }]; [installingBundleProgressIndicator startAnimation:self]; - OakShowSheetForWindow(installingBundleWindow, aWindow, ^(NSInteger returnCode){ - aCompletionHandler(self.fileType); - }); + + OakShowSheetForWindow(installingBundleWindow, aWindow, ^(NSInteger returnCode){ }); + + [[BundlesManager sharedInstance] installBundle:*bundle completionHandler:^(BOOL success){ + [installingBundleProgressIndicator stopAnimation:self]; + [installingBundleProgressIndicator unbind:NSValueBinding]; + [installingBundleActivityTextField unbind:NSValueBinding]; + [NSApp endSheet:installingBundleWindow]; + [installingBundleWindow orderOut:self]; + + aCompletionHandler(is_installed(uuid) ? self.fileType : @"text.plain"); + }]; return; } } @@ -222,21 +229,6 @@ static bool is_installed (oak::uuid_t const& uuid) }); } -- (void)checkIfBundleIsInstalled:(NSTimer*)aTimer -{ - NSString* uuid = [aTimer userInfo]; - if(is_installed(to_s(uuid))) - { - [aTimer invalidate]; - - [installingBundleProgressIndicator stopAnimation:self]; - [installingBundleProgressIndicator unbind:NSValueBinding]; - [installingBundleActivityTextField unbind:NSValueBinding]; - [NSApp endSheet:installingBundleWindow]; - [installingBundleWindow orderOut:self]; - } -} - - (IBAction)performOpenDocument:(id)sender { [self.window orderOut:self];