Skip to content

Commit 0fd0870

Browse files
committed
Polyfill for process.argv
Passing argv into bridge when initializing makes it accessible from global process.argv Added example of passing argv to UIExplorer.
1 parent 451c753 commit 0fd0870

File tree

12 files changed

+72
-20
lines changed

12 files changed

+72
-20
lines changed

Examples/UIExplorer/LinkingExample.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
*/
1414
'use strict';
1515

16-
var React = require('react-native');
16+
var React = require('react-native-desktop');
1717
var {
1818
Linking,
1919
StyleSheet,
2020
Text,
21-
TouchableNativeFeedback,
21+
TouchableHighlight,
2222
View,
2323
} = React;
2424
var UIExplorerBlock = require('./UIExplorerBlock');
@@ -41,12 +41,12 @@ var OpenURLButton = React.createClass({
4141

4242
render: function() {
4343
return (
44-
<TouchableNativeFeedback
44+
<TouchableHighlight
4545
onPress={this.handleClick}>
4646
<View style={styles.button}>
4747
<Text style={styles.text}>Open {this.props.url}</Text>
4848
</View>
49-
</TouchableNativeFeedback>
49+
</TouchableHighlight>
5050
);
5151
}
5252
});
@@ -55,12 +55,18 @@ var IntentAndroidExample = React.createClass({
5555

5656
statics: {
5757
title: 'Linking',
58-
description: 'Shows how to use Linking to open URLs.',
58+
description: 'Shows how to use Linking to parse argv and open URLs.',
5959
},
6060

6161
render: function() {
6262
return (
6363
<UIExplorerBlock title="Open external URLs">
64+
<View style={{margin: 20}}>
65+
<Text>Linking.getArgv(): {JSON.stringify(Linking.getArgv())}</Text>
66+
</View>
67+
<View style={{margin: 20}}>
68+
<Text>process.argv: {JSON.stringify(process.argv)}</Text>
69+
</View>
6470
<OpenURLButton url={'https://www.facebook.com'} />
6571
<OpenURLButton url={'http://www.facebook.com'} />
6672
<OpenURLButton url={'http://facebook.com'} />

Examples/UIExplorer/UIExplorer.xcodeproj/project.pbxproj

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
031465071CAA70BB0005E5B6 /* libRCTLinking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 031465061CAA6DF40005E5B6 /* libRCTLinking.a */; };
11+
031465081CAA71800005E5B6 /* libRCTLinking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 031465061CAA6DF40005E5B6 /* libRCTLinking.a */; };
1012
1300627F1B59179B0043FE5A /* RCTGzipTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1300627E1B59179B0043FE5A /* RCTGzipTests.m */; };
1113
13129DD41C85F87C007D611C /* RCTModuleInitNotificationRaceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 13129DD31C85F87C007D611C /* RCTModuleInitNotificationRaceTests.m */; };
1214
1323F1891C04AB9F0091BED0 /* bunny.png in Resources */ = {isa = PBXBuildFile; fileRef = 1323F1851C04AB9F0091BED0 /* bunny.png */; };
@@ -57,6 +59,13 @@
5759
/* End PBXBuildFile section */
5860

