Skip to content

Commit

Permalink
Add compatibility mode
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Nov 3, 2023
1 parent 5955341 commit aa85074
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 107 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ I also moved the code base to GitHub, where it can easier be maintained.

## Releases

The ![latest version](https://github.com/RetGal/Dayon/releases) is v11.0 (Ballsy Beaver) - released more than ten years after the initial release.
The ![latest version](https://github.com/RetGal/Dayon/releases) is v12.0 (Adorable Asteroid) - released more than ten years after the initial release.

This version comes with a new, access token based network configuration of the assisted.
This version comes with UPnP support for the assistant side. If enabled, the port forwarding rules will be created automatically.

The app is available directly from the <a href="https://www.microsoft.com/store/apps/9PBM5KW0C790">Microsoft Store</a>:

Expand Down Expand Up @@ -90,6 +90,6 @@ You don't have to be a programmer!

For example translations for additional languages would make this app more useful for more earthlings - see: [src/main/resources/Babylon.properties](https://github.com/RetGal/Dayon/blob/master/src/main/resources/Babylon.properties) or [docs](https://github.com/RetGal/Dayon/tree/master/docs)

Also improvements of the existing translations and documentation are very welcome! For example, my current knowledge of Chinese is far below zero - and my knowledge of Russian or Turkish just fractions better..
Also, improvements of the existing translations and documentation are very welcome! For example, my current knowledge of Chinese is far below zero - and my knowledge of Russian or Turkish just fractions better..

Some additional testing, especially on macOS would also be highly appreciated.
67 changes: 33 additions & 34 deletions src/main/java/mpo/dayon/assistant/gui/Assistant.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public class Assistant implements ClipboardOwner {

private Boolean upnpEnabled;

private final AtomicBoolean compatibilityModeActive = new AtomicBoolean(false);

public Assistant() {
receivedBitCounter = new BitCounter("receivedBits", translate("networkBandwidth"));
receivedBitCounter.start(1000);
Expand Down Expand Up @@ -179,6 +181,7 @@ private AssistantActions createAssistantActions() {
assistantActions.setRemoteClipboardSetAction(createRemoteClipboardUpdateAction());
assistantActions.setStartAction(createStartAction());
assistantActions.setStopAction(createStopAction());
assistantActions.setToggleCompatibilityModeAction(createToggleCompatibilityModeAction());
return assistantActions;
}

Expand Down Expand Up @@ -208,7 +211,7 @@ public void actionPerformed(ActionEvent ev) {
frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
publicIp = UPnP.getExternalIP();
if (publicIp == null) {
if (publicIp == null || publicIp.startsWith("192.168") || publicIp.startsWith("10.")) {
final URL url = new URL(WHATSMYIP_SERVER_URL);
try (final BufferedReader lines = new BufferedReader(new InputStreamReader(url.openStream()))) {
publicIp = lines.readLine();
Expand All @@ -223,7 +226,6 @@ public void actionPerformed(ActionEvent ev) {
}
if (publicIp != null) {
button.setText(publicIp);
button.setFont(new Font("Sans Serif", Font.PLAIN, 18));
}
});
choices.add(menuItem);
Expand Down Expand Up @@ -263,8 +265,6 @@ public void actionPerformed(ActionEvent ev) {
choices.setLocation(choicesLocation.x - xOffset, choicesLocation.y + yOffset);
}
};

ip.putValue(Action.NAME, "whatIsMyIpAddress");
ip.putValue("DISPLAY_NAME", "127.0.0.1"); // always a selection
// ...
ip.putValue(Action.SHORT_DESCRIPTION, translate("ipAddress.msg1"));
Expand Down Expand Up @@ -304,7 +304,7 @@ private JMenuItem getJMenuItemCopyIpAndPort(JButton button) {
}

private Action createNetworkAssistantConfigurationAction(Assistant assistant) {
final Action exit = new AbstractAction() {
final Action conf = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent ev) {
JFrame networkFrame = (JFrame) SwingUtilities.getRoot((Component) ev.getSource());
Expand Down Expand Up @@ -347,11 +347,10 @@ public void actionPerformed(ActionEvent ev) {
}
}
};

exit.putValue(Action.NAME, margin(translate("connection.network")));
exit.putValue(Action.SHORT_DESCRIPTION, translate("connection.settings"));
exit.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.NETWORK_SETTINGS));
return exit;
conf.putValue(Action.NAME, margin(translate("connection.network")));
conf.putValue(Action.SHORT_DESCRIPTION, translate("connection.settings"));
conf.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.NETWORK_SETTINGS));
return conf;
}

private Action createRemoteClipboardRequestAction() {
Expand All @@ -361,8 +360,6 @@ public void actionPerformed(ActionEvent ev) {
sendRemoteClipboardRequest();
}
};

getRemoteClipboard.putValue(Action.NAME, "getClipboard");
getRemoteClipboard.putValue(Action.SHORT_DESCRIPTION, translate("clipboard.getRemote"));
getRemoteClipboard.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.DOWN));
return getRemoteClipboard;
Expand All @@ -375,8 +372,6 @@ public void actionPerformed(ActionEvent ev) {
sendLocalClipboard();
}
};

