Skip to content

Commit 2b7f807

Browse files
committed
[close #12] Ported OS X template for react-native-desktop-cli
1 parent c2f7725 commit 2b7f807

File tree

23 files changed

+48930
-71
lines changed

23 files changed

+48930
-71
lines changed

Examples/SimpleChatClient/SimpleChatClient/AppDelegate.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ - (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
105105
* then add the `main.jsbundle` file to your project and uncomment this line:
106106
*/
107107

108-
//sourceURL = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
108+
sourceURL = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
109109

110110
#if RUNNING_ON_CI
111111
sourceURL = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
@@ -142,10 +142,7 @@ - (id)firstResponder
142142

143143
- (void)setUpEditMenu
144144
{
145-
//
146-
// 416 if (![[[NSApp keyWindow] firstResponder] tryToPerform:@selector(cut:) with:nil])
147-
// 417 if (wbui->get_active_form() && wbui->get_active_form()->can_cut())
148-
NSMenuItem *developerItemContainer = [[NSMenuItem alloc] init]; //WithTitle:@"Developer" action:nil keyEquivalent:@"d"
145+
NSMenuItem *developerItemContainer = [[NSMenuItem alloc] init];
149146
NSMenu *developerMenu = [[NSMenu alloc] initWithTitle:@"Edit"];
150147
[developerItemContainer setSubmenu:developerMenu];
151148
[developerMenu setAutoenablesItems:YES];

Examples/SimpleChatClient/SimpleChatClient/main.jsbundle

Lines changed: 14 additions & 14 deletions
Large diffs are not rendered by default.

Examples/UIExplorer/UIExplorer.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
038010671BCCAF2500B1BE0C /* libRCTSettings.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 834C36D21AF8DA610019C93C /* libRCTSettings.a */; };
1414
03911C6C1BCFFCB7006809D1 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14AADF041AC3DB95002390C9 /* libReact.a */; };
1515
03911C6D1BCFFCBC006809D1 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13417FEF1AA914B8003F314A /* libRCTText.a */; };
16+
03AF39751C182D0B0002E93F /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = 03AF39741C182D0B0002E93F /* main.jsbundle */; };
1617
1300627F1B59179B0043FE5A /* RCTGzipTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1300627E1B59179B0043FE5A /* RCTGzipTests.m */; };
1718
138D6A181B53CD440074A87E /* RCTShadowViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 138D6A161B53CD440074A87E /* RCTShadowViewTests.m */; };
1819
1393D0381B68CD1300E1B601 /* RCTModuleMethodTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1393D0371B68CD1300E1B601 /* RCTModuleMethodTests.m */; };
@@ -111,6 +112,7 @@
111112
/* Begin PBXFileReference section */
112113
004D289E1AAF61C70097A701 /* UIExplorerUnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UIExplorerUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
113114
031631871BDF6FC1003A8A7A /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = ../../Libraries/Image/RCTImage.xcodeproj; sourceTree = "<group>"; };
115+
03AF39741C182D0B0002E93F /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.jsbundle; path = UIExplorer/main.jsbundle; sourceTree = "<group>"; };
114116
1300627E1B59179B0043FE5A /* RCTGzipTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTGzipTests.m; sourceTree = "<group>"; };
115117
13417FEA1AA914B8003F314A /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = ../../Libraries/Text/RCTText.xcodeproj; sourceTree = "<group>"; };
116118
134180261AA91779003F314A /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = ../../Libraries/Network/RCTNetwork.xcodeproj; sourceTree = "<group>"; };
@@ -250,6 +252,7 @@
250252
13B07FAE1A68108700A75B9A /* UIExplorer */ = {
251253
isa = PBXGroup;
252254
children = (
255+
03AF39741C182D0B0002E93F /* main.jsbundle */,
253256
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
254257
13B07FB01A68108700A75B9A /* AppDelegate.m */,
255258
13B07FB51A68108700A75B9A /* Images.xcassets */,
@@ -601,6 +604,7 @@
601604
buildActionMask = 2147483647;
602605
files = (
603606
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
607+
03AF39751C182D0B0002E93F /* main.jsbundle in Resources */,
604608
);
605609
runOnlyForDeploymentPostprocessing = 0;
606610
};

Examples/UIExplorer/UIExplorer/AppDelegate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ - (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
9595
* Load from pre-bundled file on disk. To re-generate the static bundle, `cd`
9696
* to your Xcode project folder and run
9797
*
98-
* $ curl 'http://localhost:8081/Examples/UIExplorer/UIExplorerApp.ios.bundle?platform=ios' -o main.jsbundle
98+
* $ curl 'http://localhost:8081/Examples/UIExplorer/UIExplorerApp.osx.bundle?platform=osx&dev=false' -o main.jsbundle
9999
*
100100
* then add the `main.jsbundle` file to your project and uncomment this line:
101101
*/
102102

103-
// sourceURL = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
103+
//sourceURL = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
104104

105105
#if RUNNING_ON_CI
106106
sourceURL = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

Examples/UIExplorer/UIExplorer/main.jsbundle

Lines changed: 47703 additions & 17 deletions
Large diffs are not rendered by default.

local-cli/generator-osx/index.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
'use strict';
10+
11+
var chalk = require('chalk');
12+
var path = require('path');
13+
var yeoman = require('yeoman-generator');
14+
15+
module.exports = yeoman.generators.NamedBase.extend({
16+
writing: function() {
17+
var templateVars = {name: this.name};
18+
// SomeApp/ios/SomeApp
19+
this.fs.copyTpl(
20+
this.templatePath(path.join('app', '**')),
21+
this.destinationPath(path.join('osx', this.name)),
22+
templateVars
23+
);
24+
25+
// SomeApp/ios/SomeAppTests
26+
this.fs.copyTpl(
27+
this.templatePath(path.join('tests', 'Tests.m')),
28+
this.destinationPath(path.join('osx', this.name + 'Tests', this.name + 'Tests.m')),
29+
templateVars
30+
);
31+
this.fs.copy(
32+
this.templatePath(path.join('tests', 'Info.plist')),
33+
this.destinationPath(path.join('osx', this.name + 'Tests', 'Info.plist'))
34+
);
35+
36+
// SomeApp/ios/SomeApp.xcodeproj
37+
this.fs.copyTpl(
38+
this.templatePath(path.join('xcodeproj', 'project.pbxproj')),
39+
this.destinationPath(path.join('osx', this.name + '.xcodeproj', 'project.pbxproj')),
40+
templateVars
41+
);
42+
this.fs.copyTpl(
43+
this.templatePath(path.join('xcodeproj', 'xcshareddata', 'xcschemes', '_xcscheme')),
44+
this.destinationPath(path.join('osx', this.name + '.xcodeproj', 'xcshareddata', 'xcschemes', this.name + '.xcscheme')),
45+
templateVars
46+
);
47+
},
48+
49+
end: function() {
50+
var projectPath = path.resolve(this.destinationRoot(), 'ios', this.name);
51+
this.log(chalk.white.bold('To run your app on OSX:'));
52+
this.log(chalk.white(' Open ' + projectPath + '.xcodeproj in Xcode'));
53+
this.log(chalk.white(' Hit Run button'));
54+
}
55+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import <Cocoa/Cocoa.h>
11+
12+
@interface AppDelegate : NSObject <NSApplicationDelegate>
13+
14+
@property (strong, nonatomic) NSWindow *window;
15+
16+
@end
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#import "AppDelegate.h"
2+
3+
#import "RCTBridge.h"
4+
#import "RCTJavaScriptLoader.h"
5+
#import "RCTRootView.h"
6+
#import <Cocoa/Cocoa.h>
7+
8+
@interface AppDelegate() <RCTBridgeDelegate>
9+
10+
@end
11+
12+
@implementation AppDelegate
13+
14+
-(id)init
15+
{
16+
if(self = [super init]) {
17+
NSRect contentSize = NSMakeRect(200, 500, 1000, 500); // TODO: should not be hardcoded
18+
19+
self.window = [[NSWindow alloc] initWithContentRect:contentSize
20+
styleMask:NSTitledWindowMask | NSResizableWindowMask | NSFullSizeContentViewWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask
21+
backing:NSBackingStoreBuffered
22+
defer:NO];
23+
NSWindowController *windowController = [[NSWindowController alloc] initWithWindow:self.window];
24+
25+
[[self window] setTitleVisibility:NSWindowTitleHidden];
26+
[[self window] setTitlebarAppearsTransparent:YES];
27+
[[self window] setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
28+
29+
[windowController setShouldCascadeWindows:NO];
30+
[windowController setWindowFrameAutosaveName:@"<%= name %>"];
31+
32+
[windowController showWindow:self.window];
33+
34+
// TODO: remove broilerplate
35+
[self setUpApplicationMenu];
36+
}
37+
return self;
38+
}
39+
40+
- (void)applicationDidFinishLaunching:(__unused NSNotification *)aNotification
41+
{
42+
43+
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self
44+
launchOptions:nil];
45+
46+
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
47+
moduleName:@"<%= name %>"
48+
initialProperties:nil];
49+
50+
51+
52+
[self.window setContentView:rootView];
53+
}
54+
55+
56+
- (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
57+
{
58+
NSURL *sourceURL;
59+
60+
/**
61+
* Loading JavaScript code - uncomment the one you want.
62+
*
63+
* OPTION 1
64+
* Load from development server. Start the server from the repository root:
65+
*
66+
* $ npm start
67+
*
68+
* To run on device, change `localhost` to the IP address of your computer
69+
* (you can get this by typing `ifconfig` into the terminal and selecting the
70+
* `inet` value under `en0:`) and make sure your computer and iOS device are
71+
* on the same Wi-Fi network.
72+
*/
73+
74+
sourceURL = [NSURL URLWithString:@"http://localhost:8081/index.osx.bundle?platform=osx&dev=true"];
75+
76+
/**
77+
* OPTION 2
78+
* Load from pre-bundled file on disk. To re-generate the static bundle, `cd`
79+
* to your Xcode project folder and run
80+
*
81+
* $ curl 'http://localhost:8081/index.osx.bundle?platform=osx&dev=false&minify=true' -o RNGLDesktop/main.jsbundle
82+
*
83+
* then add the `main.jsbundle` file to your project and uncomment this line:
84+
*/
85+
86+
//sourceURL = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
87+
88+
#if RUNNING_ON_CI
89+
sourceURL = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
90+
#endif
91+
92+
return sourceURL;
93+
}
94+
95+
- (void)loadSourceForBridge:(RCTBridge *)bridge
96+
withBlock:(RCTSourceLoadBlock)loadCallback
97+
{
98+
[RCTJavaScriptLoader loadBundleAtURL:[self sourceURLForBridge:bridge]
99+
onComplete:loadCallback];
100+
}
101+
102+
103+
- (void)setUpApplicationMenu
104+
{
105+
NSMenu *mainMenu = [[NSMenu alloc] initWithTitle:@"" ];
106+
NSMenuItem *containerItem = [[NSMenuItem alloc] init];
107+
NSMenu *rootMenu = [[NSMenu alloc] initWithTitle:@"" ];
108+
[containerItem setSubmenu:rootMenu];
109+
[mainMenu addItem:containerItem];
110+
[rootMenu addItemWithTitle:@"Quit <%= name %>" action:@selector(terminate) keyEquivalent:@"Q"];
111+
112+
}
113+
114+
- (id)firstResponder
115+
{
116+
return [self.window firstResponder];
117+
}
118+
119+
@end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "29x29",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "29x29",
11+
"scale" : "3x"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"size" : "40x40",
16+
"scale" : "2x"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"size" : "40x40",
21+
"scale" : "3x"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"size" : "60x60",
26+
"scale" : "2x"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"size" : "60x60",
31+
"scale" : "3x"
32+
}
33+
],
34+
"info" : {
35+
"version" : 1,
36+
"author" : "xcode"
37+
}
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIconFile</key>
10+
<string></string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>$(PRODUCT_NAME)</string>
17+
<key>CFBundlePackageType</key>
18+
<string>APPL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleSignature</key>
22+
<string>????</string>
23+
<key>CFBundleVersion</key>
24+
<string>1</string>
25+
<key>LSMinimumSystemVersion</key>
26+
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
27+
<key>NSHumanReadableCopyright</key>
28+
<string>Copyright © 2015</string>
29+
<key>NSMainNibFile</key>
30+
<string>MainMenu</string>
31+
<key>NSPrincipalClass</key>
32+
<string>NSApplication</string>
33+
<key>NSAppTransportSecurity</key>
34+
<dict>
35+
<key>NSAllowsArbitraryLoads</key>
36+
<true/>
37+
</dict>
38+
</dict>
39+
</plist>

0 commit comments

Comments
 (0)