From aceff1f8632d159922d49dbcaa1aaf930a4a2fed Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 11 Apr 2018 13:40:27 +0200 Subject: macOS: Implement new dynamic Finder menu items #6328 --- .../FinderSyncExt/SyncClientProxy.m | 38 ++++++++++++++-------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/SyncClientProxy.m') diff --git a/shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/SyncClientProxy.m b/shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/SyncClientProxy.m index b7b64571f..656f77003 100644 --- a/shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/SyncClientProxy.m +++ b/shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/SyncClientProxy.m @@ -27,7 +27,7 @@ - (instancetype)initWithDelegate:(id)arg1 serverName:(NSString*)serverName { self = [super init]; - + self.delegate = arg1; _serverName = serverName; _remoteEnd = nil; @@ -41,20 +41,20 @@ { if (_remoteEnd) return; - + // Lookup the server connection NSConnection *conn = [NSConnection connectionWithRegisteredName:_serverName host:nil]; - + if (!conn) { // Could not connect to the sync client [self scheduleRetry]; return; } - + [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(connectionDidDie:) - name:NSConnectionDidDieNotification - object:conn]; + selector:@selector(connectionDidDie:) + name:NSConnectionDidDieNotification + object:conn]; NSDistantObject *server = (NSDistantObject *)[conn rootProxy]; assert(server); @@ -71,7 +71,7 @@ // The server replied with the distant object that we will use for tx _remoteEnd = (NSDistantObject *)tx; [_remoteEnd setProtocolForProxy:@protocol(ChannelProtocol)]; - + // Everything is set up, start querying [self askOnSocket:@"" query:@"GET_STRINGS"]; } @@ -83,7 +83,7 @@ - (void)connectionDidDie:(NSNotification*)notification { -#pragma unused(notification) +#pragma unused(notification) _remoteEnd = nil; [_delegate connectionDidDie]; @@ -95,11 +95,11 @@ - (void)sendMessage:(NSData*)msg { NSString *answer = [[NSString alloc] initWithData:msg encoding:NSUTF8StringEncoding]; - - // Cut the trailing newline + + // Cut the trailing newline. We always only receive one line from the client. answer = [answer substringToIndex:[answer length] - 1]; NSArray *chunks = [answer componentsSeparatedByString: @":"]; - + if( [[chunks objectAtIndex:0] isEqualToString:@"STATUS"] ) { NSString *result = [chunks objectAtIndex:1]; NSString *path = [chunks objectAtIndex:2]; @@ -123,6 +123,18 @@ // BEGIN and END messages, do nothing. } else if( [[chunks objectAtIndex:0 ] isEqualToString:@"STRING"] ) { [_delegate setString:[chunks objectAtIndex:1] value:[chunks objectAtIndex:2]]; + } else if( [[chunks objectAtIndex:0 ] isEqualToString:@"GET_MENU_ITEMS"] ) { + if ([[chunks objectAtIndex:1] isEqualToString:@"BEGIN"]) { + [_delegate resetMenuItems]; + } else if ([[chunks objectAtIndex:1] isEqualToString:@"END"]) { + // Don't do anything special, the askOnSocket call in FinderSync menuForMenuKind will return after this line + } + } else if( [[chunks objectAtIndex:0 ] isEqualToString:@"MENU_ITEM"] ) { + NSMutableDictionary *item = [[NSMutableDictionary alloc] init]; + [item setValue:[chunks objectAtIndex:1] forKey:@"command"]; // e.g. "COPY_PRIVATE_LINK" + [item setValue:[chunks objectAtIndex:2] forKey:@"flags"]; // e.g. "d" + [item setValue:[chunks objectAtIndex:3] forKey:@"text"]; // e.g. "Copy private link to clipboard" + [_delegate addMenuItem:item]; } else { NSLog(@"SyncState: Unknown command %@", [chunks objectAtIndex:0]); } @@ -131,7 +143,7 @@ - (void)askOnSocket:(NSString*)path query:(NSString*)verb { NSString *query = [NSString stringWithFormat:@"%@:%@\n", verb,path]; - + @try { [_remoteEnd sendMessage:[query dataUsingEncoding:NSUTF8StringEncoding]]; } @catch(NSException* e) { -- cgit v1.2.3