setRemoteClipboard.putValue(Action.NAME, "setClipboard");
setRemoteClipboard.putValue(Action.SHORT_DESCRIPTION, translate("clipboard.setRemote"));
setRemoteClipboard.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.UP));
return setRemoteClipboard;
Expand Down Expand Up @@ -468,13 +463,11 @@ public void actionPerformed(ActionEvent ev) {
if (!newCaptureEngineConfiguration.equals(captureEngineConfiguration)) {
captureEngineConfiguration = newCaptureEngineConfiguration;
captureEngineConfiguration.persist();

sendCaptureConfiguration(captureEngineConfiguration);
}
}
}
};

configure.putValue(Action.NAME, margin(translate("capture")));
configure.putValue(Action.SHORT_DESCRIPTION, translate("capture.settings"));
configure.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.CAPTURE_SETTINGS));
Expand Down Expand Up @@ -565,7 +558,6 @@ public void actionPerformed(ActionEvent ev) {
}
}
};

configure.putValue(Action.NAME, margin(translate("compression")));
configure.putValue(Action.SHORT_DESCRIPTION, translate("compression.settings"));
configure.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.COMPRESSION_SETTINGS));
Expand Down Expand Up @@ -608,8 +600,6 @@ public void actionPerformed(ActionEvent ev) {
sendCaptureConfiguration(captureEngineConfiguration);
}
};

configure.putValue(Action.NAME, "resetCapture");
configure.putValue(Action.SHORT_DESCRIPTION, translate("capture.reset"));
configure.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.RESET_CAPTURE));
return configure;
Expand All @@ -628,8 +618,6 @@ public void actionPerformed(ActionEvent ev) {
frame.repaint();
}
};

fitScreen.putValue(Action.NAME, "toggleScreenMode");
fitScreen.putValue(Action.SHORT_DESCRIPTION, translate("toggle.screen.mode"));
fitScreen.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.FIT));
return fitScreen;
Expand All @@ -650,8 +638,6 @@ public void actionPerformed(ActionEvent ev) {
choices.show(caller, 0, caller.getHeight());
}
};

settings.putValue(Action.NAME, translate("settings"));
settings.putValue(Action.SHORT_DESCRIPTION, translate("settings"));
settings.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.SETTINGS));
return settings;
Expand Down Expand Up @@ -690,8 +676,6 @@ public void actionPerformed(ActionEvent ev) {
clipboard.setContents(value, value);
}
};

tokenAction.putValue(Action.NAME, "createToken");
tokenAction.putValue(Action.SHORT_DESCRIPTION, translate("token.create.msg"));
tokenAction.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.KEY));
return tokenAction;
Expand All @@ -704,7 +688,6 @@ public void actionPerformed(ActionEvent ev) {
new Assistant.NetWorker().execute();
}
};
startAction.putValue(Action.NAME, "start");
startAction.putValue(Action.SHORT_DESCRIPTION, translate("start.session"));
startAction.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.START));
return startAction;
Expand All @@ -718,7 +701,6 @@ public void actionPerformed(ActionEvent ev) {
}
};
stopAction.setEnabled(false);
stopAction.putValue(Action.NAME, "stop");
stopAction.putValue(Action.SHORT_DESCRIPTION, translate("stop.session"));
stopAction.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.STOP));
return stopAction;
Expand Down Expand Up @@ -758,6 +740,19 @@ private void switchLookAndFeel(UIManager.LookAndFeelInfo lnf) {
}
}

private Action createToggleCompatibilityModeAction() {
final Action compatibilityMode = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent ev) {
compatibilityModeActive.set(!compatibilityModeActive.get());
frame.repaint();
}
};
compatibilityMode.putValue(Action.SHORT_DESCRIPTION, translate("compatibility.mode"));
compatibilityMode.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.COMPATIBILITY));
return compatibilityMode;
}

