Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
subhra74 committed Mar 28, 2024
1 parent 70e5f94 commit 82b2f1d
Show file tree
Hide file tree
Showing 37 changed files with 1,506 additions and 293 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/muon/AppContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import muon.dto.session.SavedSessionTree;
import muon.exceptions.AuthenticationException;
import muon.service.FileIconService;
import muon.service.SessionMetaDataStoreService;
import muon.service.SessionStore;

public class AppContext {
public static final FileIconService ICONS = new FileIconService();
public static final SessionMetaDataStoreService META_DATA_STORE_SERVICE = new SessionMetaDataStoreService();
public static SavedSessionTree sessionTree;
public static String password = "";

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/muon/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
public class AppConfig {
public static final String CONFIG_DIR = System.getProperty("user.home") + File.separatorChar + "muon-ssh";
public static final String SESSION_DB_FILE = "session-store.db";
public static final String SESSION_META_FILE = "session-meta.properties";

}
28 changes: 28 additions & 0 deletions app/src/main/java/muon/dto/session/SessionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class SessionInfo extends NamedItem {
private List<PortForwardingRule> portForwardingRules = new ArrayList<>();
private transient String lastPassword;
private String password;
private transient String osName;
private transient String osType;
private transient Boolean shellAccess;

public int getAuthMode() {
return authMode;
Expand Down Expand Up @@ -328,4 +331,29 @@ public String getLastPassword() {
public void setLastPassword(String lastPassword) {
this.lastPassword = lastPassword;
}

public String getOsName() {
return osName;
}

public void setOsName(String osName) {
this.osName = osName;
}

public String getOsType() {
return osType;
}

public void setOsType(String osType) {
this.osType = osType;
}

public Boolean getShellAccess() {
return shellAccess;
}

public void setShellAccess(Boolean shellAccess) {
this.shellAccess = shellAccess;
}

}
39 changes: 39 additions & 0 deletions app/src/main/java/muon/misc/CancellationToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package muon.misc;

import muon.util.AppUtils;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;

public class CancellationToken implements AutoCloseable {
private CountDownLatch countDownLatch = new CountDownLatch(1);
private AtomicBoolean cancellationRequested = new AtomicBoolean(false);
private AtomicBoolean closed = new AtomicBoolean(false);

public void await() {
AppUtils.await(countDownLatch);
}

public void requestCancellation() {
if (closed.get()) {
return;
}
cancellationRequested.set(true);
countDownLatch.countDown();
}

public boolean isCancellationRequested() {
return cancellationRequested.get();
}

@Override
public void close() throws Exception {
if (closed.get()) {
return;
}
if (countDownLatch.getCount() == 1) {
countDownLatch.countDown();
}
closed.set(true);
}
}
72 changes: 72 additions & 0 deletions app/src/main/java/muon/misc/ExtendedRemoteDirectory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
*
*/
package muon.misc;

import net.schmizz.sshj.sftp.*;
import net.schmizz.sshj.sftp.Response.StatusCode;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
* @author subhro
*/
public class ExtendedRemoteDirectory extends RemoteDirectory {

/**
* @param requester
* @param path
* @param handle
*/
public ExtendedRemoteDirectory(SFTPEngine requester, String path,
byte[] handle) {
super(requester, path, handle);
}

public List<RemoteResourceInfoWrapper> scanExtended(
CancellationToken cancellationToken) throws IOException {
List<RemoteResourceInfoWrapper> rri = new ArrayList<>();
// TODO: Remove GOTO!
loop:
for (; ; ) {
if (cancellationToken.isCancellationRequested()) {
throw new IOException("Operation cancelled");
}
final Response res = requester
.request(newRequest(PacketType.READDIR))
.retrieve(requester.getTimeoutMs(), TimeUnit.MILLISECONDS);
switch (res.getType()) {

case NAME:
final int count = res.readUInt32AsInt();
for (int i = 0; i < count; i++) {
final String name = res.readString(
requester.getSubsystem().getRemoteCharset());
final String longName = res.readString();

final FileAttributes attrs = res.readFileAttributes();
final PathComponents comps = requester.getPathHelper()
.getComponents(path, name);
final RemoteResourceInfo inf = new RemoteResourceInfo(comps,
attrs);
final RemoteResourceInfoWrapper wri = new RemoteResourceInfoWrapper(
inf, longName);
rri.add(wri);
}
break;

case STATUS:
res.ensureStatusIs(StatusCode.EOF);
break loop;

default:
throw new SFTPException("Unexpected packet: " + res.getType());
}
}
return rri;
}

}
53 changes: 53 additions & 0 deletions app/src/main/java/muon/misc/RemoteResourceInfoWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
*
*/
package muon.misc;

import net.schmizz.sshj.sftp.RemoteResourceInfo;

/**
* @author subhro
*
*/
public class RemoteResourceInfoWrapper {
/**
* @param info
* @param longPath
*/
public RemoteResourceInfoWrapper(RemoteResourceInfo info, String longPath) {
super();
this.info = info;
this.longPath = longPath;
}

private RemoteResourceInfo info;
private String longPath;

/**
* @return the info
*/
public RemoteResourceInfo getInfo() {
return info;
}

/**
* @param info the info to set
*/
public void setInfo(RemoteResourceInfo info) {
this.info = info;
}

/**
* @return the longPath
*/
public String getLongPath() {
return longPath;
}

/**
* @param longPath the longPath to set
*/
public void setLongPath(String longPath) {
this.longPath = longPath;
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/muon/screens/appwin/AppWin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package muon.screens.appwin;

import muon.dto.session.SessionInfo;

import java.awt.*;
import java.awt.event.ActionListener;

Expand All @@ -11,4 +13,6 @@ public interface AppWin {
void setProgress(int progress, String title, String status);

void unblockInput();

void openTerminal(String command, SessionInfo sessionInfo);
}
10 changes: 9 additions & 1 deletion app/src/main/java/muon/screens/appwin/MainContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.formdev.flatlaf.extras.FlatSVGIcon;
import muon.AppContext;
import muon.dto.session.SessionInfo;
import muon.exceptions.AuthenticationException;
import muon.screens.appwin.filebrowser.DualPaneFileBrowser;
import muon.screens.appwin.terminal.TabbedTerminal;
Expand All @@ -24,6 +25,7 @@ public class MainContainer extends JPanel implements AppWin {
private JPasswordField txtPassword;
private JButton btnPassword;
private Container defaultComponentHolder;
private JTabbedPane tabs;

private ImageIcon createIcon(String name, int size) {
FlatSVGIcon.ColorFilter filter = new FlatSVGIcon.ColorFilter();
Expand All @@ -44,7 +46,7 @@ public MainContainer() {
setBorder(new MatteBorder(1, 0, 0, 0, UIManager.getColor("TableHeader.bottomSeparatorColor")));
}
//setBorder(new EmptyBorder(30, 0, 0, 0));
var tabs = new JTabbedPane();
tabs = new JTabbedPane();
tabs.setTabPlacement(JTabbedPane.BOTTOM);
// tabs.putClientProperty("JTabbedPane.tabRotation", "left");
//tabs.putClientProperty("JTabbedPane.tabType", "card");
Expand Down Expand Up @@ -226,4 +228,10 @@ public void unblockInput() {
this.defaultComponentHolder.removeAll();
((CardLayout) this.getLayout()).show(this, "CONTENT");
}

@Override
public void openTerminal(String command, SessionInfo sessionInfo) {
tabbedTerminal.createNewTab(command, sessionInfo);
tabs.setSelectedIndex(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public abstract class AbstractFileBrowserView extends JPanel {
private FolderViewRowFilter folderViewRowFilter;
private JToolBar panFilter;

public AbstractFileBrowserView(FileBrowserViewParent parent) {
public AbstractFileBrowserView(FileBrowserViewParent parent, String path) {
super(new CardLayout());
this.parent = parent;

this.history = new NavigationHistory();
this.popup = new JPopupMenu();


createContentPanel();
createContentPanel(path);
this.add(contentPanel, "CONTENT");

installMouseListener(table);
Expand Down Expand Up @@ -89,7 +89,7 @@ private void onCancel() {

public abstract void preparePopup();

private JToolBar createToolbar() {
private JToolBar createToolbar(String path) {
var toolbar = new JToolBar();
toolbar.setBackground(UIManager.getColor("TextArea.background"));

Expand Down Expand Up @@ -127,7 +127,7 @@ private JToolBar createToolbar() {
//txtAddress.setForeground(UIManager.getColor("Label.disabledForeground"));
txtAddress.setBorder(new EmptyBorder(0, 5, 0, 0));
//txtAddress.setBackground(UIManager.getColor("TabbedPane.background"));
txtAddress.setText("");
txtAddress.setText(path);
txtAddress.addActionListener(e -> {
navigate(txtAddress.getText());
});
Expand Down Expand Up @@ -169,11 +169,11 @@ private void createSearchPanel() {
this.add(searchPanel, "SEARCH");
}

private void createContentPanel() {
private void createContentPanel(String path) {

//UIManager.put("TableHeader.showTrailingVerticalLine", true);
//var c1 = AppTheme.INSTANCE.getBackground();
var toolbar = createToolbar();
var toolbar = createToolbar(path);
folderViewTableModel = new FolderViewTableModel(true);
table = new JTable(folderViewTableModel);
table.putClientProperty("isFileList", Boolean.TRUE);
Expand Down Expand Up @@ -411,13 +411,16 @@ private void render(String path, java.util.List<FileInfo> result) {
folderViewTableModel.addAll(result);
}

protected abstract void cancelOperation();

public void navigate() {
navigate(txtAddress.getText());
}

protected void navigate(final String path) {
System.out.println("Navigating to: " + path);
App.getAppWindow().blockInput(true, "Please wait", "", e -> {
cancelOperation();
});
AppUtils.runAsync(() -> {
try {
Expand Down Expand Up @@ -581,10 +584,12 @@ public FileBrowserViewParent getParentView() {
return parent;
}

protected abstract List<String> getPinnedLocations();

protected JPopupMenu createPopupMenu() {
var mShowHiddenFiles = new JCheckBoxMenuItem("Show hidden files");
var mShowFilterPanel = new JCheckBoxMenuItem("Show filter");
var mBookmarks = new JCheckBoxMenuItem("Pinned locations");
var mBookmarks = new JMenu("Pinned locations");

mShowHiddenFiles.addActionListener(e -> {
this.folderViewRowFilter.setShowHiddenFiles(!this.folderViewRowFilter.isShowHiddenFiles());
Expand All @@ -605,6 +610,15 @@ protected JPopupMenu createPopupMenu() {
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
mShowFilterPanel.setSelected(panFilter != null && panFilter.isVisible());
mShowHiddenFiles.setSelected(folderViewRowFilter.isShowHiddenFiles());
var locations = getPinnedLocations();
mBookmarks.removeAll();
for (var location :
locations) {
var menuItem = new JMenuItem(location);
menuItem.putClientProperty("location.path", location);
menuItem.addActionListener(a -> navigate((String) menuItem.getClientProperty("location.path")));
mBookmarks.add(menuItem);
}
}

@Override
Expand Down
Loading

0 comments on commit 82b2f1d

Please sign in to comment.