Skip to content

Commit 16acce0

Browse files
committed
macOS: Use local socket to communicate with finder extension
#6343
1 parent 3535be9 commit 16acce0

File tree

16 files changed

+627
-737
lines changed

16 files changed

+627
-737
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/FinderSync.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@
1515

1616
#import <Cocoa/Cocoa.h>
1717
#import <FinderSync/FinderSync.h>
18-
#import "SyncClientProxy.h"
1918

20-
@interface FinderSync : FIFinderSync <SyncClientProxyDelegate>
21-
{
22-
SyncClientProxy *_syncClientProxy;
23-
NSMutableSet *_registeredDirectories;
24-
NSString *_shareMenuTitle;
25-
NSMutableDictionary *_strings;
26-
NSMutableArray *_menuItems;
19+
#import "FinderSyncExt-Swift.h"
20+
#import "SyncClient.h"
21+
22+
@interface FinderSync : FIFinderSync <SyncClientDelegate> {
23+
NSMutableSet *_registeredDirectories;
24+
NSString *_shareMenuTitle;
25+
NSMutableDictionary *_strings;
26+
NSMutableArray *_menuItems;
27+
NSCondition *_menuIsComplete;
2728
}
2829

30+
@property LineProcessorV1 *v1LineProcessor;
31+
@property LocalSocketClient *localSocketClient;
32+
2933
@end

shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/FinderSync.m

Lines changed: 170 additions & 141 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//
2+
// Use this file to import your target's public headers that you would like to expose to Swift.
3+
//
4+
5+
#import "SyncClient.h"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// LineProcessorV1.swift
3+
// FinderSyncExt
4+
//
5+
// Created by Erik Verbruggen <[email protected]> on 06-11-21.
6+
//
7+
8+
import Foundation
9+
import OSLog
10+
11+
class LineProcessorV1: NSObject, LineProcessor {
12+
let delegate: SyncClientDelegate
13+
14+
@objc init(withDelegate delegate: SyncClientDelegate) {
15+
self.delegate = delegate
16+
}
17+
18+
private func log(_ str: String, type logType: OSLogType) {
19+
// We cannot use OSLog's Logger class, because a lot of methods are only available in macOS 11.0 or higher.
20+
os_log("%@", type: logType, str)
21+
}
22+
23+
/// Processes a line, where the trailing \n has already been stripped
24+
func process(line: String) {
25+
26+
self.log("Processing line '\(line)'", type: .debug)
27+
let chunks = line.components(separatedBy: ":")
28+
let command = chunks[0]
29+
30+
switch command {
31+
case "STATUS":
32+
let result = chunks[1]
33+
let path = chunks.suffix(from: 2).joined(separator: ":")
34+
DispatchQueue.main.async { self.delegate.setResultForPath(path, result: result) }
35+
case "UPDATE_VIEW":
36+
let path = chunks[1]
37+
DispatchQueue.main.async { self.delegate.reFetchFileNameCache(forPath: path) }
38+
case "REGISTER_PATH":
39+
let path = chunks[1]
40+
DispatchQueue.main.async { self.delegate.registerPath(path) }
41+
case "UNREGISTER_PATH":
42+
let path = chunks[1]
43+
DispatchQueue.main.async { self.delegate.unregisterPath(path) }
44+
case "GET_STRINGS":
45+
// BEGIN and END messages, do nothing.
46+
break
47+
case "STRING":
48+
DispatchQueue.main.async { self.delegate.setString(chunks[1], value: chunks[2]) }
49+
case "GET_MENU_ITEMS":
50+
if chunks[1] == "BEGIN" {
51+
DispatchQueue.main.async { self.delegate.resetMenuItems() }
52+
} else {
53+
// Do NOT run this on the main queue! It might be blocked waiting for the menu to be completed.
54+
delegate.menuHasCompleted()
55+
}
56+
case "MENU_ITEM":
57+
let item = [
58+
"command" : chunks[1],
59+
"flags" : chunks[2],
60+
"text" : chunks[3]
61+
]
62+
DispatchQueue.main.async { self.delegate.addMenuItem(item) }
63+
default:
64+
self.log("Unknown command '\(command)'", type: .error)
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)