mirror of
https://github.com/chylex/Nextcloud-Desktop.git
synced 2025-04-09 19:15:43 +02:00
MocOverlays: Handle the UPDATE_VIEW socket notification correctly.
With UPDATE_VIEW the plugin gets notified to update the overlays. It invalidates the entries in the file icon cache for the path that comes with the UPDATE_VIEW and than refreshes the view.
This commit is contained in:
parent
a6987ad703
commit
86acdf69d9
shell_integration/MacOSX/LiferayNativityFinder
@ -28,5 +28,6 @@
|
||||
- (void)removeIcons:(NSArray*)paths;
|
||||
- (void)setIcons:(NSDictionary*)iconDictionary filterByFolder:(NSString*)filterFolder;
|
||||
- (void)setResultForPath:(NSString*)path result:(NSString*)result;
|
||||
- (void)clearFileNameCacheForPath:(NSString*)path;
|
||||
|
||||
@end
|
@ -77,7 +77,7 @@ static ContentManager* sharedInstance = nil;
|
||||
int res = 0; // NOP
|
||||
if( [result isEqualToString:@"OK"] ) {
|
||||
res = 1;
|
||||
} else if( [result isEqualToString:@"NEED_SYNC"]) {
|
||||
} else if( [result isEqualToString:@"SYNC"] || [result isEqualToString:@"NEW"] ) {
|
||||
res = 2;
|
||||
} else if( [result isEqualToString:@"IGNORE"]) {
|
||||
res = 3;
|
||||
@ -112,7 +112,7 @@ static ContentManager* sharedInstance = nil;
|
||||
NSString* normalizedPath = [path decomposedStringWithCanonicalMapping];
|
||||
|
||||
NSNumber* result = [_fileNamesCache objectForKey:normalizedPath];
|
||||
NSLog(@"XXXXXXX Asking for icon for path %@ = %d",path, [result intValue]);
|
||||
// NSLog(@"XXXXXXX Asking for icon for path %@ = %d",path, [result intValue]);
|
||||
|
||||
if( result == nil ) {
|
||||
// start the async call
|
||||
@ -126,11 +126,34 @@ static ContentManager* sharedInstance = nil;
|
||||
} else {
|
||||
// there is a proper icon index
|
||||
}
|
||||
NSLog(@"iconByPath return value %d", [result intValue]);
|
||||
// NSLog(@"iconByPath return value %d", [result intValue]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// called as a result of an UPDATE_VIEW message.
|
||||
// it clears the entries from the hash to make it call again home to mirall.
|
||||
- (void)clearFileNameCacheForPath:(NSString*)path
|
||||
{
|
||||
NSMutableArray *keysToDelete = [NSMutableArray array];
|
||||
NSLog(@"Clearing the cache for %@", path);
|
||||
|
||||
for (id path in [_fileNamesCache keyEnumerator]) {
|
||||
//do stuff with obj
|
||||
if ( [path hasPrefix:path] ) {
|
||||
[keysToDelete addObject:path];
|
||||
}
|
||||
}
|
||||
|
||||
if( [keysToDelete count] > 0 ) {
|
||||
NSLog( @"Entries to delete: %d", [keysToDelete count]);
|
||||
[_fileNamesCache removeObjectsForKeys:keysToDelete];
|
||||
|
||||
[self repaintAllWindows];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeAllIcons
|
||||
{
|
||||
[_fileNamesCache removeAllObjects];
|
||||
|
@ -78,7 +78,7 @@
|
||||
}
|
||||
|
||||
NSNumber* imageIndex = [[ContentManager sharedInstance] iconByPath:[url path] isDirectory:isDir];
|
||||
NSLog(@"2 The icon index is %d", [imageIndex intValue]);
|
||||
// NSLog(@"2 The icon index is %d", [imageIndex intValue]);
|
||||
|
||||
if ([imageIndex intValue] > 0)
|
||||
{
|
||||
|
@ -92,10 +92,43 @@ static RequestManager* sharedInstance = nil;
|
||||
}
|
||||
|
||||
|
||||
- (void)socket:(GCDAsyncSocket*)socket didReadData:(NSData*)data withTag:(long)tag
|
||||
{
|
||||
NSArray *chunks;
|
||||
NSString *answer = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
if (answer != nil && [answer length] > 0) {
|
||||
// cut a trailing newline
|
||||
answer = [answer substringToIndex:[answer length] - 1];
|
||||
chunks = [answer componentsSeparatedByString: @":"];
|
||||
}
|
||||
NSLog(@"READ from socket (%ld): <%@>", tag, answer);
|
||||
ContentManager *contentman = [ContentManager sharedInstance];
|
||||
|
||||
if( [chunks count] > 0 && tag == READ_TAG ) {
|
||||
if( [[chunks objectAtIndex:0] isEqualToString:@"STATUS"] ) {
|
||||
[contentman setResultForPath:[chunks objectAtIndex:2] result:[chunks objectAtIndex:1]];
|
||||
} else if( [[chunks objectAtIndex:0] isEqualToString:@"UPDATE_VIEW"] ) {
|
||||
[contentman clearFileNameCacheForPath:[chunks objectAtIndex:1]]; // Fixme: index1 can be empty
|
||||
} else {
|
||||
NSLog(@"Unknown command %@", [chunks objectAtIndex:0]);
|
||||
}
|
||||
} else {
|
||||
NSLog(@"Received unknown tag %ld", tag);
|
||||
}
|
||||
// Read on and on
|
||||
NSData* stop = [@"\n" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
[_socket readDataToData:stop withTimeout:-1 tag:READ_TAG];
|
||||
|
||||
}
|
||||
|
||||
- (NSTimeInterval)socket:(GCDAsyncSocket*)socket shouldTimeoutReadWithTag:(long)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length
|
||||
{
|
||||
// Called if a read operation has reached its timeout without completing.
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
- (void)socket:(GCDAsyncSocket*)socket didConnectToHost:(NSString*)host port:(UInt16)port
|
||||
{
|
||||
// [socket readDataToData:[GCDAsyncSocket CRLFData] withTimeout:-1 tag:0];
|
||||
|
||||
NSLog( @"Connected to host successfully!");
|
||||
_isConnected = YES;
|
||||
|
||||
@ -105,41 +138,17 @@ static RequestManager* sharedInstance = nil;
|
||||
[self askOnSocket:path];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)socket:(GCDAsyncSocket*)socket didReadData:(NSData*)data withTag:(long)tag
|
||||
{
|
||||
|
||||
if( tag == READ_TAG) {
|
||||
NSString *answer = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
|
||||
// Cut the trailing newline.
|
||||
if ([answer length] > 0) {
|
||||
answer = [answer substringToIndex:[answer length] - 1];
|
||||
}
|
||||
|
||||
NSLog(@"READ from socket (%ld): <%@>", tag, answer);
|
||||
// Read for the UPDATE_VIEW requests
|
||||
NSData* stop = [@"\n" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
[_socket readDataToData:stop withTimeout:-1 tag:READ_TAG];
|
||||
|
||||
if( answer != nil ) {
|
||||
NSArray *chunks = [answer componentsSeparatedByString: @":"];
|
||||
|
||||
if( [chunks count] > 0 && [[chunks objectAtIndex:0] isEqualToString:@"STATUS"] ) {
|
||||
ContentManager *contentman = [ContentManager sharedInstance];
|
||||
[contentman setResultForPath:[chunks objectAtIndex:2] result:[chunks objectAtIndex:1]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSTimeInterval)socket:(GCDAsyncSocket*)socket shouldTimeoutReadWithTag:(long)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length
|
||||
{
|
||||
// Called if a read operation has reached its timeout without completing.
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
- (void)socketDidDisconnect:(GCDAsyncSocket*)socket withError:(NSError*)err
|
||||
{
|
||||
NSLog(@"Socket DISconnected!");
|
||||
|
||||
if ([_connectedListenSockets containsObject:socket])
|
||||
{
|
||||
[_connectedListenSockets removeObject:socket];
|
||||
@ -165,7 +174,6 @@ static RequestManager* sharedInstance = nil;
|
||||
// If there was an error, it's likely something like "already connected" or "no delegate set"
|
||||
NSLog(@"I goofed: %@", err);
|
||||
}
|
||||
NSLog(@"Socket Connected!");
|
||||
|
||||
_isRunning = YES;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user