diff --git a/github b/github index b3e3903..e5b65f4 160000 --- a/github +++ b/github @@ -1 +1 @@ -Subproject commit b3e3903e67e8b0dff7d847a5a3690d49123ccf95 +Subproject commit e5b65f461c44e440473dde270213a0153021f6b0 diff --git a/modules/core/app-updater/index.ts b/modules/core/app-updater/index.ts index d291556..bfa4b89 100644 --- a/modules/core/app-updater/index.ts +++ b/modules/core/app-updater/index.ts @@ -836,7 +836,7 @@ async function check_update(channel: string) { console.error(error); return; } - if(version) { + if(version && !update_question_open) { update_question_open = true; dialog.showMessageBox({ buttons: ["update now", "remind me later"], diff --git a/modules/core/instance_handler.ts b/modules/core/instance_handler.ts index bbe0622..027cee5 100644 --- a/modules/core/instance_handler.ts +++ b/modules/core/instance_handler.ts @@ -1,4 +1,3 @@ -import * as electron from "electron"; import * as main_window from "./main_window"; export function handle_second_instance_call(argv: string[], work_dir: string) { @@ -10,12 +9,13 @@ export function handle_second_instance_call(argv: string[], work_dir: string) { return; } main_window.main_window.focus(); + execute_connect_urls(original_args); +} - { - const connect_url = argv.find(e => e.startsWith("teaclient://")); - if(connect_url) { - console.log("Received connect url: %s", connect_url); - main_window.main_window.webContents.send('connect', connect_url); - } +export function execute_connect_urls(argv: string[]) { + const connect_urls = argv.filter(e => e.startsWith("teaclient://")); + for(const url of connect_urls) { + console.log("Received connect url: %s", url); + main_window.main_window.webContents.send('connect', url); } } \ No newline at end of file diff --git a/modules/core/main.ts b/modules/core/main.ts index 4bc2bb7..c23eb46 100644 --- a/modules/core/main.ts +++ b/modules/core/main.ts @@ -9,33 +9,8 @@ import MessageBoxOptions = electron.MessageBoxOptions; import {process_args, parse_arguments, Arguments} from "../shared/process-arguments"; import {open as open_changelog} from "./app-updater/changelog"; import * as crash_handler from "../crash_handler"; -import {open_preview} from "./url-preview"; async function execute_app() { - /* legacy, will be removed soon */ - if(process_args.has_value("update-failed")) { - const result = await electron.dialog.showMessageBox({ - type: "error", - message: "Failed to execute update:\n" + process_args.value("update-failed"), - title: "Update failed!", - buttons: ["retry", "ignore"] - } as MessageBoxOptions); - if(result.response == 0) - if(await app_updater.execute_graphical(await app_updater.selected_channel(), false)) - return; - } else if(process_args.has_value("update-succeed")) { - const result = await electron.dialog.showMessageBox({ - type: "info", - message: "Update successfully installed!\nShould we launch TeaClient?", - title: "Update succeeded!", - buttons: ["yes", "no"] - } as MessageBoxOptions); - if(result.response != 0) { - electron.app.exit(0); - return; //Not really required here! - } - } - if(process_args.has_value("update-execute")) { console.log("Executing update " + process_args.value("update-execute")); await app_updater.execute_update(process_args.value("update-execute"), callback => { @@ -65,8 +40,8 @@ async function execute_app() { } } data.parse_success = true; - } catch($) { - console.error($); + } catch(error) { + console.warn("Failed to parse update response data: %o", error); } console.log("Update success: %o. Update data: %o", success, data); @@ -140,7 +115,7 @@ async function execute_app() { callback: async () => true }); - const result = await electron.dialog.showMessageBox({ + const result = await electron.dialog.showMessageBox(null, { type: type, message: message, title: title, diff --git a/modules/core/render-backend/index.ts b/modules/core/render-backend/index.ts index c44c6cf..a05f974 100644 --- a/modules/core/render-backend/index.ts +++ b/modules/core/render-backend/index.ts @@ -6,11 +6,15 @@ import BrowserWindow = electron.BrowserWindow; import {open as open_changelog} from "../app-updater/changelog"; import * as updater from "../app-updater"; +import {execute_connect_urls} from "../instance_handler"; +import {process_args} from "../../shared/process-arguments"; ipcMain.on('basic-action', (event, action, ...args: any[]) => { const window = BrowserWindow.fromWebContents(event.sender); - if(action === "open-changelog") { + if(action == "parse-connect-arguments") { + execute_connect_urls(process_args["_"] || []); + } else if(action === "open-changelog") { open_changelog(); } else if(action === "check-native-update") { updater.selected_channel().then(channel => updater.execute_graphical(channel, true)); diff --git a/modules/renderer/app_backend.ts b/modules/renderer/app_backend.ts index afeff17..dcaaa95 100644 --- a/modules/renderer/app_backend.ts +++ b/modules/renderer/app_backend.ts @@ -1,9 +1,37 @@ window["require_setup"](module); import * as electron from "electron"; -const remote = electron.remote; -electron.ipcRenderer.on('connect', (event, url) => { - console.log(tr("Received connect event to %s"), url); - console.error(tr("Dropping connect event (Currently not supported)")); -}); \ No newline at end of file +electron.ipcRenderer.on('connect', (event, url) => handle_native_connect_request(url)); + +function handle_native_connect_request(url_string: string) { + console.log(tr("Received connect event to %s"), url_string); + + + if(!url_string.toLowerCase().startsWith("teaclient://")) { + createErrorModal(tr("Failed to parse connect URL"), tra("Failed to parse connect URL (Unknown protocol).{:br:}URL: {}", url_string)).open(); + return; + } + + let url: URL; + try { + url = new URL("https://" + url_string.substring(10)); + } catch(error) { + createErrorModal(tr("Failed to parse connect URL"), tra("Failed to parse connect URL.{:br:}URL: {}", url_string)).open(); + return; + } + + let connection = server_connections.active_connection_handler(); + if(connection.connected) + connection = server_connections.spawn_server_connection_handler(); + + handle_connect_request({ + address: url.host, + password: { + value: url.password, + hashed: (url.searchParams.get("password_raw") || "0") == "0" + }, + profile: url.searchParams.get("profile"), + username: url.searchParams.get("username") + }, connection) +} \ No newline at end of file diff --git a/modules/renderer/index.ts b/modules/renderer/index.ts index a9979d1..70b2234 100644 --- a/modules/renderer/index.ts +++ b/modules/renderer/index.ts @@ -1,11 +1,12 @@ /// -import {Arguments, process_args, parse_arguments} from "../shared/process-arguments"; +import {Arguments, parse_arguments, process_args} from "../shared/process-arguments"; +import * as electron from "electron"; import {remote} from "electron"; import * as crash_handler from "../crash_handler"; -import * as electron from "electron"; import * as path from "path"; import * as os from "os"; +import ipcRenderer = electron.ipcRenderer; /* first of all setup crash handler */ { @@ -112,6 +113,14 @@ export const initialize = async () => { }, priority: 100 }); + + loader.register_task(loader.Stage.LOADED, { + name: "argv connect", + function: async () => { + ipcRenderer.send('basic-action', "parse-connect-arguments"); + }, + priority: 0 + }) }; const jquery_initialize = async () => { diff --git a/modules/renderer/ppt.ts b/modules/renderer/ppt.ts index e093261..cdfd1af 100644 --- a/modules/renderer/ppt.ts +++ b/modules/renderer/ppt.ts @@ -20,11 +20,10 @@ namespace _ppt { key_alt: nevent.key_alt, key_windows: nevent.key_windows } as any; - - //console.debug("Trigger key event %o", key_event); + //console.debug("Trigger key event %o", type); for (const listener of key_listener) - listener(event); + listener && listener(event); } function native_keyhook(event: NKeyEvent) { @@ -36,6 +35,8 @@ namespace _ppt { listener_key(ppt.EventType.KEY_RELEASE, event); else if(event.type == 2) listener_key(ppt.EventType.KEY_TYPED, event); + else + console.warn(tr("Received unknown native event: %o"), event); } export async function initialize() : Promise { @@ -70,20 +71,6 @@ namespace _ppt { let key_hooks_active: ppt.KeyHook[] = []; - function listener_blur() { - current_state.special[ppt.SpecialKey.ALT] = false; - current_state.special[ppt.SpecialKey.CTRL] = false; - current_state.special[ppt.SpecialKey.SHIFT] = false; - current_state.special[ppt.SpecialKey.WINDOWS] = false; - - for(const code of Object.keys(current_state.keys)) - delete current_state[code]; - - for(const hook of key_hooks_active) - hook.callback_release(); - key_hooks_active = []; - } - function listener_hook(event: ppt.KeyEvent) { if(event.type == ppt.EventType.KEY_TYPED) return; @@ -142,7 +129,7 @@ namespace _ppt { export function key_pressed(code: string | ppt.SpecialKey) : boolean { if(typeof(code) === 'string') - return current_state.code == code; + return typeof(current_state[code]) === "object"; return current_state.special[code]; } } diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 11de65a..6dda7ce 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -144,6 +144,7 @@ else() endif() include_directories(${NODEJS_INCLUDE_DIRS}) +add_subdirectory(dist/ext_nan/) function(build_update_installer) add_subdirectory(updater) endfunction() diff --git a/native/codec/codec/CeltCodec.cpp b/native/codec/codec/CeltCodec.cpp index 60e0703..3613eac 100644 --- a/native/codec/codec/CeltCodec.cpp +++ b/native/codec/codec/CeltCodec.cpp @@ -4,8 +4,8 @@ #include #include "CeltCodec.h" #include "NativeCodec.h" -#include "NanException.h" -#include "NanEventCallback.h" +#include "include/NanException.h" +#include "include/NanEventCallback.h" using namespace std; using namespace std::chrono; diff --git a/native/codec/codec/NativeCodec.cpp b/native/codec/codec/NativeCodec.cpp index a54838f..2183f36 100644 --- a/native/codec/codec/NativeCodec.cpp +++ b/native/codec/codec/NativeCodec.cpp @@ -5,7 +5,7 @@ #include "OpusCodec.h" #include "SpeexCodec.h" #include "CeltCodec.h" -#include "NanException.h" +#include "include/NanException.h" #include using namespace std; diff --git a/native/codec/codec/OpusCodec.cpp b/native/codec/codec/OpusCodec.cpp index af9c34a..77a06a3 100644 --- a/native/codec/codec/OpusCodec.cpp +++ b/native/codec/codec/OpusCodec.cpp @@ -4,8 +4,8 @@ #include #include "OpusCodec.h" #include "NativeCodec.h" -#include "NanException.h" -#include "NanEventCallback.h" +#include "include/NanException.h" +#include "include/NanEventCallback.h" using namespace std; using namespace std::chrono; diff --git a/native/codec/codec/SpeexCodec.cpp b/native/codec/codec/SpeexCodec.cpp index a8e2eaa..769474a 100644 --- a/native/codec/codec/SpeexCodec.cpp +++ b/native/codec/codec/SpeexCodec.cpp @@ -4,8 +4,8 @@ #include #include "SpeexCodec.h" #include "NativeCodec.h" -#include "NanException.h" -#include "NanEventCallback.h" +#include "include/NanException.h" +#include "include/NanEventCallback.h" using namespace std; using namespace std::chrono; diff --git a/native/crash_handler/binding.cc b/native/crash_handler/binding.cc index cd58be0..c559015 100644 --- a/native/crash_handler/binding.cc +++ b/native/crash_handler/binding.cc @@ -6,8 +6,8 @@ using namespace std; -#include "NanException.h" -#include "NanEventCallback.h" +#include "include/NanException.h" +#include "include/NanEventCallback.h" #include "src/crash_handler.h" #include diff --git a/native/dist/ext_nan/include/NanGet.h b/native/dist/ext_nan/include/NanGet.h new file mode 100644 index 0000000..12f671c --- /dev/null +++ b/native/dist/ext_nan/include/NanGet.h @@ -0,0 +1,39 @@ +#pragma once + +#include "./NanStrings.h" +#include +#include + +namespace Nan { + inline v8::MaybeLocal GetObject(v8::Local object, v8::Local key) { + auto result = Nan::Get(object, key); + if(result.IsEmpty()) + return v8::Local{}; + + return result.ToLocalChecked()->ToObject(v8::Isolate::GetCurrent()->GetCurrentContext()); + } + + inline v8::MaybeLocal Get(v8::Local object, const std::string_view& key) { + return Nan::Get(object, Nan::LocalString(key)); + } + + template ::value, int>::type * = nullptr> + inline v8::MaybeLocal Get(v8::Local object, K key) { + MaybeLocal result{Nan::Get(object, key)}; + if(result.IsEmpty()) + return v8::Local{}; + + return result.ToLocalChecked().As(); + } + + template + inline v8::Local GetLocal(v8::Local object, K key) { + return Nan::Get(object, key).FromMaybe(v8::Local{}); + } + + template + inline v8::MaybeLocal GetString(v8::Local object, T key) { return Get(object, key); } + + template + inline v8::Local GetStringLocal(v8::Local object, T key) { return GetLocal(object, key); } +} \ No newline at end of file diff --git a/native/dist/ext_nan/include/NanStrings.h b/native/dist/ext_nan/include/NanStrings.h index 3d4c65d..820571d 100644 --- a/native/dist/ext_nan/include/NanStrings.h +++ b/native/dist/ext_nan/include/NanStrings.h @@ -1,13 +1,15 @@ #pragma once +#include #include #include namespace Nan { /* UTF-8 Helpers */ - inline v8::Local StringUTF8(std::string_view buffer) { - Nan::EscapableHandleScope scope{}; - auto data = v8::String::NewFromUtf8(Nan::GetCurrentContext()->GetIsolate(), buffer.data(), v8::NewStringType::kNormal, buffer.length()); + inline v8::Local LocalStringUTF8(std::string_view buffer) { + auto isolate = Nan::GetCurrentContext()->GetIsolate(); + v8::EscapableHandleScope scope{isolate}; + auto data = v8::String::NewFromUtf8(isolate, buffer.data(), v8::NewStringType::kNormal, buffer.length()); v8::Local response{}; if(!data.ToLocal(&response)) @@ -15,39 +17,50 @@ namespace Nan { return scope.Escape(response); } - template - inline v8::Local StringUTF8(const char (&buffer)[S]) { - return Nan::StringUTF8(buffer, S); + inline v8::Local LocalStringUTF8(const std::string& buffer) { + return LocalStringUTF8(std::string_view{buffer}); } - inline v8::Local StringUTF8(const char* buffer, size_t length) { - return Nan::StringUTF8(std::string_view{buffer, length}); + inline v8::Local LocalStringUTF8(const char* buffer, size_t length) { + return Nan::LocalStringUTF8(std::string_view{buffer, length}); + } + + template + inline v8::Local LocalStringUTF8(const char (&buffer)[S]) { + return Nan::LocalStringUTF8((const char*) buffer, S - 1); } /* Latin1 Helpers */ - inline v8::Local String(std::string_view buffer) { - Nan::EscapableHandleScope scope{}; - auto data = v8::String::NewFromOneByte(Nan::GetCurrentContext()->GetIsolate(), (uint8_t*) buffer.data(), v8::NewStringType::kNormal, buffer.length()); + inline v8::Local LocalString(std::string_view buffer) { + auto isolate = Nan::GetCurrentContext()->GetIsolate(); + //v8::EscapableHandleScope scope{isolate}; + auto data = v8::String::NewFromOneByte(isolate, (uint8_t*) buffer.data(), v8::NewStringType::kNormal, buffer.length()); v8::Local response{}; if(!data.ToLocal(&response)) throw std::bad_alloc{}; - return scope.Escape(response); + return response; + //eturn scope.Escape(response); + } + + inline v8::Local LocalString(const std::string& buffer) { + return LocalString(std::string_view{buffer}); + } + + inline v8::Local LocalString(const char* buffer, size_t length) { + return Nan::LocalString(std::string_view{buffer, length}); } template - inline v8::Local String(const char (&buffer)[S]) { - return Nan::StringUTF8(buffer, S); - } - - inline v8::Local String(const char* buffer, size_t length) { - return Nan::StringUTF8(std::string_view{buffer, length}); + inline v8::Local LocalString(const char (&buffer)[S]) { + return Nan::LocalString((const char*) buffer, S - 1); } /* Wide char helpers */ - inline v8::Local String(std::wstring_view buffer) { - Nan::EscapableHandleScope scope{}; - auto data = v8::String::NewFromTwoByte(Nan::GetCurrentContext()->GetIsolate(), (uint16_t*) buffer.data(), v8::NewStringType::kNormal, buffer.length()); + inline v8::Local LocalString(std::wstring_view buffer) { + auto isolate = Nan::GetCurrentContext()->GetIsolate(); + v8::EscapableHandleScope scope{isolate}; + auto data = v8::String::NewFromTwoByte(isolate, (uint16_t*) buffer.data(), v8::NewStringType::kNormal, buffer.length()); v8::Local response{}; if(!data.ToLocal(&response)) @@ -55,12 +68,16 @@ namespace Nan { return scope.Escape(response); } - template - inline v8::Local String(const wchar_t (&buffer)[S]) { - return Nan::String(buffer, S); + inline v8::Local LocalString(const std::wstring& buffer) { + return LocalString(std::wstring_view{buffer}); } - inline v8::Local String(const wchar_t* buffer, size_t length) { - return Nan::String(std::wstring_view{buffer, length}); + template + inline v8::Local LocalString(const wchar_t (&buffer)[S]) { + return Nan::LocalString(buffer, S - 1); + } + + inline v8::Local LocalString(const wchar_t* buffer, size_t length) { + return Nan::LocalString(std::wstring_view{buffer, length}); } } \ No newline at end of file diff --git a/native/dist/ext_nan/test/main.cpp b/native/dist/ext_nan/test/main.cpp index 3ac0fea..ac7e70c 100644 --- a/native/dist/ext_nan/test/main.cpp +++ b/native/dist/ext_nan/test/main.cpp @@ -1,6 +1,7 @@ #include "include/NanEventCallback.h" #include "include/NanException.h" #include "include/NanStrings.h" +#include "include/NanGet.h" int main() { auto str = Nan::StringUTF8("Hello World"); diff --git a/native/dns/binding.cc b/native/dns/binding.cc index eb4b385..70ac7a4 100644 --- a/native/dns/binding.cc +++ b/native/dns/binding.cc @@ -10,8 +10,8 @@ using namespace std; -#include "NanException.h" -#include "NanEventCallback.h" +#include "include/NanException.h" +#include "include/NanEventCallback.h" std::unique_ptr resolver{nullptr}; diff --git a/native/ppt/binding.cc b/native/ppt/binding.cc index cf7009c..fe9124c 100644 --- a/native/ppt/binding.cc +++ b/native/ppt/binding.cc @@ -3,11 +3,12 @@ #include #include #include +#include using namespace std; -#include "NanException.h" -#include "NanEventCallback.h" +#include "include/NanException.h" +#include "include/NanEventCallback.h" #include "src/KeyboardHook.h" @@ -22,19 +23,19 @@ inline v8::Local event_to_object(const std::shared_ptr(); - object->Set(Nan::New("type").ToLocalChecked(), Nan::New(event->type)); - object->Set(Nan::New("key_code").ToLocalChecked(), Nan::New(event->code).ToLocalChecked()); + Nan::Set(object, Nan::LocalString("type"), Nan::New(event->type)); + Nan::Set(object, Nan::LocalString("key_code"), Nan::New(event->code).ToLocalChecked()); - object->Set(Nan::New("key_shift").ToLocalChecked(), Nan::New(event->key_shift)); - object->Set(Nan::New("key_alt").ToLocalChecked(), Nan::New(event->key_alt)); - object->Set(Nan::New("key_windows").ToLocalChecked(), Nan::New(event->key_windows)); - object->Set(Nan::New("key_ctrl").ToLocalChecked(), Nan::New(event->key_ctrl)); + Nan::Set(object, Nan::LocalString("key_shift"), Nan::New(event->key_shift)); + Nan::Set(object, Nan::LocalString("key_alt"), Nan::New(event->key_alt)); + Nan::Set(object, Nan::LocalString("key_windows"), Nan::New(event->key_windows)); + Nan::Set(object, Nan::LocalString("key_ctrl"), Nan::New(event->key_ctrl)); return scope.Escape(object); } NAN_METHOD(RegisterCallback) { - if(!info[0]->IsFunction()) { + if(info.Length() < 1 || !info[0]->IsFunction()) { NAN_THROW_EXCEPTION(Error, "argument must be a function!"); return; } @@ -47,7 +48,7 @@ NAN_METHOD(RegisterCallback) { } NAN_METHOD(UnregisterCallback) { - if(!info[0]->IsFunction()) { + if(info.Length() < 1 || !info[0]->IsFunction()) { NAN_THROW_EXCEPTION(Error, "argument must be a function!"); return; } @@ -94,7 +95,8 @@ NAN_MODULE_INIT(init) { v8::Local args[] = { object }; - callback->Call(1, args); + + Nan::Call(*callback, Nan::Undefined().As(), 1, args); } } }); diff --git a/native/serverconnection/CMakeLists.txt b/native/serverconnection/CMakeLists.txt index f60bdee..32928a3 100644 --- a/native/serverconnection/CMakeLists.txt +++ b/native/serverconnection/CMakeLists.txt @@ -125,6 +125,7 @@ set(REQUIRED_LIBRARIES ${ed25519_LIBRARIES_STATIC} spdlog::spdlog + Nan::Helpers ) if (WIN32) diff --git a/native/serverconnection/src/audio/js/AudioConsumer.cpp b/native/serverconnection/src/audio/js/AudioConsumer.cpp index c3c7075..a8e6d7b 100644 --- a/native/serverconnection/src/audio/js/AudioConsumer.cpp +++ b/native/serverconnection/src/audio/js/AudioConsumer.cpp @@ -68,7 +68,7 @@ void AudioConsumerWrapper::do_wrap(const v8::Local &obj) { Nan::HandleScope scope; auto handle = this->handle(); - v8::Local callback_function = handle->Get(Nan::New("callback_data").ToLocalChecked()); + v8::Local callback_function = Nan::Get(handle, Nan::New("callback_data").ToLocalChecked()).FromMaybe(v8::Local{}); if(callback_function.IsEmpty() || callback_function->IsNullOrUndefined() || !callback_function->IsFunction()) { lock_guard lock(this->_data_lock); this->_data_entries.clear(); @@ -100,7 +100,7 @@ void AudioConsumerWrapper::do_wrap(const v8::Local &obj) { Nan::HandleScope scope; auto handle = this->handle(); - v8::Local callback_function = handle->Get(Nan::New("callback_ended").ToLocalChecked()); + v8::Local callback_function = Nan::Get(handle, Nan::New("callback_ended").ToLocalChecked()).FromMaybe(v8::Local{}); if(callback_function.IsEmpty() || callback_function->IsNullOrUndefined() || !callback_function->IsFunction()) return; callback_function.As()->Call(Nan::GetCurrentContext(), Nan::Undefined(), 0, nullptr); @@ -110,7 +110,7 @@ void AudioConsumerWrapper::do_wrap(const v8::Local &obj) { Nan::HandleScope scope; auto handle = this->handle(); - v8::Local callback_function = handle->Get(Nan::New("callback_started").ToLocalChecked()); + v8::Local callback_function = Nan::Get(handle, Nan::New("callback_started").ToLocalChecked()).FromMaybe(v8::Local{}); if(callback_function.IsEmpty() || callback_function->IsNullOrUndefined() || !callback_function->IsFunction()) return; callback_function.As()->Call(Nan::GetCurrentContext(), Nan::Undefined(), 0, nullptr); @@ -240,7 +240,7 @@ NAN_METHOD(AudioConsumerWrapper::_get_filters) { auto result = Nan::New(filters.size()); for(size_t index = 0; index < filters.size(); index++) - result->Set(index, filters[index]->handle()); + Nan::Set(result, index, filters[index]->handle()); info.GetReturnValue().Set(result); } diff --git a/native/serverconnection/src/audio/js/AudioConsumer.h b/native/serverconnection/src/audio/js/AudioConsumer.h index 00658e9..9681480 100644 --- a/native/serverconnection/src/audio/js/AudioConsumer.h +++ b/native/serverconnection/src/audio/js/AudioConsumer.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include namespace tc { namespace audio { diff --git a/native/serverconnection/src/audio/js/AudioFilter.h b/native/serverconnection/src/audio/js/AudioFilter.h index ecd6b24..6c4202d 100644 --- a/native/serverconnection/src/audio/js/AudioFilter.h +++ b/native/serverconnection/src/audio/js/AudioFilter.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace tc { namespace audio { diff --git a/native/serverconnection/src/audio/js/AudioOutputStream.h b/native/serverconnection/src/audio/js/AudioOutputStream.h index a2a89c7..dfae54b 100644 --- a/native/serverconnection/src/audio/js/AudioOutputStream.h +++ b/native/serverconnection/src/audio/js/AudioOutputStream.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace tc { namespace audio { diff --git a/native/serverconnection/src/audio/js/AudioPlayer.cpp b/native/serverconnection/src/audio/js/AudioPlayer.cpp index 3e4d3c1..dcf6d66 100644 --- a/native/serverconnection/src/audio/js/AudioPlayer.cpp +++ b/native/serverconnection/src/audio/js/AudioPlayer.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "AudioPlayer.h" #include "../AudioOutput.h" #include "../AudioDevice.h" @@ -28,7 +29,7 @@ NAN_METHOD(audio::available_devices) { auto device_info = Nan::New(); auto device = devices[index]; - Nan::Set(device_info, Nan::New("name").ToLocalChecked(), Nan::New(device->name).ToLocalChecked()); + Nan::Set(device_info, Nan::LocalString("name"), Nan::LocalString(device->name)); Nan::Set(device_info, Nan::New("driver").ToLocalChecked(), Nan::New(device->driver).ToLocalChecked()); Nan::Set(device_info, Nan::New("device_id").ToLocalChecked(), Nan::New(base64::encode(digest::sha1(device->name + device->driver))).ToLocalChecked()); @@ -40,7 +41,7 @@ NAN_METHOD(audio::available_devices) { Nan::Set(device_info, Nan::New("device_index").ToLocalChecked(), Nan::New(device->device_id)); - result->Set(index, device_info); + Nan::Set(result, index, device_info); } info.GetReturnValue().Set(result); diff --git a/native/serverconnection/src/audio/js/AudioRecorder.cpp b/native/serverconnection/src/audio/js/AudioRecorder.cpp index 69c036b..4816d6e 100644 --- a/native/serverconnection/src/audio/js/AudioRecorder.cpp +++ b/native/serverconnection/src/audio/js/AudioRecorder.cpp @@ -227,7 +227,7 @@ NAN_METHOD(AudioRecorderWrapper::_get_consumers) { auto result = Nan::New(consumers.size()); for(size_t index = 0; index < consumers.size(); index++) - result->Set(index, consumers[index]->handle()); + Nan::Set(result, index, consumers[index]->handle()); info.GetReturnValue().Set(result); } diff --git a/native/serverconnection/src/bindings.cpp b/native/serverconnection/src/bindings.cpp index 38659cc..13c3f48 100644 --- a/native/serverconnection/src/bindings.cpp +++ b/native/serverconnection/src/bindings.cpp @@ -7,8 +7,8 @@ #include #include "logger.h" -#include "NanException.h" -#include "NanEventCallback.h" +#include "include/NanException.h" +#include "include/NanEventCallback.h" #include "connection/ServerConnection.h" #include "connection/audio/VoiceConnection.h" #include "connection/audio/VoiceClient.h" diff --git a/native/serverconnection/src/connection/ServerConnection.cpp b/native/serverconnection/src/connection/ServerConnection.cpp index f5e4980..2681ce8 100644 --- a/native/serverconnection/src/connection/ServerConnection.cpp +++ b/native/serverconnection/src/connection/ServerConnection.cpp @@ -14,6 +14,7 @@ #include #include #include +#include //#define FUZZ_VOICE //#define SHUFFLE_VOICE @@ -404,15 +405,15 @@ NAN_METHOD(ServerConnection::send_command) { ts::Command cmd(*Nan::Utf8String(command)); for(size_t index = 0; index < arguments->Length(); index++) { - auto object = arguments->Get((uint32_t) index); - if(!object->IsObject()) { + auto object = Nan::GetLocal(arguments, (uint32_t) index); + if(object.IsEmpty() || !object->IsObject()) { Nan::ThrowError(Nan::New("invalid parameter (" + to_string(index) + ")").ToLocalChecked()); return; } v8::Local properties = object->ToObject(Nan::GetCurrentContext()).ToLocalChecked()->GetOwnPropertyNames(Nan::GetCurrentContext()).ToLocalChecked(); for(uint32_t i = 0; i < properties->Length(); i++) { - auto key = properties->Get(i)->ToString(Nan::GetCurrentContext()).ToLocalChecked(); + auto key = Nan::GetStringLocal(properties, i); auto value = object->ToObject(Nan::GetCurrentContext()).ToLocalChecked()->Get(Nan::GetCurrentContext(), key).ToLocalChecked(); string key_string = *Nan::Utf8String(key); @@ -435,8 +436,8 @@ NAN_METHOD(ServerConnection::send_command) { for(size_t index = 0; index < switches->Length(); index++) { - auto object = switches->Get((uint32_t) index); - if(!object->IsString()) { + auto object = Nan::GetStringLocal(switches, (uint32_t) index); + if(object.IsEmpty()) { Nan::ThrowError(Nan::New("invalid switch (" + to_string(index) + ")").ToLocalChecked()); return; } @@ -646,7 +647,7 @@ void ServerConnection::_execute_callback_commands() { for(const auto& key : bulk.keys()) Nan::Set(object, Nan::New(key).ToLocalChecked(), Nan::New(bulk[key].string()).ToLocalChecked()); - parameters->Set((uint32_t) index, object); + Nan::Set(parameters, (uint32_t) index, object); } arguments[1] = parameters; @@ -654,7 +655,7 @@ void ServerConnection::_execute_callback_commands() { auto switched = Nan::New((int) next_command->parms().size()); for(size_t index = 0; index < next_command->parms().size(); index++) { auto& key = next_command->parms()[index]; - parameters->Set((uint32_t) index, Nan::New(key).ToLocalChecked()); + Nan::Set(parameters, (uint32_t) index, Nan::New(key).ToLocalChecked()); } arguments[2] = switched; diff --git a/native/serverconnection/src/connection/ServerConnection.h b/native/serverconnection/src/connection/ServerConnection.h index 69fded3..cd15401 100644 --- a/native/serverconnection/src/connection/ServerConnection.h +++ b/native/serverconnection/src/connection/ServerConnection.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/native/serverconnection/src/connection/audio/VoiceClient.h b/native/serverconnection/src/connection/audio/VoiceClient.h index 1738ea9..e721f7d 100644 --- a/native/serverconnection/src/connection/audio/VoiceClient.h +++ b/native/serverconnection/src/connection/audio/VoiceClient.h @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include "../../audio/AudioResampler.h" diff --git a/native/serverconnection/src/connection/ft/FileTransferManager.cpp b/native/serverconnection/src/connection/ft/FileTransferManager.cpp index 606fabe..32dd063 100644 --- a/native/serverconnection/src/connection/ft/FileTransferManager.cpp +++ b/native/serverconnection/src/connection/ft/FileTransferManager.cpp @@ -8,6 +8,8 @@ #ifndef WIN32 #include #include +#include + #ifndef IPPROTO_TCP #define IPPROTO_TCP (0) #endif @@ -616,11 +618,11 @@ NAN_METHOD(JSTransfer::NewInstance) { * object: HandledTransferObject; */ auto options = info[0]->ToObject(Nan::GetCurrentContext()).ToLocalChecked(); - v8::Local key = options->Get(Nan::New("transfer_key").ToLocalChecked()).As(); - v8::Local client_transfer_id = options->Get(Nan::New("client_transfer_id").ToLocalChecked()).As(); - v8::Local server_transfer_id = options->Get(Nan::New("server_transfer_id").ToLocalChecked()).As(); - v8::Local remote_address = options->Get(Nan::New("remote_address").ToLocalChecked()).As(); - v8::Local remote_port = options->Get(Nan::New("remote_port").ToLocalChecked()).As(); + auto key = Nan::GetStringLocal(options, "transfer_key"); + v8::Local client_transfer_id = Nan::GetLocal(options, "client_transfer_id"); + v8::Local server_transfer_id = Nan::GetLocal(options, "server_transfer_id"); + v8::Local remote_address = Nan::GetStringLocal(options, "remote_address"); + v8::Local remote_port = Nan::GetLocal(options, "remote_port"); if( key.IsEmpty() || !key->IsString() || @@ -633,7 +635,7 @@ NAN_METHOD(JSTransfer::NewInstance) { return; } - auto wrapped_options = options->Get(Nan::New("object").ToLocalChecked()).As(); + auto wrapped_options = Nan::GetLocal(options, "object"); if(!TransferObjectWrap::is_wrap(wrapped_options)) { Nan::ThrowError("invalid handle"); return; diff --git a/native/serverconnection/src/connection/ft/FileTransferManager.h b/native/serverconnection/src/connection/ft/FileTransferManager.h index 6e959ef..d8bc3d8 100644 --- a/native/serverconnection/src/connection/ft/FileTransferManager.h +++ b/native/serverconnection/src/connection/ft/FileTransferManager.h @@ -17,7 +17,7 @@ #if NODEJS_API #include - #include + #include #endif namespace tc { diff --git a/native/serverconnection/src/logger.cpp b/native/serverconnection/src/logger.cpp index 94a130f..1cf469f 100644 --- a/native/serverconnection/src/logger.cpp +++ b/native/serverconnection/src/logger.cpp @@ -1,4 +1,5 @@ #include +#include #include "logger.h" /* Basic */ @@ -8,7 +9,8 @@ void force_log_raw(logger::category::value, spdlog::level::level_enum level, con void force_log_node(logger::category::value, spdlog::level::level_enum, const std::string_view &); #ifdef NODEJS_API -#include +#include +#include /* NODE JS */ struct LogMessage { @@ -41,16 +43,19 @@ struct StdExternalStringResourceBase : public v8::String::ExternalOneByteStringR std::string message; }; -inline v8::Local get_logger_method() { +inline v8::MaybeLocal get_logger_method() { v8::Local global_context = Nan::GetCurrentContext()->Global(); - v8::Local logger_context = global_context->Get(Nan::New("logger").ToLocalChecked()).As(); - v8::Local logger_method = logger_context->Get(Nan::New("log").ToLocalChecked()); - if(!logger_method.IsEmpty() && !logger_method->IsNullOrUndefined()) - return logger_method; + auto logger = Nan::GetLocal(global_context, "logger"); + if(!logger.IsEmpty()) { + auto log_function = Nan::Get(logger, "log"); + if(!log_function.IsEmpty()) return log_function; + } - logger_context = global_context->Get(Nan::New("console").ToLocalChecked()).As(); - return logger_context->Get(Nan::New("log").ToLocalChecked()); + auto console = Nan::GetLocal(global_context, "console"); + assert(!console.IsEmpty()); + + return Nan::Get(console, "log"); } void logger::initialize_node() { @@ -58,7 +63,7 @@ void logger::initialize_node() { Nan::HandleScope scope; auto isolate = Nan::GetCurrentContext()->GetIsolate(); - v8::Local logger_method = get_logger_method(); + auto logger_method = get_logger_method(); v8::Local arguments[3]; while(true) { @@ -72,14 +77,15 @@ void logger::initialize_node() { log_messages_tail = &log_messages_head; messages_lock.unlock(); - if(!logger_method.IsEmpty() && !logger_method->IsNullOrUndefined()) { - arguments[0] = Nan::New(entry->category); - arguments[1] = Nan::New(entry->level); - arguments[2] = v8::String::NewExternalOneByte(isolate, new StdExternalStringResourceBase(entry->message)).ToLocalChecked(); + if(!logger_method.IsEmpty()) { + auto logger = logger_method.ToLocalChecked(); + arguments[0] = Nan::New(entry->category); + arguments[1] = Nan::New(entry->level); + arguments[2] = v8::String::NewExternalOneByte(isolate, new StdExternalStringResourceBase(entry->message)).ToLocalChecked(); - logger_method.As()->Call(Nan::GetCurrentContext(), Nan::Undefined(), 3, arguments); + logger.As()->Call(Nan::GetCurrentContext(), Nan::Undefined(), 3, arguments); } else { - std::cout << "Failed to log message! Invalid method!" << std::endl; + std::cout << "Failed to log message! Invalid method!" << std::endl; } delete entry; diff --git a/native/serverconnection/src/logger.h b/native/serverconnection/src/logger.h index 821765e..83b7720 100644 --- a/native/serverconnection/src/logger.h +++ b/native/serverconnection/src/logger.h @@ -39,10 +39,8 @@ namespace logger { template inline void force_log(category::value category, level::level_enum lvl, const char *fmt, const Args &... args) { try { - fmt::MemoryWriter fmt_writer; - fmt_writer.write(fmt, args...); - - _force_log(category, lvl, std::string_view{fmt_writer.data(), fmt_writer.size()}); + const auto msg = fmt::format(fmt, args...); + _force_log(category, lvl, msg); } catch (const std::exception &ex) {