Skip to content

Commit

Permalink
Merge pull request #43 from Izurii/fix/hotkey-addon
Browse files Browse the repository at this point in the history
Fix/hotkey addon
  • Loading branch information
Izurii authored Feb 9, 2022
2 parents 84f9443 + fc64a26 commit d6914a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Changelog
### [2.0.1](https://github.com/Izurii/Lenovo-Y720-KB-Led-Controller/compare/v1.8.90-apocalypse...v2.0.1) (2022-02-09)


### Bug Fixes

* Corrigido problema com o valor da hotkey passada como param no callback js ([b37617d](https://github.com/Izurii/Lenovo-Y720-KB-Led-Controller/commit/b37617dbb96fb6978e8839df290adb5d548fdcd3))
28 changes: 16 additions & 12 deletions libs/hotkey/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,16 @@ String getInputDevice(const CallbackInfo &info)

void _threadCallback(int err, libevdev *dev, input_event ev)
{
int *value;
int hotkeyPressed;
int hotkeyPressedValue;
bool hotkeyPressed = false;

auto callback = [](Napi::Env env, Function jsCallback, int *value)
auto callback = [&](Napi::Env env, Function jsCallback, int *value)
{
if (jsCallback.IsFunction())
{
jsCallback.Call({Number::New(env, *value)});
}
hotkeyPressedValue = 0;
};

do
Expand All @@ -105,18 +106,21 @@ void _threadCallback(int err, libevdev *dev, input_event ev)
{
if (ev.type == EV_MSC && (ev.value == HOTKEY_FN_SPACE || ev.value == HOTKEY_7))
{
hotkeyPressed = ev.value;
value = &hotkeyPressed;
if (!hotkeyPressed)
{
hotkeyPressed = true;
hotkeyPressedValue = ev.value;
}
}
else if (ev.type == EV_KEY && ev.value == 0)
else if (ev.type == EV_KEY && ev.value == 0 && hotkeyPressed)
{
if (hotkeyPressed && hotkeyPressed > 0)
napi_status status = tsfn.BlockingCall(&hotkeyPressedValue, callback);

hotkeyPressed = false;

if (status != napi_ok)
{
napi_status status = tsfn.BlockingCall(value, callback);
if (status != napi_ok)
{
break;
}
break;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"node": "=16.9.1"
},
"engineStrict": true,
"version": "v2.0.0-corinthians",
"version": "2.0.1",
"description": "Software to control the keyboard backlight rgb leds of Lenovo Legion Y720 notebook.",
"main": "./dist/js/main.js",
"author": "Izurii Hootoh <izuriihootoh@gmail.com> (https://github.com/Izurii)",
Expand Down Expand Up @@ -65,6 +65,7 @@
"electron": "^16.0.5",
"electron-builder": "^22.14.5",
"electron-reloader": "^1.2.1",
"standard-version": "^9.3.2",
"tsc": "^2.0.3",
"typescript": "^4.5.4"
},
Expand Down

0 comments on commit d6914a5

Please sign in to comment.