Skip to content

Commit

Permalink
refactor(addon): expose hasPipeWire instead of throwing
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Oct 14, 2023
1 parent 2bc11cb commit 7c5837d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
6 changes: 6 additions & 0 deletions addon/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ struct patchbay : public Napi::ObjectWrap<patchbay>
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)
{
Expand All @@ -99,6 +104,7 @@ struct patchbay : public Napi::ObjectWrap<patchbay>
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)};
Expand Down
2 changes: 1 addition & 1 deletion include/vencord/patchbay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ namespace vencord

public:
[[nodiscard]] static patchbay &get();
[[nodiscard]] static bool is_pipewire();
[[nodiscard]] static bool has_pipewire();
};
} // namespace vencord
6 changes: 4 additions & 2 deletions lib/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 1 addition & 6 deletions src/patchbay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@ namespace vencord

if (!instance)
{
if (!is_pipewire())
{
throw std::runtime_error("Audio Server is not PipeWire");
}

instance = std::unique_ptr<patchbay>(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");
Expand Down
4 changes: 3 additions & 1 deletion tests/node/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 7c5837d

Please sign in to comment.