Opened 11 years ago

Closed 11 years ago

#1409 closed Enhancement (Fixed)

NSUserDefaults in JavaScript Plugin

Reported by: Jeena Owned by: timothy
Component: Colloquy (Mac) Version: Local Build
Severity: Normal Keywords: NSUserDefaults
Cc:

Description

Hi,

I wanted to write a JavaScript? plugin which does save the last.fm username in the defaults. Unfortunately the plugin SDK does not allow the JavaScript? to comunicate with NSUserDefaults. I wrote a patch and hope that it will be implemented as soon as possible so I can distribute my plugin :-).

There are 5 lines of code which have to be added, see the diff:

Index: Plug-Ins/JavaScript Support/JVJavaScriptChatPlugin.m
===================================================================
--- Plug-Ins/JavaScript Support/JVJavaScriptChatPlugin.m	(revision 4185)
+++ Plug-Ins/JavaScript Support/JVJavaScriptChatPlugin.m	(working copy)
@@ -235,6 +235,7 @@
 	[[webView windowScriptObject] setValue:[JVSpeechController sharedSpeechController] forKey:@"SpeechController"];
 	[[webView windowScriptObject] setValue:[JVNotificationController defaultController] forKey:@"NotificationController"];
 	[[webView windowScriptObject] setValue:[MVChatPluginManager defaultManager] forKey:@"ChatPluginManager"];
+	[[webView windowScriptObject] setValue:[NSUserDefaults standardUserDefaults] forKey:@"NSUserDefaults"];
 }
 
 - (void) removeScriptGlobalsForWebView:(WebView *) webView {
@@ -251,6 +252,7 @@
 	[[webView windowScriptObject] removeWebScriptKey:@"SpeechController"];
 	[[webView windowScriptObject] removeWebScriptKey:@"NotificationController"];
 	[[webView windowScriptObject] removeWebScriptKey:@"ChatPluginManager"];
+	[[webView windowScriptObject] removeWebScriptKey:@"NSUserDefaults"];
 }
 
 #pragma mark -
Index: Plug-Ins/JavaScript Support/plugin.html
===================================================================
--- Plug-Ins/JavaScript Support/plugin.html	(revision 4185)
+++ Plug-Ins/JavaScript Support/plugin.html	(working copy)
@@ -170,6 +170,10 @@
 	throw "Can't create a NSURL without a URL string.";
 }
 
+function NSUserDefaults() {
+	return Plugin.allocInstance('NSUserDefaults');
+}
+
 </script>
 </head>
 <body></body>

I'll add my plugin so you can test if the changes are working.

Change History (1)

comment:1 Changed 11 years ago by timothy

  • Resolution set to fixed
  • Status changed from new to closed

Landed the patch in r4192.

Note: See TracTickets for help on using tickets.