Skip to content

Commit

Permalink
Changed how the show/hide editor window logic works so that relaunchi…
Browse files Browse the repository at this point in the history
…ng is not necessary. Bumped version to 0.8.5 (#110)
  • Loading branch information
amuraco authored and 2ndalpha committed Mar 17, 2018
1 parent 7e45260 commit b3ee7f2
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions Source/ApplicationController.m
Expand Up @@ -110,9 +110,7 @@ - (IBAction)openEditorWindow:(id)sender

- (IBAction)closeEditorWindow:(id)sender
{
[Preferences setShowEditorWindow:NO];
shouldQuit = NO;
[self quit:nil];
[self hideApplicationFromDock];
}

- (IBAction)addFromURL:(id)sender
Expand Down Expand Up @@ -203,8 +201,9 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
shouldQuit = NO;
return YES;
shouldQuit = YES;
[self hideApplicationFromDock];
return NO;
}

- (void)applicationWillTerminate:(NSNotification *)aNotification
Expand Down Expand Up @@ -292,25 +291,38 @@ - (void)notifyHostsChange:(Hosts*)hosts
[NotificationHelper notify:@"Hosts File Activated" message:[hosts name]];
}

BOOL tranformAppToState(ProcessApplicationTransformState newState)
{
ProcessSerialNumber psn = { 0, kCurrentProcess };
OSStatus transformStatus = TransformProcessType(&psn, newState);
if((transformStatus != 0))
{
NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:transformStatus userInfo:nil];
NSLog(@"TranformAppToState: Unable to transform App state. Error - %@",error);
}

return (transformStatus == 0);
}

- (void)showApplicationInDock
{
ProcessSerialNumber psn = {0, kCurrentProcess};
OSStatus returnCode = TransformProcessType(&psn, kProcessTransformToForegroundApplication);
if (returnCode == 0) {
BOOL bSuccess = tranformAppToState(kProcessTransformToForegroundApplication);
if(bSuccess)
{
[NSApp activateIgnoringOtherApps:YES];
ProcessSerialNumber psnx = {0, kNoProcess};
GetNextProcess(&psnx);
SetFrontProcess(&psnx);
[self performSelector:@selector(setFront) withObject:nil afterDelay:0.5];
}

}

- (void)hideApplicationFromDock
{
NSArray *arguments = [NSArray arrayWithObjects:@"-c",
[NSString stringWithFormat:@"sleep 1 ; /usr/bin/open '%@' --args \\#reopen\\#", [[NSBundle mainBundle] bundlePath]],
nil];
[NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:arguments];
[NSApp terminate:self];
tranformAppToState(kProcessTransformToBackgroundApplication);
[Preferences setShowEditorWindow:NO];
editorWindowOpened = NO;
}

- (void)setFront
Expand Down

0 comments on commit b3ee7f2

Please sign in to comment.