Skip to content
Snippets Groups Projects
Commit 11c08e90 authored by George Nachman's avatar George Nachman
Browse files

Fix bug where startup activities aren't always performed on Lion.

parent a7557946
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -48,9 +48,10 @@ static NSString* AUTO_LAUNCH_SCRIPT = @"~/Library/Application Support/iTerm/Auto
 
NSMutableString* gDebugLogStr = nil;
NSMutableString* gDebugLogStr2 = nil;
static BOOL usingAutoLaunchScript = NO;
static BOOL ranAutoLaunchScript = NO;
BOOL gDebugLogging = NO;
int gDebugLogFile = -1;
static BOOL hasBecomeActive = NO;
 
@implementation iTermAboutWindow
 
Loading
Loading
@@ -117,6 +118,40 @@ int gDebugLogFile = -1;
}
}
 
- (void)_performStartupActivities
{
// Check if we have an autolauch script to execute. Do it only once, i.e. at application launch.
if (ranAutoLaunchScript == NO &&
[[NSFileManager defaultManager] fileExistsAtPath:[AUTO_LAUNCH_SCRIPT stringByExpandingTildeInPath]]) {
ranAutoLaunchScript = YES;
NSAppleScript *autoLaunchScript;
NSDictionary *errorInfo = [NSDictionary dictionary];
NSURL *aURL = [NSURL fileURLWithPath:[AUTO_LAUNCH_SCRIPT stringByExpandingTildeInPath]];
// Make sure our script suite registry is loaded
[NSScriptSuiteRegistry sharedScriptSuiteRegistry];
autoLaunchScript = [[NSAppleScript alloc] initWithContentsOfURL:aURL
error:&errorInfo];
[autoLaunchScript executeAndReturnError:&errorInfo];
[autoLaunchScript release];
} else {
if ([[PreferencePanel sharedInstance] openBookmark]) {
[self showBookmarkWindow:nil];
if ([[PreferencePanel sharedInstance] openArrangementAtStartup]) {
// Open both bookmark window and arrangement!
[[iTermController sharedInstance] loadWindowArrangement];
}
} else if ([[PreferencePanel sharedInstance] openArrangementAtStartup]) {
[[iTermController sharedInstance] loadWindowArrangement];
} else {
[self newWindow:nil];
}
}
ranAutoLaunchScript = YES;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Prevent the input manager from swallowing control-q. See explanation here:
Loading
Loading
@@ -139,9 +174,10 @@ int gDebugLogFile = -1;
// register for services
[NSApp registerServicesMenuSendTypes:[NSArray arrayWithObjects:NSStringPboardType, nil]
returnTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, NSStringPboardType, nil]];
[self _performStartupActivities];
}
 
- (BOOL)applicationShouldTerminate: (NSNotification *) theNotification
- (BOOL)applicationShouldTerminate:(NSNotification *)theNotification
{
NSArray *terminals;
 
Loading
Loading
@@ -192,63 +228,34 @@ int gDebugLogFile = -1;
 
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
//NSLog(@"%s: %@", __PRETTY_FUNCTION__, filename);
filename = [filename stringWithEscapedShellCharacters];
if (filename) {
// Verify whether filename is a script or a folder
BOOL isDir;
[[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&isDir];
if (!isDir) {
NSString *aString = [NSString stringWithFormat:@"%@; exit;\n", filename];
[[iTermController sharedInstance] launchBookmark:nil inTerminal:nil];
// Sleeping a while waiting for the login.
sleep(1);
[[[[iTermController sharedInstance] currentTerminal] currentSession] insertText:aString];
}
else {
NSString *aString = [NSString stringWithFormat:@"cd %@\n", filename];
[[iTermController sharedInstance] launchBookmark:nil inTerminal:nil];
// Sleeping a while waiting for the login.
sleep(1);
[[[[iTermController sharedInstance] currentTerminal] currentSession] insertText:aString];
}
filename = [filename stringWithEscapedShellCharacters];
if (filename) {
// Verify whether filename is a script or a folder
BOOL isDir;
[[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&isDir];
if (!isDir) {
NSString *aString = [NSString stringWithFormat:@"%@; exit;\n", filename];
[[iTermController sharedInstance] launchBookmark:nil inTerminal:nil];
// Sleeping a while waiting for the login.
sleep(1);
[[[[iTermController sharedInstance] currentTerminal] currentSession] insertText:aString];
}
else {
NSString *aString = [NSString stringWithFormat:@"cd %@\n", filename];
[[iTermController sharedInstance] launchBookmark:nil inTerminal:nil];
// Sleeping a while waiting for the login.
sleep(1);
[[[[iTermController sharedInstance] currentTerminal] currentSession] insertText:aString];
}
return (YES);
}
return (YES);
}
 
- (BOOL)applicationOpenUntitledFile:(NSApplication *)app
- (BOOL)applicationOpenUntitledFile:(NSApplication *)theApplication
{
// Check if we have an autolauch script to execute. Do it only once, i.e. at application launch.
if (usingAutoLaunchScript == NO &&
[[NSFileManager defaultManager] fileExistsAtPath:[AUTO_LAUNCH_SCRIPT stringByExpandingTildeInPath]]) {
usingAutoLaunchScript = YES;
NSAppleScript *autoLaunchScript;
NSDictionary *errorInfo = [NSDictionary dictionary];
NSURL *aURL = [NSURL fileURLWithPath: [AUTO_LAUNCH_SCRIPT stringByExpandingTildeInPath]];
// Make sure our script suite registry is loaded
[NSScriptSuiteRegistry sharedScriptSuiteRegistry];
autoLaunchScript = [[NSAppleScript alloc] initWithContentsOfURL: aURL error: &errorInfo];
[autoLaunchScript executeAndReturnError: &errorInfo];
[autoLaunchScript release];
} else {
if ([[PreferencePanel sharedInstance] openBookmark]) {
[self showBookmarkWindow:nil];
if ([[PreferencePanel sharedInstance] openArrangementAtStartup]) {
// Open both bookmark window and arrangement!
[[iTermController sharedInstance] loadWindowArrangement];
}
} else if ([[PreferencePanel sharedInstance] openArrangementAtStartup]) {
[[iTermController sharedInstance] loadWindowArrangement];
} else {
[self newWindow:nil];
}
if (hasBecomeActive) {
[self _performStartupActivities];
}
usingAutoLaunchScript = YES;
return YES;
}
 
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app
Loading
Loading
@@ -545,6 +552,7 @@ static void FlushDebugLog() {
 
- (void)applicationDidBecomeActive:(NSNotification *)aNotification
{
hasBecomeActive = YES;
if (secureInputDesired_) {
if (EnableSecureEventInput() != noErr) {
NSLog(@"Failed to enable secure input.");
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment