Skip to content

Commit

Permalink
feat(client): config entry to disable input device
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Sep 5, 2023
1 parent 2b70772 commit 91c7157
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void initialize(@NotNull ServerInfo serverInfo) {
config.getVoice().getStereoCapture().value()
);

if (!getDevice().isPresent()) {
if (!getDevice().isPresent() && !config.getVoice().getDisableInputDevice().value()) {
try {
InputDevice device = voiceClient.getDeviceManager().openInputDevice(format, Params.EMPTY);
devices.replace(null, device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private void tickJob() throws DeviceException {
}

if (inputDevices.isEmpty()) {
if (inputFactory.getDeviceNames().size() > 0) {
if (inputFactory.getDeviceNames().size() > 0 && !config.getVoice().getDisableInputDevice().value()) {
try {
replace(null, voiceClient.getDeviceManager().openInputDevice(null, Params.EMPTY));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ public static class Voice implements ClientConfig.Voice {
@ConfigField
private ConfigEntry<String> outputDevice = new ConfigEntry<>("");

@ConfigField
private BooleanConfigEntry disableInputDevice = new BooleanConfigEntry(false);

@ConfigField
private BooleanConfigEntry useJavaxInput = new BooleanConfigEntry(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ private OptionEntry<DropDownWidget> createMicrophoneEntry() {

ImmutableList<String> inputDeviceNames = deviceFactory.get().getDeviceNames();
Collection<AudioDevice> inputDevices = this.devices.getDevices(DeviceType.INPUT);
Optional<AudioDevice> inputDevice = inputDevices.stream().findFirst();
Optional<AudioDevice> inputDevice = Optional.empty();
if (!config.getVoice().getDisableInputDevice().value()) {
inputDevice = inputDevices.stream().findFirst();
}

DropDownWidget dropdown = new DropDownWidget(
parent,
Expand All @@ -164,7 +167,7 @@ private OptionEntry<DropDownWidget> createMicrophoneEntry() {
}
);

dropdown.setActive(!inputDeviceNames.isEmpty());
dropdown.setActive(!inputDeviceNames.isEmpty() && !config.getVoice().getDisableInputDevice().value());

return new OptionEntry<>(
MinecraftTextComponent.translatable("gui.plasmovoice.devices.microphone"),
Expand Down Expand Up @@ -288,6 +291,8 @@ private void reloadOutputDevice() {
}

private void reloadInputDevice() {
if (config.getVoice().getDisableInputDevice().value()) return;

try {
InputDevice device = devices.openInputDevice(null, Params.EMPTY);

Expand Down

0 comments on commit 91c7157

Please sign in to comment.