From 426760d1f92e84488723509649b412a4e91ffb7f Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 24 Apr 2025 16:26:35 +1000 Subject: [PATCH 1/2] chore: enable logging back to console.log --- package.json | 2 +- src/addon.cpp | 62 +++++++++++++++++++++------------------------------ 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index bf29ba3..1bfcbf1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "main": "index.js", "name": "libsession_util_nodejs", "description": "Wrappers for the Session Util Library", - "version": "0.5.2", + "version": "0.5.3", "license": "GPL-3.0", "author": { "name": "Oxen Project", diff --git a/src/addon.cpp b/src/addon.cpp index 14beee5..f69ccb7 100644 --- a/src/addon.cpp +++ b/src/addon.cpp @@ -11,47 +11,35 @@ #include "user_config.hpp" #include "user_groups_config.hpp" -/** - * Note: After days of trying to get the libsession-util logger to play nice with console.log, - * I've decided to just not log anything from libsession for now. - * Note for my future self: - * - we need a thread-safe function to be called in the add_logger callback here because if - * the `env` is not valid it will crash the whole app without an error at all, - * - macos crashes a lot more easily than linux, so better to debug this issue on macOS, - * - using the thread-safe function below is working for linux, and kind of working for macOS, but - * it also prevents the normal logging from being written to the inspector (macOS only) - * - * For all those reasons, and because we want a point release soon, there is no logging from - * libsession-util for now. - */ -// Napi::ThreadSafeFunction tsfn; -// tsfn = Napi::ThreadSafeFunction::New( -// env, -// Napi::Function::New(env, [](const Napi::CallbackInfo& info) {}), -// "LoggerCallback", -// 0, -// 1); - -// session::add_logger([](std::string_view msg) { -// tsfn.BlockingCall( -// new std::string(msg), -// [](Napi::Env env, Napi::Function jsCallback, std::string* msg) { -// Napi::HandleScope scope(env); -// Napi::Function consoleLog = env.Global() -// .Get("console") -// .As() -// .Get("log") -// .As(); -// Napi::String jsStr = Napi::String::New(env, "libsession-util: " + *msg); -// consoleLog.Call({jsStr}); -// delete msg; -// }); -// }); -// oxen::log::set_level_default(oxen::log::Level::info); +Napi::ThreadSafeFunction tsfn; Napi::Object InitAll(Napi::Env env, Napi::Object exports) { using namespace session::nodeapi; + tsfn = Napi::ThreadSafeFunction::New( + env, + Napi::Function::New(env, [](const Napi::CallbackInfo& info) {}), + "LoggerCallback", + 0, + 1); + + session::add_logger([](std::string_view msg) { + tsfn.BlockingCall( + new std::string(msg), + [](Napi::Env env, Napi::Function jsCallback, std::string* msg) { + Napi::HandleScope scope(env); + Napi::Function consoleLog = env.Global() + .Get("console") + .As() + .Get("log") + .As(); + Napi::String jsStr = Napi::String::New(env, "libsession-util: " + *msg); + consoleLog.Call({jsStr}); + delete msg; + }); + }); + oxen::log::set_level_default(oxen::log::Level::info); + ConstantsWrapper::Init(env, exports); // Group wrappers init From 6337d2e602fab46b76ef7595fb2bab8309888772 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 24 Apr 2025 16:29:40 +1000 Subject: [PATCH 2/2] chore: add macos 14 (arm) to make sure libsession-util-nodejs builds --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dc74af4..28163b4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - os: [windows-2022, macos-13, ubuntu-22.04] + os: [windows-2022, macos-13, macos-14, ubuntu-22.04] env: SIGNAL_ENV: production GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}