Skip to content

Commit

Permalink
macOS: Use local socket to communicate with finder extension
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjv committed Nov 19, 2021
1 parent 3535be9 commit 2f6bf2f
Show file tree
Hide file tree
Showing 16 changed files with 627 additions and 737 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@

#import <Cocoa/Cocoa.h>
#import <FinderSync/FinderSync.h>
#import "SyncClientProxy.h"

@interface FinderSync : FIFinderSync <SyncClientProxyDelegate>
{
SyncClientProxy *_syncClientProxy;
NSMutableSet *_registeredDirectories;
NSString *_shareMenuTitle;
NSMutableDictionary *_strings;
NSMutableArray *_menuItems;
#import "FinderSyncExt-Swift.h"
#import "SyncClient.h"

@interface FinderSync : FIFinderSync <SyncClientDelegate> {
NSMutableSet *_registeredDirectories;
NSString *_shareMenuTitle;
NSMutableDictionary *_strings;
NSMutableArray *_menuItems;
NSCondition *_menuIsComplete;
}

@property LineProcessorV1 *v1LineProcessor;
@property LocalSocketClient *localSocketClient;

@end
311 changes: 170 additions & 141 deletions shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/FinderSync.m

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "SyncClient.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// LineProcessorV1.swift
// FinderSyncExt
//
// Created by Erik Verbruggen <[email protected]> on 06-11-21.
//

import Foundation
import OSLog

class LineProcessorV1: NSObject, LineProcessor {
let delegate: SyncClientDelegate

@objc init(withDelegate delegate: SyncClientDelegate) {
self.delegate = delegate
}

private func log(_ str: String, type logType: OSLogType) {
// We cannot use OSLog's Logger class, because a lot of methods are only available in macOS 11.0 or higher.
os_log("%@", type: logType, str)
}

/// Processes a line, where the trailing \n has already been stripped
func process(line: String) {

self.log("Processing line '\(line)'", type: .debug)
let chunks = line.components(separatedBy: ":")
let command = chunks[0]

switch command {
case "STATUS":
let result = chunks[1]
let path = chunks.suffix(from: 2).joined(separator: ":")
DispatchQueue.main.async { self.delegate.setResultForPath(path, result: result) }
case "UPDATE_VIEW":
let path = chunks[1]
DispatchQueue.main.async { self.delegate.reFetchFileNameCache(forPath: path) }
case "REGISTER_PATH":
let path = chunks[1]
DispatchQueue.main.async { self.delegate.registerPath(path) }
case "UNREGISTER_PATH":
let path = chunks[1]
DispatchQueue.main.async { self.delegate.unregisterPath(path) }
case "GET_STRINGS":
// BEGIN and END messages, do nothing.
break
case "STRING":
DispatchQueue.main.async { self.delegate.setString(chunks[1], value: chunks[2]) }
case "GET_MENU_ITEMS":
if chunks[1] == "BEGIN" {
DispatchQueue.main.async { self.delegate.resetMenuItems() }
} else {
// Do NOT run this on the main queue! It might be blocked waiting for the menu to be completed.
delegate.menuHasCompleted()
}
case "MENU_ITEM":
let item = [
"command" : chunks[1],
"flags" : chunks[2],
"text" : chunks[3]
]
DispatchQueue.main.async { self.delegate.addMenuItem(item) }
default:
self.log("Unknown command '\(command)'", type: .error)
}
}
}
Loading

0 comments on commit 2f6bf2f

Please sign in to comment.