mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-25 10:09:28 +00:00
Started on Feature #14. Server is now running. But cannot communicate.
This commit is contained in:
@@ -9,13 +9,18 @@
|
||||
#import "MPServerDaemon.h"
|
||||
#import "MPSettingsHelper.h"
|
||||
#import "HTTPServer.h"
|
||||
#import "MPIconHelper.h"
|
||||
#import "MPConnection.h"
|
||||
#import "MPServerRequestHandler.h"
|
||||
|
||||
@interface MPServerDaemon () {
|
||||
@private
|
||||
HTTPServer *server;
|
||||
NSStatusItem *statusItem;
|
||||
}
|
||||
|
||||
@property (nonatomic, assign) BOOL isEnabled;
|
||||
@property (nonatomic, assign) BOOL showStatusItem;
|
||||
|
||||
@end
|
||||
|
||||
@@ -25,14 +30,17 @@
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
|
||||
NSString *defaultsKeyPath = [NSString stringWithFormat:@"values.%@", kMPSettingsKeyEnableHttpServer];
|
||||
[self bind:@"isEnabled" toObject:defaultsController withKeyPath:defaultsKeyPath options:nil];
|
||||
NSString *enableServerKeyPath = [NSString stringWithFormat:@"values.%@", kMPSettingsKeyEnableHttpServer];
|
||||
NSString *showItemKeyPath = [NSString stringWithFormat:@"values.%@", kMPSettingsKeyShowMenuItem];
|
||||
[self bind:@"isEnabled" toObject:defaultsController withKeyPath:enableServerKeyPath options:nil];
|
||||
[self bind:@"showStatusItem" toObject:defaultsController withKeyPath:showItemKeyPath options:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[statusItem release];
|
||||
[server release];
|
||||
[super dealloc];
|
||||
}
|
||||
@@ -47,23 +55,46 @@
|
||||
[self _setupServer];
|
||||
}
|
||||
NSError *error= nil;
|
||||
if(![server start:&error]) {
|
||||
if(![server start:&error]) {
|
||||
[NSApp presentError:error];
|
||||
}
|
||||
// setup menu item
|
||||
}
|
||||
else {
|
||||
/* Do not let the resource linger around */
|
||||
[server release];
|
||||
server = nil;
|
||||
}
|
||||
[self _updateStatusItem];
|
||||
}
|
||||
|
||||
|
||||
- (void)setShowStatusItem:(BOOL)showStatusItem {
|
||||
if(_showStatusItem != showStatusItem) {
|
||||
_showStatusItem = showStatusItem;
|
||||
[self _updateStatusItem];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_updateStatusItem {
|
||||
if(_isEnabled && _showStatusItem) {
|
||||
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
|
||||
[statusItem setImage:[MPIconHelper icon:MPIconServer ]];
|
||||
}
|
||||
else if(statusItem) {
|
||||
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
|
||||
statusItem = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_setupServer {
|
||||
NSAssert(server == nil, @"Server should be nil");
|
||||
server = [[HTTPServer alloc] init];
|
||||
[server setConnectionClass:[MPConnection class]];
|
||||
[server setInterface:@"localhost"];
|
||||
NSInteger port = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyHttpPort];
|
||||
[server setPort:port];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user