Skip to content

Commit

Permalink
Finally fixed the bugs and tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
cb1kenobi committed Jul 16, 2024
1 parent 7ea61f0 commit 8a9b876
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 80 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* BREAKING CHANGE: Require Node.js 18.17 or newer
* feat: Support for arm/arm64
* fix: Fixed order of child key events when parent key is deleted

# v2.0.4 (July 2, 2024)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@biomejs/biome": "1.8.3",
"@rollup/plugin-typescript": "11.1.6",
"@types/node": "20.14.10",
"@vitest/coverage-v8": "2.0.2",
"@vitest/coverage-v8": "2.0.3",
"esbuild": "0.23.0",
"lefthook": "1.7.2",
"prebuildify": "6.0.1",
Expand All @@ -59,7 +59,7 @@
"rollup-plugin-esbuild": "6.1.1",
"tslib": "2.6.3",
"typescript": "5.5.3",
"vitest": "2.0.2"
"vitest": "2.0.3"
},
"homepage": "https://github.com/tidev/winreglib",
"bugs": "https://github.com/tidev/winreglib/issues",
Expand Down
94 changes: 47 additions & 47 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/watchman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ void Watchman::dispatch() {
* Prints the watcher tree for debugging.
*/
void Watchman::printTree() {
std::wstringstream wss(L"");
std::wstring line;
root->print(wss);
while (std::getline(wss, line, L'\n')) {
WLOG_DEBUG("Watchman::printTree", line)
}
// std::wstringstream wss(L"");
// std::wstring line;
// root->print(wss);
// while (std::getline(wss, line, L'\n')) {
// WLOG_DEBUG("Watchman::printTree", line)
// }
}

/**
Expand Down
24 changes: 18 additions & 6 deletions src/watchnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ std::u16string WatchNode::getKey() {

/**
* Attempts to open this node's registry key and watch it.
*
* Returns true if something changed.
*/
bool WatchNode::load(CallbackQueue* pending) {
bool result = false;
Expand All @@ -99,8 +101,6 @@ bool WatchNode::load(CallbackQueue* pending) {
LOG_DEBUG_1("WatchNode::load", L"\"%ls\" hkey is still valid", name.c_str())
} else {
// no longer valid!
LOG_DEBUG_1("WatchNode::load", L"\"%ls\" hkey is no longer valid", name.c_str())
unload(pending);
result = true;
}
} else {
Expand All @@ -116,9 +116,7 @@ bool WatchNode::load(CallbackQueue* pending) {
}

for (auto const& it : subkeys) {
if (it.second->load(pending)) {
result = true;
}
it.second->load(pending);
}

result = true;
Expand Down Expand Up @@ -146,6 +144,17 @@ bool WatchNode::onChange() {

if (hkey) {
if (watch(&pending)) {
// hkey should be valid, check if subkeys are ok
LOG_DEBUG_1("WatchNode::onChange", L"Checking if subkeys under \"%ls\" are still valid", name.c_str())
for (auto const& it : subkeys) {
HKEY tmp;
LSTATUS status = ::RegOpenKeyW(hkey, it.second->name.c_str(), &tmp);
if (status != ERROR_SUCCESS) {
LOG_DEBUG_1("WatchNode::onChange", L"\"%ls\" hkey is no longer valid", it.second->name.c_str())
it.second->unload(&pending);
}
}

PUSH_CALLBACK(pending, "change", getKey(), listeners)
}

Expand Down Expand Up @@ -240,6 +249,7 @@ void WatchNode::removeListener(napi_value listener) {
* Closes this node's registry key handle and its subkey's key handles.
*/
void WatchNode::unload(CallbackQueue* pending) {
LOG_DEBUG_1("WatchNode::unload", L"Checking subkeys under \"%ls\" hkey", name.c_str())
for (auto const& it : subkeys) {
it.second->unload(pending);
}
Expand All @@ -257,7 +267,9 @@ void WatchNode::unload(CallbackQueue* pending) {
}

/**
* Wires up the change notification event.
* Wires up the Windows Registry change notification event asynchronously.
*
* Returns true if the key is valid and the watcher was successfully registered.
*/
bool WatchNode::watch(CallbackQueue* pending) {
if (hkey) {
Expand Down
Loading

0 comments on commit 8a9b876

Please sign in to comment.