mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Load index.html based on the resource path
Node uses the location of index as a starting point when looking for node_modules. Previously, we always loaded index.html out of the app bundle, which caused us to always load node_modules from the app bundle as well, which is not what we want in dev mode. Since we no longer depend on a compiled require.js, it's just as easy to load index.html from the repository path when in dev mode.
This commit is contained in:
@@ -26,26 +26,31 @@
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id)initWithBootstrapScript:(NSString *)bootstrapScript background:(BOOL)background alwaysUseBundleResourcePath:(BOOL)alwaysUseBundleResourcePath {
|
||||
- (id)initWithBootstrapScript:(NSString *)bootstrapScript background:(BOOL)background useBundleResourcePath:(BOOL)useBundleResourcePath {
|
||||
self = [super initWithWindowNibName:@"AtomWindow"];
|
||||
_bootstrapScript = [bootstrapScript retain];
|
||||
|
||||
AtomApplication *atomApplication = (AtomApplication *)[AtomApplication sharedApplication];
|
||||
|
||||
_resourcePath = [atomApplication.arguments objectForKey:@"resource-path"];
|
||||
if (!alwaysUseBundleResourcePath && !_resourcePath) {
|
||||
NSString *defaultRepositoryPath = [@"~/github/atom" stringByStandardizingPath];
|
||||
if ([defaultRepositoryPath characterAtIndex:0] == '/') {
|
||||
BOOL isDir = false;
|
||||
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:defaultRepositoryPath isDirectory:&isDir];
|
||||
if (isDir && exists)
|
||||
_resourcePath = defaultRepositoryPath;
|
||||
}
|
||||
}
|
||||
|
||||
if (alwaysUseBundleResourcePath || !_resourcePath) {
|
||||
if (useBundleResourcePath) {
|
||||
_resourcePath = [[NSBundle bundleForClass:self.class] resourcePath];
|
||||
}
|
||||
else {
|
||||
_resourcePath = [[atomApplication.arguments objectForKey:@"resource-path"] stringByStandardizingPath];
|
||||
if (!_resourcePath) {
|
||||
NSString *defaultRepositoryPath = [@"~/github/atom" stringByStandardizingPath];
|
||||
if ([defaultRepositoryPath characterAtIndex:0] == '/') {
|
||||
BOOL isDir = false;
|
||||
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:defaultRepositoryPath isDirectory:&isDir];
|
||||
if (isDir && exists) {
|
||||
_resourcePath = defaultRepositoryPath;
|
||||
}
|
||||
else {
|
||||
NSLog(@"Warning: No resource path specified and no directory exists at ~/github/atom");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([self isDevMode]) {
|
||||
[self displayDevIcon];
|
||||
@@ -99,19 +104,19 @@
|
||||
_pathToOpen = [path retain];
|
||||
AtomApplication *atomApplication = (AtomApplication *)[AtomApplication sharedApplication];
|
||||
BOOL useBundleResourcePath = [atomApplication.arguments objectForKey:@"dev"] == nil;
|
||||
return [self initWithBootstrapScript:@"window-bootstrap" background:NO alwaysUseBundleResourcePath:useBundleResourcePath];
|
||||
return [self initWithBootstrapScript:@"window-bootstrap" background:NO useBundleResourcePath:useBundleResourcePath];
|
||||
}
|
||||
|
||||
- (id)initDevWithPath:(NSString *)path {
|
||||
_pathToOpen = [path retain];
|
||||
return [self initWithBootstrapScript:@"window-bootstrap" background:NO alwaysUseBundleResourcePath:false];
|
||||
return [self initWithBootstrapScript:@"window-bootstrap" background:NO useBundleResourcePath:false];
|
||||
}
|
||||
|
||||
- (id)initInBackground {
|
||||
AtomApplication *atomApplication = (AtomApplication *)[AtomApplication sharedApplication];
|
||||
BOOL useBundleResourcePath = [atomApplication.arguments objectForKey:@"dev"] == nil;
|
||||
|
||||
[self initWithBootstrapScript:@"window-bootstrap" background:YES alwaysUseBundleResourcePath:useBundleResourcePath];
|
||||
[self initWithBootstrapScript:@"window-bootstrap" background:YES useBundleResourcePath:useBundleResourcePath];
|
||||
[self.window setFrame:NSMakeRect(0, 0, 0, 0) display:NO];
|
||||
[self.window setExcludedFromWindowsMenu:YES];
|
||||
[self.window setCollectionBehavior:NSWindowCollectionBehaviorStationary];
|
||||
@@ -121,13 +126,13 @@
|
||||
- (id)initSpecsThenExit:(BOOL)exitWhenDone {
|
||||
_runningSpecs = true;
|
||||
_exitWhenDone = exitWhenDone;
|
||||
return [self initWithBootstrapScript:@"spec-bootstrap" background:NO alwaysUseBundleResourcePath:NO];
|
||||
return [self initWithBootstrapScript:@"spec-bootstrap" background:NO useBundleResourcePath:NO];
|
||||
}
|
||||
|
||||
- (id)initBenchmarksThenExit:(BOOL)exitWhenDone {
|
||||
_runningSpecs = true;
|
||||
_exitWhenDone = exitWhenDone;
|
||||
return [self initWithBootstrapScript:@"benchmark-bootstrap" background:NO alwaysUseBundleResourcePath:NO];
|
||||
return [self initWithBootstrapScript:@"benchmark-bootstrap" background:NO useBundleResourcePath:NO];
|
||||
}
|
||||
|
||||
- (void)addBrowserToView:(NSView *)view url:(const char *)url cefHandler:(CefRefPtr<AtomCefClient>)cefClient {
|
||||
@@ -153,9 +158,11 @@
|
||||
// have the correct initial size based on the frame's last stored size.
|
||||
// HACK: I hate this and want to place this code directly in windowDidLoad
|
||||
- (void)attachWebView {
|
||||
NSURL *url = [[NSBundle bundleForClass:self.class] resourceURL];
|
||||
NSMutableString *urlString = [NSMutableString string];
|
||||
[urlString appendString:[[url URLByAppendingPathComponent:@"static/index.html"] absoluteString]];
|
||||
|
||||
NSURL *indexUrl = [[NSURL alloc] initFileURLWithPath:[_resourcePath stringByAppendingPathComponent:@"static/index.html"]];
|
||||
NSLog(@"%@", [indexUrl absoluteString]);
|
||||
[urlString appendString:[indexUrl absoluteString]];
|
||||
[urlString appendFormat:@"?bootstrapScript=%@", [self encodeUrlParam:_bootstrapScript]];
|
||||
[urlString appendFormat:@"&resourcePath=%@", [self encodeUrlParam:_resourcePath]];
|
||||
if ([self isDevMode])
|
||||
|
||||
Reference in New Issue
Block a user