download plugin archive works

This commit is contained in:
Michael Starke
2019-02-04 16:06:23 +01:00
parent 07309b5c24
commit e5ad0728cc
2 changed files with 19 additions and 18 deletions

View File

@@ -47,8 +47,9 @@ typedef NS_ENUM(NSUInteger, MPPluginTableColumn) {
- (void)executePluginAction:(id)sender {
NSInteger tableRow = [self.itemTable rowForView:sender];
if(tableRow < -1 && tableRow < self.repositoryItems.count) {
if(tableRow > -1 && tableRow < self.repositoryItems.count) {
MPPluginRepositoryItem *actionItem = self.repositoryItems[tableRow];
[self _downloadPluginForItem:actionItem];
}
}
@@ -58,6 +59,7 @@ typedef NS_ENUM(NSUInteger, MPPluginTableColumn) {
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSTableCellView *view = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
MPPluginRepositoryItem *item = self.repositoryItems[row];
NSUInteger column = [tableView.tableColumns indexOfObjectIdenticalTo:tableColumn];
@@ -71,6 +73,7 @@ typedef NS_ENUM(NSUInteger, MPPluginTableColumn) {
else if(column == MPPluginTableColumnStatus) {
MPPluginStatusTableCellView *statusView = (MPPluginStatusTableCellView *)view;
statusView.actionButton.title = NSLocalizedString(@"PLUGIN_BROWSER_DOWNLOAD_PLUGIN_BUTTON", "Button to download the Plugin");
MPPlugin *plugin = [MPPluginHost.sharedHost pluginWithBundleIdentifier:item.bundleIdentifier];
if(plugin) {
switch([MPPluginVersionComparator compareVersion:plugin.shortVersionString toVersion:item.currentVersion]) {
@@ -95,26 +98,24 @@ typedef NS_ENUM(NSUInteger, MPPluginTableColumn) {
return view;
}
- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row {
NSLog(@"%@", NSStringFromSelector(_cmd));
return YES;
}
- (void)tableViewSelectionIsChanging:(NSNotification *)notification {
NSLog(@"%@", NSStringFromSelector(_cmd));
}
- (void)tableViewSelectionDidChange:(NSNotification *)notification {
NSLog(@"%@", NSStringFromSelector(_cmd));
}
- (void)_refreshRepository {
self.repositoryItems = MPPluginRepository.defaultRepository.availablePlugins;
[self.itemTable reloadData];
}
- (void)_downloadPluginAtURL:(NSURL *)url {
NSURLSessionDownloadTask *taks = [NSURLSession.sharedSession downloadTaskWithURL:url];
- (void)_downloadPluginForItem:(MPPluginRepositoryItem *)item {
NSURL *url = item.downloadURL;
NSURLSessionDownloadTask *task = [NSURLSession.sharedSession downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
if(httpResponse.statusCode == 200) {
if(location) {
NSError *error;
NSURL *downloadFolderURL = [NSFileManager.defaultManager URLsForDirectory:NSDownloadsDirectory inDomains:NSUserDomainMask].firstObject;
NSURL *fileURL = [downloadFolderURL URLByAppendingPathComponent:httpResponse.suggestedFilename];
[NSFileManager.defaultManager moveItemAtURL:location toURL:fileURL error:&error];
}
}
}];
[task resume];
}
@end

View File

@@ -25,7 +25,7 @@
<rect key="frame" x="1" y="0.0" width="596" height="418"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="sequential" alternatingRowBackgroundColors="YES" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="24" rowSizeStyle="systemDefault" headerView="uVe-04-Now" viewBased="YES" id="gDR-Fx-c0h">
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="sequential" alternatingRowBackgroundColors="YES" columnReordering="NO" columnResizing="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" rowHeight="24" rowSizeStyle="systemDefault" headerView="uVe-04-Now" viewBased="YES" id="gDR-Fx-c0h">
<rect key="frame" x="0.0" y="0.0" width="599" height="395"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>