diff --git a/addon/addon.cpp b/addon/addon.cpp index a238230..113887a 100644 --- a/addon/addon.cpp +++ b/addon/addon.cpp @@ -89,6 +89,11 @@ struct patchbay : public Napi::ObjectWrap return {}; } + static Napi::Value has_pipewire(const Napi::CallbackInfo &info) + { + return Napi::Boolean::New(info.Env(), vencord::patchbay::has_pipewire()); + } + public: static Napi::Object Init(Napi::Env env, Napi::Object exports) { @@ -99,6 +104,7 @@ struct patchbay : public Napi::ObjectWrap InstanceMethod<&patchbay::link>("link", attributes), InstanceMethod<&patchbay::list>("list", attributes), InstanceMethod<&patchbay::unlink>("unlink", attributes), + StaticMethod<&patchbay::has_pipewire>("hasPipeWire", attributes), }); auto *constructor = new Napi::FunctionReference{Napi::Persistent(func)}; diff --git a/include/vencord/patchbay.hpp b/include/vencord/patchbay.hpp index cd95883..8926677 100644 --- a/include/vencord/patchbay.hpp +++ b/include/vencord/patchbay.hpp @@ -48,6 +48,6 @@ namespace vencord public: [[nodiscard]] static patchbay &get(); - [[nodiscard]] static bool is_pipewire(); + [[nodiscard]] static bool has_pipewire(); }; } // namespace vencord diff --git a/lib/module.d.ts b/lib/module.d.ts index 4a9b532..4a297c4 100644 --- a/lib/module.d.ts +++ b/lib/module.d.ts @@ -7,8 +7,10 @@ export interface Props export class PatchBay { - unlink(): void; list(): Props[]; - link(key: string, value: string, mode: "include" | "exclude"): boolean; + unlink(): void; + link(key: keyof Props, value: string, mode: "include" | "exclude"): boolean; + + static hasPipeWire(): boolean; } diff --git a/src/patchbay.cpp b/src/patchbay.cpp index 449cd5c..09ba471 100644 --- a/src/patchbay.cpp +++ b/src/patchbay.cpp @@ -31,18 +31,13 @@ namespace vencord if (!instance) { - if (!is_pipewire()) - { - throw std::runtime_error("Audio Server is not PipeWire"); - } - instance = std::unique_ptr(new patchbay); } return *instance; } - bool patchbay::is_pipewire() + bool patchbay::has_pipewire() { auto *loop = pa_mainloop_new(); auto *context = pa_context_new(pa_mainloop_get_api(loop), "venmic-info"); diff --git a/tests/node/api.test.js b/tests/node/api.test.js index 952a2d4..420ab8c 100644 --- a/tests/node/api.test.js +++ b/tests/node/api.test.js @@ -17,5 +17,7 @@ try catch (error) { console.warn("No PipeWire Server available"); - assert.throws(() => new venmic.PatchBay(), /(failed to create patchbay)|(is not pipewire)/ig); + + assert(!venmic.PatchBay.hasPipeWire()); + assert.throws(() => new venmic.PatchBay(), /failed to create patchbay/ig); }