Skip to content

Commit

Permalink
re-add observer-subscription retries during application launch
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Dec 23, 2021
1 parent f403e60 commit d8dcca2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bool application_observe(struct application *application)
if (result == kAXErrorSuccess || result == kAXErrorNotificationAlreadyRegistered) {
application->notification |= 1 << i;
} else {
if (result == kAXErrorCannotComplete) application->ax_retry = true;
debug("%s: notification %s failed with error %s for %s\n", __FUNCTION__, ax_application_notification_str[i], ax_error_str[-result], application->name);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct application
uint8_t notification;
bool is_observing;
bool is_hidden;
bool ax_retry;
};

bool application_is_frontmost(struct application *application);
Expand Down
13 changes: 12 additions & 1 deletion src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,20 @@ static EVENT_CALLBACK(EVENT_HANDLER_APPLICATION_LAUNCHED)

struct application *application = application_create(process);
if (!application_observe(application)) {
bool ax_retry = application->ax_retry;

application_unobserve(application);
application_destroy(application);
debug("%s: could not observe notifications for %s (%d)\n", __FUNCTION__, process->name, process->pid);
debug("%s: could not observe notifications for %s (%d) (%d)\n", __FUNCTION__, process->name, process->pid, ax_retry);

if (ax_retry) {
__block ProcessSerialNumber psn = process->psn;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
struct process *_process = process_manager_find_process(&g_process_manager, &psn);
if (_process) event_loop_post(&g_event_loop, APPLICATION_LAUNCHED, _process, 0, NULL);
});
}

return EVENT_FAILURE;
}

Expand Down

0 comments on commit d8dcca2

Please sign in to comment.