5961
/* Begin PBXContainerItemProxy section */
62+
031465051CAA6DF40005E5B6 /* PBXContainerItemProxy */ = {
63+
isa = PBXContainerItemProxy;
64+
containerPortal = 031465011CAA6DF30005E5B6 /* RCTLinking.xcodeproj */;
65+
proxyType = 2;
66+
remoteGlobalIDString = 134814201AA4EA6300B7C361;
67+
remoteInfo = RCTLinking;
68+
};
6069
035D95A71C9352CC00B095A8 /* PBXContainerItemProxy */ = {
6170
isa = PBXContainerItemProxy;
6271
containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */;
@@ -124,6 +133,7 @@
124133

125134
/* Begin PBXFileReference section */
126135
004D289E1AAF61C70097A701 /* UIExplorerUnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UIExplorerUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
136+
031465011CAA6DF30005E5B6 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = ../../Libraries/LinkingIOS/RCTLinking.xcodeproj; sourceTree = "<group>"; };
127137
1300627E1B59179B0043FE5A /* RCTGzipTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTGzipTests.m; sourceTree = "<group>"; };
128138
13129DD31C85F87C007D611C /* RCTModuleInitNotificationRaceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTModuleInitNotificationRaceTests.m; sourceTree = "<group>"; };
129139
1323F1851C04AB9F0091BED0 /* bunny.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bunny.png; sourceTree = "<group>"; };
@@ -195,6 +205,7 @@
195205
isa = PBXFrameworksBuildPhase;
196206
buildActionMask = 2147483647;
197207
files = (
208+
031465071CAA70BB0005E5B6 /* libRCTLinking.a in Frameworks */,
198209
14D6D7211B2222EF001FB087 /* libRCTImage.a in Frameworks */,
199210
14D6D7221B2222EF001FB087 /* libRCTNetwork.a in Frameworks */,
200211
14D6D7241B2222EF001FB087 /* libRCTSettings.a in Frameworks */,
@@ -210,6 +221,7 @@
210221
isa = PBXFrameworksBuildPhase;
211222
buildActionMask = 2147483647;
212223
files = (
224+
031465081CAA71800005E5B6 /* libRCTLinking.a in Frameworks */,
213225
14AADF051AC3DBB1002390C9 /* libReact.a in Frameworks */,
214226
13417FE91AA91432003F314A /* libRCTImage.a in Frameworks */,
215227
1341802C1AA9178B003F314A /* libRCTNetwork.a in Frameworks */,
@@ -230,11 +242,20 @@
230242
/* End PBXFrameworksBuildPhase section */
231243

232244
/* Begin PBXGroup section */
245+
031465021CAA6DF30005E5B6 /* Products */ = {
246+
isa = PBXGroup;
247+
children = (
248+
031465061CAA6DF40005E5B6 /* libRCTLinking.a */,
249+
);
250+
name = Products;
251+
sourceTree = "<group>";
252+
};
233253
1316A21D1AA397F400C0188E /* Libraries */ = {
234254
isa = PBXGroup;
235255
children = (
236256
14AADEFF1AC3DB95002390C9 /* React.xcodeproj */,
237257
13417FE31AA91428003F314A /* RCTImage.xcodeproj */,
258+
031465011CAA6DF30005E5B6 /* RCTLinking.xcodeproj */,
238259
134180261AA91779003F314A /* RCTNetwork.xcodeproj */,
239260
13CC9D481AEED2B90020D1C2 /* RCTSettings.xcodeproj */,
240261
58005BE41ABA80530062E044 /* RCTTest.xcodeproj */,
@@ -545,6 +566,10 @@
545566
ProductGroup = 13417FE41AA91428003F314A /* Products */;
546567
ProjectRef = 13417FE31AA91428003F314A /* RCTImage.xcodeproj */;
547568
},
569+
{
570+
ProductGroup = 031465021CAA6DF30005E5B6 /* Products */;
571+
ProjectRef = 031465011CAA6DF30005E5B6 /* RCTLinking.xcodeproj */;
572+
},
548573
{
549574
ProductGroup = 134180271AA91779003F314A /* Products */;
550575
ProjectRef = 134180261AA91779003F314A /* RCTNetwork.xcodeproj */;
@@ -580,6 +605,13 @@
580605
/* End PBXProject section */
581606

582607
/* Begin PBXReferenceProxy section */
608+
031465061CAA6DF40005E5B6 /* libRCTLinking.a */ = {
609+
isa = PBXReferenceProxy;
610+
fileType = archive.ar;
611+
path = libRCTLinking.a;
612+
remoteRef = 031465051CAA6DF40005E5B6 /* PBXContainerItemProxy */;
613+
sourceTree = BUILT_PRODUCTS_DIR;
614+
};
583615
13417FE81AA91428003F314A /* libRCTImage.a */ = {
584616
isa = PBXReferenceProxy;
585617
fileType = archive.ar;

Examples/UIExplorer/UIExplorer/AppDelegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
@interface AppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate>
2020

2121
@property (strong, nonatomic) NSWindow *window;
22+
@property (strong) NSArray<NSString *> *argv;
2223
@property(assign) Class<NSWindowRestoration> restorationClass;
2324
@property (nonatomic, readonly) RCTBridge *bridge;
2425

Examples/UIExplorer/UIExplorer/AppDelegate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ -(id)init
5454
return self;
5555
}
5656

57-
- (void)applicationDidFinishLaunching:(NSDictionary *)launchOptions
57+
- (void)applicationDidFinishLaunching:(NSNotification * __unused)aNotification
5858
{
5959

6060
_bridge = [[RCTBridge alloc] initWithDelegate:self
61-
launchOptions:launchOptions];
61+
launchOptions:@{@"argv": [self argv]}];
6262

6363
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:_bridge
6464
moduleName:@"UIExplorerApp"

Examples/UIExplorer/UIExplorer/main.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@
1515
#import <Cocoa/Cocoa.h>
1616
#import "AppDelegate.h"
1717

18-
int main(__unused int argc, __unused char * argv[]) {
18+
int main(__unused int argc, __unused char* argv[]) {
1919
@autoreleasepool {
2020
NSApplication * application = [NSApplication sharedApplication];
2121
NSMenu *mainMenu = [[NSMenu alloc] initWithTitle:@"Application"];
2222
[NSApp setMainMenu:mainMenu];
2323
AppDelegate * appDelegate = [[AppDelegate alloc] init];
2424
[application setDelegate:appDelegate];
25+
if (argc > 1) {
26+
NSMutableArray *argvArray = [[NSMutableArray alloc] init];
27+
for (int i = 1; i < argc; i++) {
28+
[argvArray addObject:[[NSString alloc] initWithUTF8String:argv[i]]];
29+
}
30+
[appDelegate setArgv:argvArray];
31+
}
32+
2533
[application run];
2634
return EXIT_SUCCESS;
2735
}

Examples/UIExplorer/UIExplorerList.osx.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ var APIS = [
5656
require('./AsyncStorageExample'),
5757
require('./BorderExample'),
5858
require('./LayoutExample'),
59+
require('./LinkingExample'),
5960
require('./TransformExample'),
6061
require('./XHRExample.osx'),
6162
require('./DragnDropExample.osx'),
62-
require('./MenuExample.osx')
63+
require('./MenuExample.osx'),
6364
];
6465

6566
type Props = {

Libraries/Linking/Linking.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const _notifHandlers = new Map();
2525

2626
const DEVICE_NOTIF_EVENT = 'openURL';
2727

28+
// polyfill
29+
process.argv = LinkingManagerIOS && LinkingManagerIOS.argv;
30+
2831
/**
2932
* `Linking` gives you a general interface to interact with both incoming
3033
* and outgoing app links.
@@ -198,6 +201,10 @@ class Linking {
198201
}
199202
}
200203

204+
static getArgv() {
205+
return LinkingManagerIOS.argv;
206+
}
207+
201208
static _validateURL(url: string) {
202209
invariant(
203210
typeof url === 'string',

Libraries/LinkingIOS/LinkingIOS.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ var Linking = require('Linking');
1515
var RCTLinkingManager = require('NativeModules').LinkingManager;
1616
var invariant = require('fbjs/lib/invariant');
1717

18-
var _initialURL = RCTLinkingManager && RCTLinkingManager.initialURL;
18+
var _argv = RCTLinkingManager && RCTLinkingManager.argv;
19+
20+
//GLOBAL.process.argv = GLOBAL.process.argv || '';
1921

2022
/**
2123
* NOTE: `LinkingIOS` is being deprecated. Use `Linking` instead.
@@ -150,9 +152,7 @@ class LinkingIOS {
150152
*/
151153
static popInitialURL(): ?string {
152154
console.warn('"LinkingIOS.popInitialURL" is deprecated. Use the promise based "Linking.getInitialURL" instead.');
153-
var initialURL = _initialURL;
154-
_initialURL = null;
155-
return initialURL;
155+
return _argv;
156156
}
157157
}
158158

Libraries/LinkingIOS/RCTLinkingManager.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ - (void)setBridge:(RCTBridge *)bridge
3333

3434
- (NSDictionary<NSString *, id> *)constantsToExport
3535
{
36-
NSURL *initialURL = _bridge.launchOptions[@"l"];
37-
return @{};
38-
//return @{@"initialURL": RCTNullIfNil(initialURL.absoluteString)};
36+
NSString *argv = _bridge.launchOptions[@"argv"];
37+
return @{@"argv": RCTNullIfNil(argv)};
3938
}
4039

4140
- (void)dealloc

Libraries/react-native/react-native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var ReactNative = {
6464
get IntentAndroid() { return require('IntentAndroid'); },
6565
get InteractionManager() { return require('InteractionManager'); },
6666
get LayoutAnimation() { return require('LayoutAnimation'); },
67-
get LinkingIOS() { return require('LinkingIOS'); },
67+
get Linking() { return require('Linking'); },
6868
get NetInfo() { return require('NetInfo'); },
6969
get MenuManager() { return require('MenuManager'); },
7070
get PanResponder() { return require('PanResponder'); },

React/Modules/RCTClipboard.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
*/
99

1010
#import "RCTClipboard.h"
11-
1211
#import "RCTUtils.h"
13-
1412
#import <AppKit/AppKit.h>
1513

1614
@implementation RCTClipboard

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-desktop",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"description": "A framework for building native desktop apps using React",
55
"license": "BSD-3-Clause",
66
"repository": {

0 commit comments

Comments
 (0)