Skip to content

Commit 7d03dc1

Browse files
committed
Mac: change way of hiding command-line arguments from openFile
NSApplication treats command-line arguments an application as strings that should be forwarded to the application object's `openFile` method, but that's not what we want. It turns out that there has always (or at least since OS X 10.5) been an undocumented configuration option "NSTreatUnknownArgumentsAsOpen" to turn that off.
1 parent d8ee912 commit 7d03dc1

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

gui-lib/mred/private/wx/cocoa/queue.rkt

+16-12
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,27 @@
3838
queue-event
3939
yield)
4040

41-
(import-class NSApplication NSAutoreleasePool NSColor NSProcessInfo NSArray NSMenu NSThread)
41+
(import-class NSApplication NSAutoreleasePool NSColor NSProcessInfo NSArray NSMenu NSThread
42+
NSUserDefaults NSDictionary)
4243

4344
(unless (tell #:type _BOOL NSThread isMainThread)
4445
(error 'racket/gui
4546
"cannot instantiate in a non-main place on Mac OS"))
4647

47-
;; Extreme hackery to hide original arguments from
48-
;; NSApplication, because NSApplication wants to turn
49-
;; the arguments into `application:openFile:' calls.
50-
;; To hide the arguments, we replace the implementation
51-
;; of `arguments' in the NSProcessInfo object.
52-
(define (hack-argument-replacement self method)
53-
(tell NSArray
54-
arrayWithObjects: #:type (_vector i _NSString) (vector (path->string (find-system-path 'exec-file)))
55-
count: #:type _NSUInteger 1))
56-
(let ([m (class_getInstanceMethod NSProcessInfo (selector arguments))])
57-
(void (method_setImplementation m hack-argument-replacement)))
48+
;; Hide original arguments from NSApplication, because NSApplication
49+
;; otherwise turns the arguments into `application:openFile:' calls.
50+
(void
51+
(tell (tell NSUserDefaults standardUserDefaults)
52+
registerDefaults:
53+
(tell NSDictionary
54+
dictionaryWithObjects:
55+
(tell NSArray
56+
arrayWithObjects: #:type (_vector i _NSString) (vector "NO")
57+
count: #:type _NSUInteger 1)
58+
forKeys:
59+
(tell NSArray
60+
arrayWithObjects: #:type (_vector i _NSString) (vector "NSTreatUnknownArgumentsAsOpen")
61+
count: #:type _NSUInteger 1))))
5862

5963
(define app (tell NSApplication sharedApplication))
6064

0 commit comments

Comments
 (0)