diff --git a/OpenRA.Launcher.Mac/Controller.h b/OpenRA.Launcher.Mac/Controller.h index 48b4aa37f4..5840cb83a6 100644 --- a/OpenRA.Launcher.Mac/Controller.h +++ b/OpenRA.Launcher.Mac/Controller.h @@ -16,7 +16,6 @@ { SidebarEntry *sidebarItems; GameInstall *game; - JSBridge *jsbridge; IBOutlet NSOutlineView *outlineView; IBOutlet WebView *webView; } diff --git a/OpenRA.Launcher.Mac/Controller.m b/OpenRA.Launcher.Mac/Controller.m index c50b91b192..161de5409b 100644 --- a/OpenRA.Launcher.Mac/Controller.m +++ b/OpenRA.Launcher.Mac/Controller.m @@ -18,8 +18,8 @@ - (void) awakeFromNib { game = [[GameInstall alloc] initWithURL:[NSURL URLWithString:@"/Users/paul/src/OpenRA"]]; - jsbridge = [[JSBridge alloc] initWithController:self]; - + [[JSBridge sharedInstance] setController:self]; + NSTableColumn *col = [outlineView tableColumnWithIdentifier:@"mods"]; ImageAndTextCell *imageAndTextCell = [[[ImageAndTextCell alloc] init] autorelease]; [col setDataCell:imageAndTextCell]; @@ -153,7 +153,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn #pragma mark WebView delegates - (void)webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)windowObject forFrame:(WebFrame *)frame { - [windowObject setValue:jsbridge forKey:@"external"]; + [windowObject setValue:[JSBridge sharedInstance] forKey:@"external"]; } @end diff --git a/OpenRA.Launcher.Mac/JSBridge.h b/OpenRA.Launcher.Mac/JSBridge.h index 770756e814..bd24b753c9 100644 --- a/OpenRA.Launcher.Mac/JSBridge.h +++ b/OpenRA.Launcher.Mac/JSBridge.h @@ -12,7 +12,11 @@ @class Controller; @interface JSBridge : NSObject { Controller *controller; + NSDictionary *methods; } +@property(readonly) NSDictionary *methods; + ++ (JSBridge *)sharedInstance; +- (void)setController:(Controller *)aController; --(id)initWithController:(Controller *)aController; @end diff --git a/OpenRA.Launcher.Mac/JSBridge.m b/OpenRA.Launcher.Mac/JSBridge.m index 4c03cb5224..394119df5d 100644 --- a/OpenRA.Launcher.Mac/JSBridge.m +++ b/OpenRA.Launcher.Mac/JSBridge.m @@ -9,29 +9,71 @@ #import "JSBridge.h" #import "Controller.h" -@implementation JSBridge +static JSBridge *SharedInstance; --(id)initWithController:(Controller *)aController +@implementation JSBridge +@synthesize methods; + ++ (JSBridge *)sharedInstance +{ + if (SharedInstance == nil) + SharedInstance = [[JSBridge alloc] init]; + + return SharedInstance; +} + ++ (NSString *)webScriptNameForSelector:(SEL)sel +{ + return [[[JSBridge sharedInstance] methods] objectForKey:NSStringFromSelector(sel)]; +} + ++ (BOOL)isSelectorExcludedFromWebScript:(SEL)sel +{ + return [[[JSBridge sharedInstance] methods] objectForKey:NSStringFromSelector(sel)] == nil; +} + +-(id)init { self = [super init]; if (self != nil) { - controller = [aController retain]; + methods = [[NSDictionary dictionaryWithObjectsAndKeys: + @"launchCurrentMod", NSStringFromSelector(@selector(launchCurrentMod)), + @"log", NSStringFromSelector(@selector(log:)), + @"fileExistsInMod", NSStringFromSelector(@selector(fileExists:inMod:)), + nil] retain]; } return self; } -- (void) dealloc +- (void)setController:(Controller *)aController +{ + controller = [aController retain]; +} + +- (void)dealloc { [controller release]; controller = nil; [super dealloc]; } +#pragma mark JS methods + - (void)launchCurrentMod { NSLog(@"launchcurrent"); [controller launchGame]; } -+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector { return NO; } +- (void)log:(NSString *)message +{ + NSLog(@"js: %@",message); +} + +- (BOOL)fileExists:(NSString *)aFile inMod:(NSString *)aMod +{ + NSLog(@"File %@ exists in mod %@",aFile, aMod); + return NO; +} + @end diff --git a/mods/cnc/mod.html b/mods/cnc/mod.html index a9177d70ef..f84065e5b1 100644 --- a/mods/cnc/mod.html +++ b/mods/cnc/mod.html @@ -95,7 +95,7 @@