Skip to content

Commit

Permalink
Refactor getXdgStreamDetails dbus signal handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Ape committed Jan 6, 2025
1 parent c993607 commit 6ae1095
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/main/java/org/dpsoftware/managers/PipelineManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,36 @@ public static XdgStreamDetails getXdgStreamDetails() {
&& signal.getParameters()[1] instanceof LinkedHashMap
&& ((UInt32) signal.getParameters()[0]).intValue() == 0 // verify success-code
) {
var parameters = (LinkedHashMap<?, ?>) signal.getParameters()[1];

// parse signal & set appropriate Future as the result
if (((LinkedHashMap<?, ?>) signal.getParameters()[1]).containsKey("session_handle")) {
sessionHandleMaybe.complete((String) (((Variant<?>) ((LinkedHashMap<?, ?>) signal.getParameters()[1]).get("session_handle")).getValue()));
} else if (((LinkedHashMap<?, ?>) signal.getParameters()[1]).containsKey("streams")) {
if (((LinkedHashMap<?, ?>) signal.getParameters()[1]).get("restore_token") != null) {
if (parameters.containsKey("session_handle")) {
var sessionHandle = (Variant<?>) parameters.get("session_handle");
sessionHandleMaybe.complete((String) sessionHandle.getValue());
} else if (parameters.containsKey("streams")) {
var restoreTokenVariant = (Variant<?>) parameters.get("restore_token");

if (restoreTokenVariant != null) {
restoreTokenMatch.set(true);
String restoreToken = (String) ((Variant<?>) ((LinkedHashMap<?, ?>) signal.getParameters()[1]).get("restore_token")).getValue();
String restoreToken = (String) restoreTokenVariant.getValue();

try {
if (!restoreToken.equals(MainSingleton.getInstance().config.getScreenCastRestoreToken())) {
MainSingleton.getInstance().config.setScreenCastRestoreToken((String) ((Variant<?>) ((LinkedHashMap<?, ?>) signal.getParameters()[1]).get("restore_token")).getValue());
MainSingleton.getInstance().config.setScreenCastRestoreToken(restoreToken);
StorageManager storageManager = new StorageManager();
storageManager.writeConfig(MainSingleton.getInstance().config, null);
}
} catch (IOException e) {
log.error("Can't write config file.");
log.error("Can't write config file.", e);
}
}
streamIdMaybe.complete(((UInt32) ((Object[]) ((List<?>) (((Variant<?>) ((LinkedHashMap<?, ?>) signal.getParameters()[1]).get("streams")).getValue())).get(0))[0]).intValue());

// Extract stream ID
var streamsVariant = (Variant<?>) parameters.get("streams");
var streams = (List<?>) streamsVariant.getValue();
var streamData = (Object[]) streams.get(0);
var streamId = (UInt32) streamData[0];
streamIdMaybe.complete(streamId.intValue());
}
}
} catch (DBusException e) {
Expand Down

0 comments on commit 6ae1095

Please sign in to comment.