essential-actions

Clone or download

Reverse toggle if failed

Modified Files

package togglemute;
package togglemute;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.ToggleAction;
import com.stream_pi.action_api.externalplugin.ToggleAction;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import mother.motherconnection.MotherConnection;
import mother.motherconnection.MotherConnection;
public class ToggleMute extends ToggleAction
public class ToggleMute extends ToggleAction
{
{
public ToggleMute()
public ToggleMute()
{
{
setName("Toggle Mute");
setName("Toggle Mute");
setCategory("OBS");
setCategory("OBS");
setVisibilityInServerSettingsPane(false);
setVisibilityInServerSettingsPane(false);
setAuthor("rnayabed");
setAuthor("rnayabed");
setVersion(MotherConnection.VERSION);
setVersion(MotherConnection.VERSION);
}
}
@Override
@Override
public void onToggleOn() throws Exception
public void onToggleOn() throws Exception
{
{
onClicked(true);
onClicked(true);
}
}
@Override
@Override
public void onToggleOff() throws Exception
public void onToggleOff() throws Exception
{
{
onClicked(false);
onClicked(false);
}
}
@Override
@Override
public void initProperties() throws Exception
public void initProperties() throws Exception
{
{
Property sourceProperty = new Property("source", Type.STRING);
Property sourceProperty = new Property("source", Type.STRING);
sourceProperty.setDisplayName("Source");
sourceProperty.setDisplayName("Source");
Property autoConnectProperty = new Property("auto_connect", Type.BOOLEAN);
Property autoConnectProperty = new Property("auto_connect", Type.BOOLEAN);
autoConnectProperty.setDefaultValueBoolean(true);
autoConnectProperty.setDefaultValueBoolean(true);
autoConnectProperty.setDisplayName("Auto Connect if not connected");
autoConnectProperty.setDisplayName("Auto Connect if not connected");
addClientProperties(sourceProperty, autoConnectProperty);
addClientProperties(sourceProperty, autoConnectProperty);
}
}
public void onClicked(boolean mute) throws MinorException
public void onClicked(boolean mute) throws MinorException
{
{
String source = getClientProperties().getSingleProperty("source").getStringValue();
String source = getClientProperties().getSingleProperty("source").getStringValue();
if(source.isBlank())
if(source.isBlank())
{
{
reverse(mute);
throw new MinorException("Blank Source Name","No Source specified");
throw new MinorException("Blank Source Name","No Source specified");
}
}
if (MotherConnection.getRemoteController() == null)
if (MotherConnection.getRemoteController() == null)
{
{
boolean autoConnect = getClientProperties().getSingleProperty(
boolean autoConnect = getClientProperties().getSingleProperty(
"auto_connect"
"auto_connect"
).getBoolValue();
).getBoolValue();
if(autoConnect)
if(autoConnect)
{
{
MotherConnection.connect(()->setMute(source, mute));
MotherConnection.connect(()->setMute(source, mute));
}
}
else
else
{
{
MotherConnection.showOBSNotRunningError();
MotherConnection.showOBSNotRunningError();
}
}
}
}
else
else
{
{
setMute(source, mute);
setMute(source, mute);
}
}
}
}
public void setMute(String scene, boolean mute)
public void setMute(String scene, boolean mute)
{
{
MotherConnection.getRemoteController().setMute(scene, mute, setMuteResponse -> {
MotherConnection.getRemoteController().setMute(scene, mute, setMuteResponse -> {
String status = setMuteResponse.getStatus();
String status = setMuteResponse.getStatus();
String error = setMuteResponse.getError();
String error = setMuteResponse.getError();
if(status.equals("error"))
if(status.equals("error"))
{
{
String content;
String content;
if(error.equals("source does not exist"))
if(error.equals("source does not exist"))
{
{
content = "Source "+scene+" does not exist.";
content = "Source "+scene+" does not exist.";
}
}
else
else
{
{
content = error;
content = error;
}
}
new StreamPiAlert("OBS",content, StreamPiAlertType.ERROR).show();
new StreamPiAlert("OBS",content, StreamPiAlertType.ERROR).show();
reverse(mute);
}
}
});
});
}
private void reverse(boolean current)
{
try
{
setCurrentStatus(!current);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}