Skip to content

Commit

Permalink
#543 resolve issue with lifetime of NSRunningApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed May 28, 2020
1 parent 8c9bbbe commit 2e280b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/process_manager.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "process_manager.h"

extern struct event_loop g_event_loop;
extern void *g_workspace_context;

static TABLE_HASH_FUNC(hash_psn)
{
Expand Down Expand Up @@ -40,7 +41,7 @@ struct process *process_create(ProcessSerialNumber psn)

void process_destroy(struct process *process)
{
workspace_application_destroy_running_ns_application(process);
workspace_application_destroy_running_ns_application(g_workspace_context, process);
free(process->name);
free(process);
}
Expand Down
2 changes: 1 addition & 1 deletion src/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void workspace_event_handler_end(void *context);

struct process;
void *workspace_application_create_running_ns_application(struct process *process);
void workspace_application_destroy_running_ns_application(struct process *process);
void workspace_application_destroy_running_ns_application(void *context, struct process *process);
bool workspace_application_is_observable(struct process *process);
bool workspace_application_is_finished_launching(struct process *process);
void workspace_application_observe_finished_launching(void *context, struct process *process);
Expand Down
15 changes: 13 additions & 2 deletions src/workspace.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,21 @@ void workspace_event_handler_end(void *context)
return [NSRunningApplication runningApplicationWithProcessIdentifier:process->pid];
}

void workspace_application_destroy_running_ns_application(struct process *process)
void workspace_application_destroy_running_ns_application(void *context, struct process *process)
{
NSRunningApplication *application = process->ns_application;
if (application) [application release];

if (application) {
@try {
[application removeObserver:context forKeyPath:@"activationPolicy"];
} @catch (NSException * __unused exception) {}

@try {
[application removeObserver:context forKeyPath:@"finishedLaunching"];
} @catch (NSException * __unused exception) {}

[application release];
}
}

void workspace_application_observe_finished_launching(void *context, struct process *process)
Expand Down

0 comments on commit 2e280b6

Please sign in to comment.