From 28817b6c802719cd2e547e395c6719ef89802e87 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Wed, 26 Jun 2019 13:05:40 +0200 Subject: [PATCH] wired plugin repository download settings and fixed crash when initializing plugin host --- MacPass/Base.lproj/PluginPreferences.xib | 3 ++- MacPass/MPPluginPreferencesController.m | 5 +++++ MacPass/MPPluginRepository.m | 20 +++++++++++++------- MacPass/de.lproj/Localizable.strings | 12 ++++++++++++ MacPass/en.lproj/Localizable.strings | 12 ++++++++++++ 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/MacPass/Base.lproj/PluginPreferences.xib b/MacPass/Base.lproj/PluginPreferences.xib index b79f7c31..1b2c6e0e 100644 --- a/MacPass/Base.lproj/PluginPreferences.xib +++ b/MacPass/Base.lproj/PluginPreferences.xib @@ -9,6 +9,7 @@ + @@ -229,7 +230,7 @@ - + diff --git a/MacPass/MPPluginPreferencesController.m b/MacPass/MPPluginPreferencesController.m index 02c71f9e..eb07bebc 100644 --- a/MacPass/MPPluginPreferencesController.m +++ b/MacPass/MPPluginPreferencesController.m @@ -42,6 +42,7 @@ typedef NS_ENUM(NSUInteger, MPPluginSegmentType) { @interface MPPluginPreferencesController () +@property (strong) IBOutlet NSButton *allowRemoteConnectionCheckButton; @property (strong) IBOutlet NSTableView *pluginTableView; @property (strong) IBOutlet NSView *settingsView; @property (strong) IBOutlet NSView *fallbackSettingsView; @@ -83,6 +84,10 @@ typedef NS_ENUM(NSUInteger, MPPluginSegmentType) { toObject:NSUserDefaultsController.sharedUserDefaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyLoadIncompatiblePlugins] options:nil]; + [self.allowRemoteConnectionCheckButton bind:NSValueBinding + toObject:NSUserDefaultsController.sharedUserDefaultsController + withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyAllowRemoteFetchOfPluginRepository] + options:nil]; [self.pluginTableView registerForDraggedTypes:@[(NSString *)kUTTypeFileURL]]; } diff --git a/MacPass/MPPluginRepository.m b/MacPass/MPPluginRepository.m index e272837f..ff40ad20 100644 --- a/MacPass/MPPluginRepository.m +++ b/MacPass/MPPluginRepository.m @@ -57,7 +57,7 @@ NSString *const MPPluginRepositoryDidUpdateAvailablePluginsNotification = @"com. if(self) { _isInitialized = NO; _lastDataFetchTime = NSDate.distantPast.timeIntervalSinceReferenceDate; - [self _fetchRepositoryDataCompletionHandler:^(NSArray * _Nonnull availablePlugins) { + [self _fetchAppropriateRepositoryDataCompletionHandler:^(NSArray * _Nonnull availablePlugins) { self.availablePlugins = availablePlugins; self.isInitialized = YES; }]; @@ -69,7 +69,7 @@ NSString *const MPPluginRepositoryDidUpdateAvailablePluginsNotification = @"com. /* update cache on every read if it's older than 5 minutes */ if((NSDate.timeIntervalSinceReferenceDate - self.lastDataFetchTime) > 60*5 ) { NSLog(@"%@: updating available plugins cache.", self.className); - [self _fetchRepositoryDataCompletionHandler:^(NSArray * _Nonnull availablePlugins) { + [self _fetchAppropriateRepositoryDataCompletionHandler:^(NSArray * _Nonnull availablePlugins) { self.availablePlugins = availablePlugins; }]; } @@ -88,12 +88,18 @@ NSString *const MPPluginRepositoryDidUpdateAvailablePluginsNotification = @"com. } } +- (void)_fetchAppropriateRepositoryDataCompletionHandler:(void (^)(NSArray * _Nonnull))completionHandler { + /* dispatch the call to allow for direct return and handle resutl later on */ + dispatch_async(dispatch_get_main_queue(), ^{ + BOOL allowRemoteConnection = [self _askForPluginRepositoryPermission]; + if(!allowRemoteConnection) { + [self _fetchLocalFallbackRepositoryData:completionHandler]; + } + [self _fetchRepositoryDataCompletionHandler:completionHandler]; + }); +} + - (void)_fetchRepositoryDataCompletionHandler:(void (^)(NSArray * _Nonnull))completionHandler { - BOOL allowRemoteConnection = [self _askForPluginRepositoryPermission]; - if(!allowRemoteConnection) { - [self _fetchLocalFallbackRepositoryData:completionHandler]; - return; - } NSString *urlString = NSBundle.mainBundle.infoDictionary[MPBundlePluginRepositoryURLKey]; if(!urlString) { [self _fetchLocalFallbackRepositoryData:completionHandler]; diff --git a/MacPass/de.lproj/Localizable.strings b/MacPass/de.lproj/Localizable.strings index 9aaf7d11..8894679c 100644 --- a/MacPass/de.lproj/Localizable.strings +++ b/MacPass/de.lproj/Localizable.strings @@ -37,6 +37,18 @@ /* Action to add an entry via template */ "ADD_TREMPLATE_ENTRY" = "Vorgabeeintrag erstellen"; +/* Allow the download of the plugin repository file */ +"ALERT_ASK_FOR_PLUGIN_REPOSITORY_ALLOW_DOWNLOAD" = "Keine Daten herunterladen."; + +/* Informative text displayed on the alert that shows up when MacPass asks for permssion to download the plugin repository JSON file */ +"ALERT_ASK_FOR_PLUGIN_REPOSITORY_CONNECTION_PERMISSION_INFORMATIVE_TEXT" = "Das Verzeichnis ist auf https://macpassapp.org hinterlegt. MacPass verbindet lädt die Defintionen herunter um sicher zu stellen, dass alle Daten auf dem neusten Stand sind."; + +/* Message displayed on the alert that askf for permission to download the plugin repository JSON file */ +"ALERT_ASK_FOR_PLUGIN_REPOSITORY_CONNECTION_PERMISSION_MESSAGE" = "MacPass möchte das Pluginverzeichnis aktualisieren."; + +/* Disallow the download of the plugin repository file */ +"ALERT_ASK_FOR_PLUGIN_REPOSITORY_DISALLOW_DOWNLOAD" = "Aktualisiere Daten online."; + /* Button in dialog to leave autotype disabled and continiue! */ "ALERT_AUTOTYPE_MISSING_ACCESSIBILTY_PERMISSIONS_BUTTON_OK" = "Autotype deaktiviert lassen."; diff --git a/MacPass/en.lproj/Localizable.strings b/MacPass/en.lproj/Localizable.strings index 403fa1bf..4e211e67 100644 --- a/MacPass/en.lproj/Localizable.strings +++ b/MacPass/en.lproj/Localizable.strings @@ -37,6 +37,18 @@ /* Action to add an entry via template */ "ADD_TREMPLATE_ENTRY" = "Create Template Entry"; +/* Allow the download of the plugin repository file */ +"ALERT_ASK_FOR_PLUGIN_REPOSITORY_ALLOW_DOWNLOAD" = "Do not update defintions"; + +/* Informative text displayed on the alert that shows up when MacPass asks for permssion to download the plugin repository JSON file */ +"ALERT_ASK_FOR_PLUGIN_REPOSITORY_CONNECTION_PERMISSION_INFORMATIVE_TEXT" = "The plugin defintions are hosted online at https://macpassapp.org. MacPass would like to download those files to ensure the data is up to date."; + +/* Message displayed on the alert that askf for permission to download the plugin repository JSON file */ +"ALERT_ASK_FOR_PLUGIN_REPOSITORY_CONNECTION_PERMISSION_MESSAGE" = "MacPass would like to check for updates of plugin defintions online"; + +/* Disallow the download of the plugin repository file */ +"ALERT_ASK_FOR_PLUGIN_REPOSITORY_DISALLOW_DOWNLOAD" = "Update definitions online"; + /* Button in dialog to leave autotype disabled and continiue! */ "ALERT_AUTOTYPE_MISSING_ACCESSIBILTY_PERMISSIONS_BUTTON_OK" = "Keep Autotype disabled.";