Skip to content

Commit

Permalink
#108 restart dock if invalid bundle is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jul 11, 2019
1 parent 8e17fd2 commit ab138fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/osax/sa.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include "common.h"

#define PAYLOAD_STATUS_SUCCESS 0
#define PAYLOAD_STATUS_OUTDATED 1
#define PAYLOAD_STATUS_NO_ATTRIB 2

int scripting_addition_load(void);
bool scripting_addition_is_installed(void);
int scripting_addition_uninstall(void);
Expand Down
15 changes: 13 additions & 2 deletions src/osax/sa.m
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,29 @@ static void scripting_addition_prepare_binaries(void)
return result;
}

static void scripting_addition_perform_validation(void)
static int scripting_addition_perform_validation(void)
{
uint32_t attrib;
char *version = scripting_addition_request_handshake(&attrib);
if (version) debug("yabai: osax version = %s, osax attrib = 0x%X\n", version, attrib);

if (!version || !string_equals(version, OSAX_VERSION)) {
notify("payload is outdated, please reinstall!", "scripting-addition");
return PAYLOAD_STATUS_OUTDATED;
} else if ((attrib & OSAX_ATTRIB_ALL) != OSAX_ATTRIB_ALL) {
notify("payload failed to locate required resources inside Dock.app!", "scripting-addition");
return PAYLOAD_STATUS_NO_ATTRIB;
} else {
debug("yabai: scripting-addition payload successfully located all requsted resources inside Dock.app..\n");
return PAYLOAD_STATUS_SUCCESS;
}
}

static void scripting_addition_maybe_restart_dock(int status)
{
if (status == PAYLOAD_STATUS_NO_ATTRIB) {
NSArray *dock = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"];
[dock makeObjectsPerformSelector:@selector(terminate)];
}
}

Expand Down Expand Up @@ -325,7 +336,7 @@ int scripting_addition_load(void)
scripting_addition_perform_validation();
} else if (loader->result == OSAX_PAYLOAD_ALREADY_LOADED) {
notify("payload was already injected into Dock.app!", "scripting-addition");
scripting_addition_perform_validation();
scripting_addition_maybe_restart_dock(scripting_addition_perform_validation());
} else if (loader->result == OSAX_PAYLOAD_NOT_LOADED) {
notify("failed to inject payload into Dock.app!", "scripting-addition");
} else if (loader->result == OSAX_PAYLOAD_NOT_FOUND) {
Expand Down

0 comments on commit ab138fb

Please sign in to comment.