Skip to content

Commit

Permalink
fixed reconnect issue
Browse files Browse the repository at this point in the history
  • Loading branch information
subhra74 committed Jun 10, 2020
1 parent 85c2c65 commit 749d1f8
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 53 deletions.
9 changes: 5 additions & 4 deletions muon-app/src/main/java/muon/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ public class App {
public static GraphicalHostKeyVerifier HOST_KEY_VERIFIER;

public static void main(String[] args) throws UnsupportedLookAndFeelException {
Security.setProperty("networkaddress.cache.ttl", "0");
Security.setProperty("networkaddress.cache.negative.ttl", "0");

Security.setProperty("crypto.policy", "unlimited");


Security.addProvider(new BouncyCastleProvider());

Security.setProperty("networkaddress.cache.ttl", "1");
Security.setProperty("networkaddress.cache.negative.ttl", "1");
Security.setProperty("crypto.policy", "unlimited");

System.out.println(System.getProperty("java.version"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public GraphicalInputBlocker(JFrame window) {
super(window);
this.window = window;
setModal(true);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setSize(400, 300);
}

Expand Down
1 change: 1 addition & 0 deletions muon-app/src/main/java/muon/app/ssh/SshFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public SFTPClient getSftp() throws Exception {

private void ensureConnected() throws Exception {
if (closed.get()) {
this.ssh.close();
throw new OperationCancelledException();
}
if (!ssh.isConnected()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public SessionContentPanel(SessionInfo info) {
this.pfSession.start();
}
}

public void reconnect() {
this.remoteSessionInstance.close();
this.remoteSessionInstance = new RemoteSessionInstance(info, App.getInputBlocker(), this);
}

@Override
public void showPage(String pageId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ private JPanel createConnectionPanel() {
lblHost.setHorizontalAlignment(JLabel.LEADING);
lblPort = new JLabel("Port");
lblUser = new JLabel("User");
lblPass = new JLabel("Password" + " ( Warning: it will be saved in plain text! )");
lblPass = new JLabel("Password");
lblLocalFolder = new JLabel("Local folder");
lblRemoteFolder = new JLabel("Remote folder");
lblKeyFile = new JLabel("Private key file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ public void actionPerformed(ActionEvent e) {

add(toolBar, BorderLayout.NORTH);

folderView = new FolderView(this);
folderView = new FolderView(this, text -> {
this.fileBrowser.updateRemoteStatus(text);
});

this.overflowMenuHandler.setFolderView(folderView);

Expand All @@ -191,7 +193,7 @@ public void actionPerformed(ActionEvent e) {
updateNavButtons();

this.fileBrowser.registerForViewNotification(this);

// setBorder(new LineBorder(App.SKIN.getDefaultBorderColor(), 1));

}
Expand Down Expand Up @@ -282,4 +284,8 @@ public void refreshViewMode() {
this.repaint();
}

public FileBrowser getFileBrowser() {
return this.fileBrowser;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class FileBrowser extends Page {
private JPopupMenu popup;
private boolean leftPopup = false;
private List<AbstractFileBrowserView> viewList = new ArrayList<>();
private JLabel lblStat1;
private Box statusBox;

public FileBrowser(SessionInfo info, SessionContentPanel holder, JRootPane rootPane, int activeSessionId) {
this.activeSessionId = activeSessionId;
Expand Down Expand Up @@ -142,29 +144,29 @@ public FileBrowser(SessionInfo info, SessionContentPanel holder, JRootPane rootP
switchToSinglePanelMode();
}

Box box = Box.createHorizontalBox();
box.setOpaque(true);

JCheckBox chk1 = new JCheckBox();
chk1.setText("Dual pane view");
chk1.setRolloverEnabled(false);
chk1.setSelected(App.getGlobalSettings().isDualPaneMode());
chk1.setSelectedIcon(new FontAwesomeIcon(FontAwesomeContants.FA_TOGGLE_ON, 16, 16));
chk1.setIcon(new FontAwesomeIcon(FontAwesomeContants.FA_TOGGLE_OFF, 16, 16));
chk1.setIconTextGap(10);

chk1.addActionListener(e -> {
if (chk1.isSelected()) {
System.out.println("going dual panel mode");
switchToDualPaneMode();
App.getGlobalSettings().setDualPaneMode(true);
} else {
System.out.println("going single panel mode");
switchToSinglePanelMode();
App.getGlobalSettings().setDualPaneMode(false);
}
App.saveSettings();
});
// statusBox = Box.createHorizontalBox();
// statusBox.setOpaque(true);
//
// JCheckBox chk1 = new JCheckBox();
// chk1.setText("Dual pane view");
// chk1.setRolloverEnabled(false);
// chk1.setSelected(App.getGlobalSettings().isDualPaneMode());
// chk1.setSelectedIcon(new FontAwesomeIcon(FontAwesomeContants.FA_TOGGLE_ON, 16, 16));
// chk1.setIcon(new FontAwesomeIcon(FontAwesomeContants.FA_TOGGLE_OFF, 16, 16));
// chk1.setIconTextGap(10);
//
// chk1.addActionListener(e -> {
// if (chk1.isSelected()) {
// System.out.println("going dual panel mode");
// switchToDualPaneMode();
// App.getGlobalSettings().setDualPaneMode(true);
// } else {
// System.out.println("going single panel mode");
// switchToSinglePanelMode();
// App.getGlobalSettings().setDualPaneMode(false);
// }
// App.saveSettings();
// });

// JCheckBox chk2 = new JCheckBox();
// chk2.setText("List view");
Expand All @@ -187,16 +189,19 @@ public FileBrowser(SessionInfo info, SessionContentPanel holder, JRootPane rootP
// App.saveSettings();
// });

box.setBackground(App.SKIN.getTableBackgroundColor());
box.setBorder(new CompoundBorder(new MatteBorder(1, 0, 0, 0, App.SKIN.getDefaultBorderColor()),
new EmptyBorder(5, 10, 5, 5)));
// box.setBorder(new EmptyBorder(5, 10, 5, 5));
// box.add(Box.createRigidArea(new Dimension(10, 24)));

box.add(chk1);
//box.add(chk2);

this.add(box, BorderLayout.SOUTH);
// statusBox.setBackground(App.SKIN.getTableBackgroundColor());
// statusBox.setBorder(new CompoundBorder(new MatteBorder(1, 0, 0, 0, App.SKIN.getDefaultBorderColor()),
// new EmptyBorder(5, 10, 5, 5)));
// // box.setBorder(new EmptyBorder(5, 10, 5, 5));
// // box.add(Box.createRigidArea(new Dimension(10, 24)));
//
// statusBox.add(chk1);
// statusBox.add(Box.createHorizontalGlue());
// this.lblStat1 = new JLabel();
// // box.add(chk2);
// statusBox.add(lblStat1);
// statusBox.add(Box.createRigidArea(new Dimension(10, 5)));
// this.add(statusBox, BorderLayout.SOUTH);

// leftDropdown.addActionListener(e -> {
// System.out.println("Left drop down changed");
Expand Down Expand Up @@ -672,10 +677,10 @@ public boolean handleLocalDrop(DndTransferData transferData, SessionInfo info, F
System.out.println("Dropped: " + transferData);
int sessionHashCode = transferData.getInfo();
if (sessionHashCode == 0) {
System.out.println("Session hash code: "+sessionHashCode);
System.out.println("Session hash code: " + sessionHashCode);
return true;
}

if (info != null && info.hashCode() == sessionHashCode) {
if (holder.transferMode == TransferMode.Background) {
this.getHolder().downloadInBackground(transferData.getFiles(), currentPath, holder.conflictAction);
Expand Down Expand Up @@ -711,4 +716,16 @@ public void registerForViewNotification(AbstractFileBrowserView view) {
public void unRegisterForViewNotification(AbstractFileBrowserView view) {
this.viewList.remove(view);
}

public void updateLocalStatus(String text) {
// this.lblStat1.setText(text);
// this.statusBox.revalidate();
// this.statusBox.repaint(0);
}

public void updateRemoteStatus(String text) {
// this.lblStat1.setText(text);
// this.statusBox.revalidate();
// this.statusBox.repaint(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public void render(String path) {
SwingUtilities.invokeLater(() -> {
addressBar.setText(this.path);
folderView.setItems(list);
int tc = list.size();
String text = String.format("Total %d remote file(s)", tc);
fileBrowser.updateRemoteStatus(text);
tabTitle.getCallback().accept(PathUtils.getFileName(this.path));
});
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ private void renderDirectory(final String path, final boolean fromCache) throws
addressBar.setText(path);
folderView.setItems(list2);
tabTitle.getCallback().accept(PathUtils.getFileName(path));
int tc = list2.size();
String text = String.format("Total %d remote file(s)", tc);
fileBrowser.updateRemoteStatus(text);
});
}
}
Expand Down Expand Up @@ -179,6 +182,8 @@ public void render(String path, boolean useCache) {
return;
}
System.out.println("Exception caught in sftp file browser: " + e.getMessage());

this.fileBrowser.getHolder().reconnect();

e.printStackTrace();
if (JOptionPane.showConfirmDialog(null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;

public class FolderView extends JPanel {
// private DefaultListModel<FileInfo> listModel;
Expand All @@ -40,7 +41,7 @@ public class FolderView extends JPanel {
private List<FileInfo> files;
private TableRowSorter<? extends Object> sorter;

public FolderView(FolderViewEventListener listener) {
public FolderView(FolderViewEventListener listener, Consumer<String> statusCallback) {
super(new BorderLayout());
this.listener = listener;
this.popup = new JPopupMenu();
Expand Down Expand Up @@ -333,6 +334,17 @@ public void actionPerformed(ActionEvent ae) {
}
});

table.getSelectionModel().addListSelectionListener(e -> {
if (e.getValueIsAdjusting()) {
return;
}
int rc = table.getSelectedRowCount();
int tc = table.getRowCount();

String text = String.format("%d of %d selected", rc, tc);
statusCallback.accept(text);
});

table.addKeyListener(new FolderViewKeyHandler(table, folderViewModel));

table.addMouseListener(new MouseAdapter() {
Expand Down Expand Up @@ -494,6 +506,13 @@ public void mousePressed(MouseEvent e) {
});

refreshViewMode();

// table.getModel().addTableModelListener(e -> {
// int rc = table.getSelectedRowCount();
// int tc = table.getRowCount();
// String text = String.format("Total %d file(s)", tc);
// statusCallback.accept(text);
// });
}

private void selectRow(MouseEvent e) {
Expand Down
23 changes: 23 additions & 0 deletions muon-app/src/main/java/util/PlatformUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,29 @@ public static List<EditorEntry> getKnownEditors() {
}
}

} else if (App.IS_MAC) {
Map<String, String> knownEditorMap = new CollectionHelper.Dict<String, String>().putItem(
"Visual Studio Code", "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code");
for (String key : knownEditorMap.keySet()) {
File file = new File(knownEditorMap.get(key));
if (file.exists()) {
EditorEntry ent = new EditorEntry(key, file.getAbsolutePath());
list.add(ent);
}
}

} else {
Map<String, String> knownEditorMap = new CollectionHelper.Dict<String, String>()
.putItem("Visual Studio Code", "/usr/bin/code").putItem("Atom", "/usr/bin/atom")
.putItem("Sublime Text", "/usr/bin/subl").putItem("Gedit", "/usr/bin/gedit")
.putItem("Kate", "/usr/bin/kate");
for (String key : knownEditorMap.keySet()) {
File file = new File(knownEditorMap.get(key));
if (file.exists()) {
EditorEntry ent = new EditorEntry(key, file.getAbsolutePath());
list.add(ent);
}
}
}
return list;
}
Expand Down
Loading

0 comments on commit 749d1f8

Please sign in to comment.