private class NetWorker extends SwingWorker<String, String> {
@Override
protected String doInBackground() {
Expand All @@ -769,7 +764,7 @@ protected String doInBackground() {

private void startNetwork() {
frame.onGettingReady();
network.start();
network.start(compatibilityModeActive.get());
}

@Override
Expand All @@ -788,14 +783,14 @@ protected void done() {

private void initUpnp() {
CompletableFuture.supplyAsync(() -> {
upnpEnabled = Boolean.valueOf(UPnP.isUPnPAvailable());
upnpEnabled = UPnP.isUPnPAvailable();
Log.info(format("UPnP is %s", isUpnpEnabled() ? "enabled" : "disabled"));
return upnpEnabled;
});
}

private String margin(String in) {
return " " + in;
return format(" %s", in);
}

private class MyDeCompressorEngineListener implements DeCompressorEngineListener {
Expand Down Expand Up @@ -879,6 +874,14 @@ public void onConnected(Socket connection) {
frame.onSessionStarted();
}

@Override
public void onFingerprinted(String fingerprints) {
if (null == fingerprints) {
fingerprints = translate("compatibility.mode.enable");
}
frame.setFingerprints(fingerprints);
}

/**
* Should not block as called from the network receiving thread (!)
*/
Expand Down Expand Up @@ -924,9 +927,5 @@ public void onIOError(IOException error) {
frame.onIOError(error);
}

@Override
public void onUntrustedConnection(String fingerprint) {
frame.onUntrustedConnection(fingerprint);
}
}
}
9 changes: 9 additions & 0 deletions src/main/java/mpo/dayon/assistant/gui/AssistantActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AssistantActions {
private Action stopAction;
private Action settingsAction;
private Action tokenAction;
private Action toggleCompatibilityModeAction;

public Action getIpAddressAction() {
return ipAddressAction;
Expand Down Expand Up @@ -112,4 +113,12 @@ public Action getTokenAction() {
public void setTokenAction(Action tokenAction) {
this.tokenAction = tokenAction;
}

public Action getToggleCompatibilityModeAction() {
return toggleCompatibilityModeAction;
}

public void setToggleCompatibilityModeAction(Action toggleCompatibilityModeAction) {
this.toggleCompatibilityModeAction = toggleCompatibilityModeAction;
}
}
14 changes: 5 additions & 9 deletions src/main/java/mpo/dayon/assistant/gui/AssistantFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,15 @@ private ToolBar createToolBar() {
toolbar.addToggleAction(actions.getToggleFitScreenAction());
toolbar.addAction(actions.getResetAction());
toolbar.addSeparator();
toolbar.addToggleAction(actions.getToggleCompatibilityModeAction());
toolbar.addAction(actions.getSettingsAction());
toolbar.addSeparator();
toolbar.addAction(createShowInfoAction());
toolbar.addAction(createShowHelpAction());
toolbar.addSeparator();
toolbar.addAction(actions.getTokenAction());
toolbar.addSeparator();
toolbar.add(toolbar.getMessage());
toolbar.add(toolbar.getFingerprints());
toolbar.addGlue();
toolbar.addAction(actions.getIpAddressAction());
toolbar.addSeparator();
toolbar.addAction(createExitAction());
return toolbar;
}

Expand All @@ -234,7 +231,6 @@ public void actionPerformed(ActionEvent ev) {
windowsKeyToggleButton.setEnabled(controlActivated.get());
}
};
remoteControl.putValue(Action.NAME, "toggleControlMode");
remoteControl.putValue(Action.SHORT_DESCRIPTION, translate("control.mode"));
remoteControl.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.CONTROL));
return remoteControl;
Expand All @@ -252,7 +248,6 @@ public void actionPerformed(ActionEvent ev) {
windowsKeyActivated.set(!windowsKeyActivated.get());
}
};
sendWindowsKey.putValue(Action.NAME, "sendWindowsKey");
sendWindowsKey.putValue(Action.SHORT_DESCRIPTION, translate("send.windowsKey"));
sendWindowsKey.putValue(Action.SMALL_ICON, getOrCreateIcon(ImageNames.WIN));
return sendWindowsKey;
Expand All @@ -265,6 +260,7 @@ void onReady() {
actions.getStartAction().setEnabled(true);
actions.getStopAction().setEnabled(false);
actions.getNetworkConfigurationAction().setEnabled(true);
actions.getToggleCompatibilityModeAction().setEnabled(true);
actions.getIpAddressAction().setEnabled(true);
actions.getCaptureEngineConfigurationAction().setEnabled(true);
actions.getResetAction().setEnabled(false);
Expand All @@ -275,7 +271,9 @@ void onReady() {
void onHttpStarting(int port) {
actions.getStopAction().setEnabled(true);
actions.getNetworkConfigurationAction().setEnabled(false);
actions.getToggleCompatibilityModeAction().setEnabled(false);
actions.getIpAddressAction().setEnabled(false);
toolbar.clearFingerprints();
getStatusBar().setMessage(translate("listening", port));
}

Expand Down Expand Up @@ -333,14 +331,12 @@ void onSessionStarted() {

void onDisconnecting() {
stopSessionTimer();
toolbar.clearMessage();
}

void onIOError(IOException error) {
actions.getStartAction().setEnabled(false);
actions.getStopAction().setEnabled(false);
actions.getResetAction().setEnabled(false);
toolbar.clearMessage();
disableControls();
stopSessionTimer();
hideSpinner();
Expand Down
Loading

0 comments on commit aa85074

Please sign in to comment.