From bf82350f51e771cf217e50f940a69c425e3223b4 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Wed, 12 Jan 2022 17:54:40 +0100 Subject: [PATCH] harden app name passing --- src/bar_manager.c | 2 +- src/workspace.m | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bar_manager.c b/src/bar_manager.c index ff684c1..08352bc 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -396,7 +396,7 @@ void bar_manager_handle_mouse_exited(struct bar_manager* bar_manager) { void bar_manager_handle_front_app_switch(struct bar_manager* bar_manager, char* info) { struct env_vars env_vars; env_vars_init(&env_vars); - env_vars_set(&env_vars, string_copy("INFO"), info); + if (info) env_vars_set(&env_vars, string_copy("INFO"), info); bar_manager_custom_events_trigger(bar_manager, COMMAND_SUBSCRIBE_FRONT_APP_SWITCHED, &env_vars); env_vars_destroy(&env_vars); } diff --git a/src/workspace.m b/src/workspace.m index c024ffb..c1473ba 100644 --- a/src/workspace.m +++ b/src/workspace.m @@ -86,8 +86,12 @@ void workspace_create_custom_observer (void **context, char* notification) { } - (void)appSwitched:(NSNotification *)notification { - NSRunningApplication *app = [notification.userInfo objectForKey:NSWorkspaceApplicationKey]; - struct event *event = event_create(&g_event_loop, APPLICATION_FRONT_SWITCHED, string_copy((char*)[[app localizedName] UTF8String])); + char* name = NULL; + if (notification && notification.userInfo) { + NSRunningApplication* app = [notification.userInfo objectForKey:NSWorkspaceApplicationKey]; + if (app) name = string_copy((char*)[[app localizedName] UTF8String]); + } + struct event *event = event_create(&g_event_loop, APPLICATION_FRONT_SWITCHED, name); event_loop_post(&g_event_loop, event); }