diff --git a/src/main/java/mpo/dayon/assistant/gui/Assistant.java b/src/main/java/mpo/dayon/assistant/gui/Assistant.java index 224821a1..1467deca 100644 --- a/src/main/java/mpo/dayon/assistant/gui/Assistant.java +++ b/src/main/java/mpo/dayon/assistant/gui/Assistant.java @@ -149,7 +149,7 @@ public Assistant(String tokenServerUrl, String language) { private void initGui() { createCounters(); if (frame != null) { - frame.setVisible(false); + frame.dispose(); } frame = new AssistantFrame(createAssistantActions(), counters, createLanguageSelection(), compatibilityModeActive.get(), this); FatalErrorHandler.attachFrame(frame); @@ -191,6 +191,14 @@ private AssistantActions createAssistantActions() { return assistantActions; } + public void clearToken() { + token = null; + JButton button = (JButton) frame.getActions().getTokenAction().getValue("button"); + if (button != null) { + button.setText(""); + } + } + private void stopNetwork() { frame.hideSpinner(); networkEngine.cancel(); @@ -549,6 +557,7 @@ private Action createTokenAction() { @Override public void actionPerformed(ActionEvent ev) { final JButton button = (JButton) ev.getSource(); + this.putValue("button", button); if (token == null) { CompletableFuture.supplyAsync(() -> { diff --git a/src/main/java/mpo/dayon/assistant/gui/AssistantFrame.java b/src/main/java/mpo/dayon/assistant/gui/AssistantFrame.java index 69949580..a39c1e6e 100644 --- a/src/main/java/mpo/dayon/assistant/gui/AssistantFrame.java +++ b/src/main/java/mpo/dayon/assistant/gui/AssistantFrame.java @@ -66,6 +66,8 @@ class AssistantFrame extends BaseFrame { private final JButton screenshotButton; + private final JButton tokenButton; + private final AtomicBoolean controlActivated = new AtomicBoolean(false); private final AtomicBoolean windowsKeyActivated = new AtomicBoolean(false); @@ -97,6 +99,7 @@ class AssistantFrame extends BaseFrame { this.actions.setNetworkConfigurationAction(createConnectionSettingsAction(assistant)); this.startButton = createButton(actions.getStartAction()); this.stopButton = createButton(actions.getStopAction(), false); + this.tokenButton = createTokenButton(actions.getTokenAction()); this.compatibilityToggleButton = createToggleButton(actions.getToggleCompatibilityModeAction(), true, compatibilityModeActive); this.controlToggleButton = createToggleButton(createToggleControlMode()); this.fitToScreenToggleButton = createToggleButton(createToggleFixScreenAction()); @@ -118,6 +121,10 @@ class AssistantFrame extends BaseFrame { onReady(); } + public AssistantActions getActions() { + return actions; + } + private void addListeners() { addFocusListener(); addKeyListeners(); @@ -248,7 +255,7 @@ private JTabbedPane createTabbedPane() { connectionPanel.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0)); connectionPanel.add(startButton); connectionPanel.add(stopButton); - connectionPanel.add(createTokenButton(actions.getTokenAction())); + connectionPanel.add(tokenButton); connectionPanel.add(createButton(actions.getIpAddressAction())); connectionPanel.add(compatibilityToggleButton); @@ -280,7 +287,7 @@ private JTabbedPane createTabbedPane() { return tabbedPane; } - private static Component createTokenButton(Action tokenAction) { + private static JButton createTokenButton(Action tokenAction) { String token = (String) tokenAction.getValue("token"); JButton button = createButton(tokenAction); if (token != null) { diff --git a/src/main/java/mpo/dayon/common/gui/common/BaseFrame.java b/src/main/java/mpo/dayon/common/gui/common/BaseFrame.java index ca1ca40f..7ecb253f 100644 --- a/src/main/java/mpo/dayon/common/gui/common/BaseFrame.java +++ b/src/main/java/mpo/dayon/common/gui/common/BaseFrame.java @@ -299,7 +299,7 @@ public void actionPerformed(ActionEvent ev) { if (assistant == null) { updateAssistedNetworkConfiguration(addressTextField, portNumberTextField, autoConnectCheckBox, newTokenServerUrl); } else { - updateAssistantNetworkConfiguration(portNumberTextField, newTokenServerUrl, assistant.getNetworkEngine()); + updateAssistantNetworkConfiguration(portNumberTextField, newTokenServerUrl, assistant); } } } @@ -438,7 +438,7 @@ private static void updateAssistedNetworkConfiguration(JTextField addressTextFie } } - private static void updateAssistantNetworkConfiguration(JTextField portNumberTextField, String newTokenServerUrl, NetworkAssistantEngine networkEngine) { + private static void updateAssistantNetworkConfiguration(JTextField portNumberTextField, String newTokenServerUrl, Assistant assistant) { final NetworkAssistantEngineConfiguration newNetworkConfiguration = new NetworkAssistantEngineConfiguration( Integer.parseInt(portNumberTextField.getText()), newTokenServerUrl); @@ -446,7 +446,8 @@ private static void updateAssistantNetworkConfiguration(JTextField portNumberTex if (!newNetworkConfiguration.equals(networkConfiguration)) { NetworkAssistantEngine.manageRouterPorts(networkConfiguration.getPort(), newNetworkConfiguration.getPort()); newNetworkConfiguration.persist(); - networkEngine.reconfigure(newNetworkConfiguration); + assistant.getNetworkEngine().reconfigure(newNetworkConfiguration); + assistant.clearToken(); } }