Skip to content

Commit fdb376d

Browse files
fix: early return when hotkey not found in map
Avoid sending events for unregistered hotkeys and passing invalid values to keybinder_unbind by returning early when lookup fails.
1 parent ddbb7bf commit fdb376d

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

packages/hotkey_manager_linux/linux/hotkey_manager_linux_plugin.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ G_DEFINE_TYPE(HotkeyManagerLinuxPlugin,
3232
g_object_get_type())
3333

3434
void handle_key_down(const char* keystring, void* user_data) {
35-
const char* identifier;
36-
3735
std::string val = keystring;
3836
auto result = std::find_if(hotkey_id_map.begin(), hotkey_id_map.end(),
3937
[val](const auto& e) { return e.second == val; });
4038

41-
if (result != hotkey_id_map.end())
42-
identifier = result->first.c_str();
39+
if (result == hotkey_id_map.end())
40+
return;
41+
42+
const char* identifier = result->first.c_str();
4343

4444
g_autoptr(FlValue) event_data = fl_value_new_map();
4545
fl_value_set_string_take(event_data, "identifier",
@@ -103,14 +103,16 @@ static FlMethodResponse* hkm_unregister(_HotkeyManagerLinuxPlugin* self,
103103
FlValue* args) {
104104
const char* identifier =
105105
fl_value_get_string(fl_value_lookup_string(args, "identifier"));
106-
const char* keystring;
107106

108107
std::string val = identifier;
109108
auto result = std::find_if(hotkey_id_map.begin(), hotkey_id_map.end(),
110109
[val](const auto& e) { return e.first == val; });
111110

112-
if (result != hotkey_id_map.end())
113-
keystring = result->second.c_str();
111+
if (result == hotkey_id_map.end())
112+
return FL_METHOD_RESPONSE(
113+
fl_method_success_response_new(fl_value_new_bool(false)));
114+
115+
const char* keystring = result->second.c_str();
114116

115117
keybinder_unbind(keystring, handle_key_down);
116118
hotkey_id_map.erase(identifier);

0 commit comments

Comments
 (0)