Only check network reachability when we know there are remote grammars

Previously we would check network reachability for all unknown file types, even if it lead to no grammar suggestion.
This commit is contained in:
Allan Odgaard
2016-08-19 11:05:07 +02:00
parent 196db13f1d
commit e457c8834f

View File

@@ -1038,7 +1038,7 @@ namespace
{
OakDocument* document = doc->document();
BOOL showBundleSuggestions = ![[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsDisableBundleSuggestionsKey];
if(!document.fileType && showBundleSuggestions && network::can_reach_host([[[NSURL URLWithString:@(REST_API)] host] UTF8String]))
if(!document.fileType && showBundleSuggestions)
{
NSArray<BundleGrammar*>* grammars = document.proposedGrammars;
if(NSArray* excludedGrammars = [[NSUserDefaults standardUserDefaults] arrayForKey:kUserDefaultsGrammarsToNeverSuggestKey])
@@ -1046,7 +1046,7 @@ namespace
if(_bundlesAlreadySuggested)
grammars = [grammars filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"!(bundle IN %@)", _bundlesAlreadySuggested]];
if([grammars count])
if([grammars count] && network::can_reach_host([[[NSURL URLWithString:@(REST_API)] host] UTF8String]))
{
self.bundlesAlreadySuggested = [(_bundlesAlreadySuggested ?: @[ ]) arrayByAddingObject:[grammars firstObject].bundle];