From edf40e0cc7c986caded7c35d1665acf4ef867ae5 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Thu, 11 Oct 2018 15:21:19 +0200 Subject: [PATCH] Created prototype for a plugin browser --- MacPass.xcodeproj/project.pbxproj | 10 + MacPass/MPPluginHost.m | 4 +- .../MPPluginRepositoryBrowserViewController.h | 20 ++ .../MPPluginRepositoryBrowserViewController.m | 81 ++++++++ MacPass/MPPluginSettingsController.m | 10 +- MacPass/PluginRepositoryBrowserView.xib | 193 ++++++++++++++++++ 6 files changed, 312 insertions(+), 6 deletions(-) create mode 100644 MacPass/MPPluginRepositoryBrowserViewController.h create mode 100644 MacPass/MPPluginRepositoryBrowserViewController.m create mode 100644 MacPass/PluginRepositoryBrowserView.xib diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 3fa40aa1..0818e0b6 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -226,6 +226,8 @@ 4CC0D2CE17974A47000B4BDA /* MPCustomFieldTableViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC0D2CD17974A47000B4BDA /* MPCustomFieldTableViewDelegate.m */; }; 4CC0D2D117974A5A000B4BDA /* MPAttachmentTableViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC0D2D017974A5A000B4BDA /* MPAttachmentTableViewDelegate.m */; }; 4CC281891C0F675B00B9174D /* HNHUi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CC281881C0F675B00B9174D /* HNHUi.framework */; }; + 4CC663E7216F7A7100E33965 /* MPPluginRepositoryBrowserViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC663E5216F7A7100E33965 /* MPPluginRepositoryBrowserViewController.m */; }; + 4CC663E8216F7A7100E33965 /* PluginRepositoryBrowserView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CC663E6216F7A7100E33965 /* PluginRepositoryBrowserView.xib */; }; 4CC6DB7A17D23719002C6091 /* KPKNode+IconImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6DB7917D23719002C6091 /* KPKNode+IconImage.m */; }; 4CCA8E9B18D91ED9001A6754 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CCA8E9A18D91ED9001A6754 /* Quartz.framework */; }; 4CCCE8011D75CA48006AA951 /* MPArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCCE8001D75CA48006AA951 /* MPArrayController.m */; }; @@ -755,6 +757,9 @@ 4CC0D2CF17974A5A000B4BDA /* MPAttachmentTableViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAttachmentTableViewDelegate.h; sourceTree = ""; }; 4CC0D2D017974A5A000B4BDA /* MPAttachmentTableViewDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAttachmentTableViewDelegate.m; sourceTree = ""; }; 4CC281881C0F675B00B9174D /* HNHUi.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HNHUi.framework; path = Carthage/Build/Mac/HNHUi.framework; sourceTree = ""; }; + 4CC663E4216F7A7100E33965 /* MPPluginRepositoryBrowserViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPPluginRepositoryBrowserViewController.h; sourceTree = ""; }; + 4CC663E5216F7A7100E33965 /* MPPluginRepositoryBrowserViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPPluginRepositoryBrowserViewController.m; sourceTree = ""; }; + 4CC663E6216F7A7100E33965 /* PluginRepositoryBrowserView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PluginRepositoryBrowserView.xib; sourceTree = ""; }; 4CC6DB7817D23719002C6091 /* KPKNode+IconImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KPKNode+IconImage.h"; sourceTree = ""; }; 4CC6DB7917D23719002C6091 /* KPKNode+IconImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KPKNode+IconImage.m"; sourceTree = ""; }; 4CCA7EEC1797866F00B0B55E /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/GeneralSettings.strings; sourceTree = ""; }; @@ -1556,6 +1561,9 @@ 4C73B6EE215E64A7009787F7 /* MPWelcomeViewController.h */, 4C73B6EF215E64A7009787F7 /* MPWelcomeViewController.m */, 4C7F8B6A1A10B68400CCB83D /* WelcomeView.xib */, + 4CC663E4216F7A7100E33965 /* MPPluginRepositoryBrowserViewController.h */, + 4CC663E5216F7A7100E33965 /* MPPluginRepositoryBrowserViewController.m */, + 4CC663E6216F7A7100E33965 /* PluginRepositoryBrowserView.xib */, ); name = "View Controller"; sourceTree = ""; @@ -1838,6 +1846,7 @@ 4C3826B31AD04D8E007D7D67 /* 38_SambaUnmountTemplate.pdf in Resources */, 4CB9339916D3A0DD00A13B5D /* Credits.rtf in Resources */, 4C08ACEA204F01C700863D99 /* keyboardTemplate.pdf in Resources */, + 4CC663E8216F7A7100E33965 /* PluginRepositoryBrowserView.xib in Resources */, 4C0F04412147FB49000B8568 /* OpenPanelAccessoryView.xib in Resources */, 4C6DCC451FA2457900C8AD3F /* ContextBar.xib in Resources */, 4C431BCF16E2BAB000700A81 /* OverlayWindow.xib in Resources */, @@ -2024,6 +2033,7 @@ 4CF6C3021FBF39BF0055AD03 /* MPPluginTabelCellView.m in Sources */, 4C10412C178CDD44001B5239 /* NSDate+Humanized.m in Sources */, 4C2F17A21FD69BCA0097418D /* MPUserNotificationCenterDelegate.m in Sources */, + 4CC663E7216F7A7100E33965 /* MPPluginRepositoryBrowserViewController.m in Sources */, 4C0C59F118B17F10009C7B76 /* DDHotKeyUtilities.m in Sources */, 4CEE46DD181C301D006BF1E5 /* MPAutotypeDaemon.m in Sources */, 4C50CC041F6C18830095629D /* MPCollectionViewItem.m in Sources */, diff --git a/MacPass/MPPluginHost.m b/MacPass/MPPluginHost.m index 8a9e85ed..b3f1831e 100644 --- a/MacPass/MPPluginHost.m +++ b/MacPass/MPPluginHost.m @@ -133,7 +133,9 @@ NSString *const MPPluginHostPluginBundleIdentifiyerKey = @"MPPluginHostPluginBun - (void)loadPlugins { [MPPluginRepository.defaultRepository fetchRepositoryDataCompletionHandler:^(NSArray * _Nonnull availablePlugins) { - [self _loadPlugins:availablePlugins]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self _loadPlugins:availablePlugins]; + }); }]; } diff --git a/MacPass/MPPluginRepositoryBrowserViewController.h b/MacPass/MPPluginRepositoryBrowserViewController.h new file mode 100644 index 00000000..28be75d8 --- /dev/null +++ b/MacPass/MPPluginRepositoryBrowserViewController.h @@ -0,0 +1,20 @@ +// +// MPPluginRepositoryBrowserViewController.h +// MacPass +// +// Created by Michael Starke on 11.10.18. +// Copyright © 2018 HicknHack Software GmbH. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface MPPluginRepositoryBrowserViewController : NSViewController + +- (IBAction)refresh:(id)sender; +- (IBAction)closeBrowser:(id)sender; + +@end + +NS_ASSUME_NONNULL_END diff --git a/MacPass/MPPluginRepositoryBrowserViewController.m b/MacPass/MPPluginRepositoryBrowserViewController.m new file mode 100644 index 00000000..60707764 --- /dev/null +++ b/MacPass/MPPluginRepositoryBrowserViewController.m @@ -0,0 +1,81 @@ +// +// MPPluginRepositoryBrowserViewController.m +// MacPass +// +// Created by Michael Starke on 11.10.18. +// Copyright © 2018 HicknHack Software GmbH. All rights reserved. +// + +#import "MPPluginRepositoryBrowserViewController.h" +#import "MPPluginRepository.h" +#import "MPPluginRepositoryItem.h" + +NSString *MPPluginBrowserColumnName = @"MPPluginBrowserColumnName"; +NSString *MPPluginBrowserColumnCurrentVersion = @"MPPluginBrowserColumnCurrentVersion"; +NSString *MPPluginBrowserColumnInstalledVersion = @"MPPluginBrowserColumnInstalledVersion"; + +@interface MPPluginRepositoryBrowserViewController () + +@property (copy) NSArray* repositoryItems; +@property (strong) IBOutlet NSTableView *itemTable; + +@end + +@implementation MPPluginRepositoryBrowserViewController + +- (NSNibName)nibName { + return @"PluginRepositoryBrowserView"; +} + +- (void)viewDidLoad { + + self.itemTable.tableColumns[0].identifier = MPPluginBrowserColumnName; + self.itemTable.tableColumns[1].identifier = MPPluginBrowserColumnCurrentVersion; + self.itemTable.tableColumns[2].identifier = MPPluginBrowserColumnInstalledVersion; + + [super viewDidLoad]; + [self _refreshRepository]; +} + +- (void)refresh:(id)sender { + [self _refreshRepository]; +} + +- (IBAction)closeBrowser:(id)sender { + [self.presentingViewController dismissViewController:self]; +} + +- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { + return self.repositoryItems.count > 0 ? 100 : 0; +} + +- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { + + MPPluginRepositoryItem *item = self.repositoryItems.firstObject; + if([tableColumn.identifier isEqualToString:MPPluginBrowserColumnName]) { + NSTableCellView *view = [tableView makeViewWithIdentifier:@"NameCellView" owner:self]; + view.textField.stringValue = item.name; + return view; + } + if([tableColumn.identifier isEqualToString:MPPluginBrowserColumnCurrentVersion]) { + NSTableCellView *view = [tableView makeViewWithIdentifier:@"CurrentVersionCellView" owner:self]; + view.textField.stringValue = item.currentVersion; + return view; + } + NSTableCellView *view = [tableView makeViewWithIdentifier:@"InstalledVersionCellView" owner:self]; + view.textField.stringValue = item.descriptionText; + return view; + +} + +- (void)_refreshRepository { + [MPPluginRepository.defaultRepository fetchRepositoryDataCompletionHandler:^(NSArray * _Nonnull availablePlugins) { + dispatch_async(dispatch_get_main_queue(), ^{ + self.repositoryItems = availablePlugins; + [self.itemTable reloadData]; + }); + }]; +} + + +@end diff --git a/MacPass/MPPluginSettingsController.m b/MacPass/MPPluginSettingsController.m index 54842b58..45d749e1 100644 --- a/MacPass/MPPluginSettingsController.m +++ b/MacPass/MPPluginSettingsController.m @@ -26,8 +26,7 @@ #import "MPPlugin.h" #import "MPPlugin_Private.h" #import "MPPluginConstants.h" -#import "MPPluginRepository.h" -#import "MPPluginRepositoryItem.h" +#import "MPPluginRepositoryBrowserViewController.h" #import "MPConstants.h" #import "MPSettingsHelper.h" @@ -184,7 +183,8 @@ typedef NS_ENUM(NSUInteger, MPPluginSegmentType) { #pragma mark - Actions - (IBAction)browsePlugins:(id)sender { - [NSWorkspace.sharedWorkspace openURL:[NSApp applicationSupportDirectoryURL:YES]]; + [self presentViewControllerAsSheet:[[MPPluginRepositoryBrowserViewController alloc] init]]; + // [NSWorkspace.sharedWorkspace openURL:[NSApp applicationSupportDirectoryURL:YES]]; } - (IBAction)addOrRemovePlugin:(id)sender { @@ -224,7 +224,7 @@ typedef NS_ENUM(NSUInteger, MPPluginSegmentType) { - (void)_addPlugin:(NSURL *)bundleURL { NSError *error; - if(![[MPPluginHost sharedHost] installPluginAtURL:bundleURL error:&error]) { + if(![MPPluginHost.sharedHost installPluginAtURL:bundleURL error:&error]) { [NSApp presentError:error modalForWindow:self.view.window delegate:nil didPresentSelector:NULL contextInfo:NULL]; } else { @@ -252,7 +252,7 @@ typedef NS_ENUM(NSUInteger, MPPluginSegmentType) { - (void)_removePlugin:(MPPlugin *)plugin { NSError *error; - if(![[MPPluginHost sharedHost] uninstallPlugin:plugin error:&error]) { + if(![MPPluginHost.sharedHost uninstallPlugin:plugin error:&error]) { [NSApp presentError:error modalForWindow:self.view.window delegate:nil didPresentSelector:NULL contextInfo:NULL]; } else { diff --git a/MacPass/PluginRepositoryBrowserView.xib b/MacPass/PluginRepositoryBrowserView.xib new file mode 100644 index 00000000..eac8b69c --- /dev/null +++ b/MacPass/PluginRepositoryBrowserView.xib @@ -0,0 +1,193 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +