mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 13:05:51 +03:00
SocketApi: Port OS X to use local sockets
This commit is contained in:
parent
0539098371
commit
f8b73eb9d9
3 changed files with 42 additions and 10 deletions
|
@ -183,9 +183,19 @@ static RequestManager* sharedInstance = nil;
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
-(void)socket:(GCDAsyncSocket*)socket didConnectToUrl:(NSURL *)url {
|
||||
NSLog(@"didConnectToUrl %@", url);
|
||||
[self socketDidConnect:socket];
|
||||
}
|
||||
|
||||
- (void)socket:(GCDAsyncSocket*)socket didConnectToHost:(NSString*)host port:(UInt16)port
|
||||
{
|
||||
NSLog( @"Connected to host successfully!");
|
||||
[self socketDidConnect:socket];
|
||||
}
|
||||
|
||||
// Our impl
|
||||
- (void)socketDidConnect:(GCDAsyncSocket*)socket {
|
||||
NSLog( @"Connected to sync client successfully!");
|
||||
_isConnected = YES;
|
||||
_isRunning = NO;
|
||||
|
||||
|
@ -234,12 +244,27 @@ static RequestManager* sharedInstance = nil;
|
|||
{
|
||||
if (!_isRunning)
|
||||
{
|
||||
NSLog(@"Connect Socket!");
|
||||
NSError *err = nil;
|
||||
if (![_socket connectToHost:@"localhost" onPort:34001 withTimeout:5 error:&err]) // Asynchronous!
|
||||
{
|
||||
// If there was an error, it's likely something like "already connected" or "no delegate set"
|
||||
NSLog(@"I goofed: %@", err);
|
||||
BOOL useTcp = NO;
|
||||
if (useTcp) {
|
||||
NSLog(@"Connect Socket");
|
||||
if (![_socket connectToHost:@"localhost" onPort:34001 withTimeout:5 error:&err]) {
|
||||
// If there was an error, it's likely something like "already connected" or "no delegate set"
|
||||
NSLog(@"I goofed: %@", err);
|
||||
}
|
||||
} else if (!useTcp) {
|
||||
NSURL *url;
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
if ([paths count])
|
||||
{
|
||||
// file:///Users/guruz/Library/Caches/SyncStateHelper/ownCloud.socket
|
||||
// FIXME Generify this and support all sockets there since multiple sync clients might be running
|
||||
url =[NSURL fileURLWithPath:[[[paths objectAtIndex:0] stringByAppendingPathComponent:@"SyncStateHelper"] stringByAppendingPathComponent:@"ownCloud.socket"]];
|
||||
}
|
||||
if (url) {
|
||||
NSLog(@"Connect Socket to %@", url);
|
||||
[_socket connectToUrl:url withTimeout:5 error:&err];
|
||||
}
|
||||
}
|
||||
|
||||
_isRunning = YES;
|
||||
|
|
|
@ -241,6 +241,14 @@ SocketApi::SocketApi(QObject* parent)
|
|||
if (Utility::isWindows()) {
|
||||
socketPath = QLatin1String("\\\\.\\pipe\\")
|
||||
+ Theme::instance()->appName();
|
||||
} else if (Utility::isMac()) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
// Always using Qt5 on OS X
|
||||
QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
|
||||
socketPath = runtimeDir + "/SyncStateHelper/" + Theme::instance()->appName() + ".socket";
|
||||
// We use the generic SyncStateHelper name on OS X since the different branded clients
|
||||
// should unfortunately not mention that they are ownCloud :-)
|
||||
#endif
|
||||
} else {
|
||||
QString runtimeDir;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
|
|
|
@ -33,10 +33,9 @@ class QStringList;
|
|||
|
||||
namespace Mirall {
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
// There is no easy way to use the socket API from non Qt mac applications
|
||||
#define SOCKETAPI_TCP
|
||||
#endif
|
||||
//Define this to use the old school TCP API. Maybe we should offer both APIs
|
||||
// and have the old TCP one be enableable via command line switch?
|
||||
//#define SOCKETAPI_TCP
|
||||
|
||||
#ifdef SOCKETAPI_TCP
|
||||
typedef QTcpSocket SocketType;
|
||||
|
|
Loading…
Reference in a new issue