forked from blakey22/shadowsocks-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Support proxy type: Sock5, HTTP (experimental)
2. Improve socket performance 3. Add UI
- Loading branch information
Showing
32 changed files
with
1,470 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.stfl; | ||
|
||
import java.util.Locale; | ||
|
||
public class Constant { | ||
public static final String PROG_NAME = "shadowsocks-java"; | ||
public static final String VERSION = "0.2"; | ||
public static final int BUFFER_SIZE = 16384; | ||
public static final String CONF_FILE = "config.json"; | ||
public static final Locale LOCALE = Locale.getDefault(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package com.stfl; | ||
|
||
import com.stfl.misc.UTF8Control; | ||
import com.stfl.ui.MainLayoutController; | ||
import javafx.application.Application; | ||
import javafx.application.Platform; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.Scene; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.layout.Pane; | ||
import javafx.stage.Stage; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.io.IOException; | ||
import java.util.ResourceBundle; | ||
import java.util.logging.Logger; | ||
|
||
public class MainGui extends Application { | ||
private static Logger logger = Logger.getLogger(MainGui.class.getName()); | ||
private Stage primaryStage; | ||
private Scene rootScene; | ||
private MainLayoutController controller; | ||
private TrayIcon trayIcon; | ||
|
||
@Override | ||
public void start(Stage primaryStage) throws Exception { | ||
|
||
Platform.setImplicitExit(false); | ||
this.primaryStage = primaryStage; | ||
this.primaryStage.setTitle("Server Configuration"); | ||
|
||
try { | ||
// Load the root layout from the fxml file | ||
FXMLLoader mainLayoutLoader = new FXMLLoader(MainGui.class.getResource("/resources/ui/MainLayout.fxml")); | ||
mainLayoutLoader.setResources(ResourceBundle.getBundle("resources.bundle.ui", Constant.LOCALE, new UTF8Control())); | ||
Pane rootLayout = mainLayoutLoader.load(); | ||
|
||
rootScene = new Scene(rootLayout); | ||
primaryStage.setScene(rootScene); | ||
primaryStage.setResizable(false); | ||
|
||
controller = mainLayoutLoader.getController(); | ||
controller.setMainGui(this); | ||
|
||
addToTray(); | ||
|
||
primaryStage.getIcons().add(new Image(MainGui.class.getResource("/resources/image/icon.png").toString())); | ||
primaryStage.show(); | ||
} catch (IOException e) { | ||
// Exception gets thrown if the fxml file could not be loaded | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
|
||
private void addToTray() { | ||
// ensure awt is initialized | ||
java.awt.Toolkit.getDefaultToolkit(); | ||
|
||
// make sure system tray is supported | ||
if (!java.awt.SystemTray.isSupported()) { | ||
logger.warning("No system tray support!"); | ||
} | ||
|
||
final java.awt.SystemTray tray = java.awt.SystemTray.getSystemTray(); | ||
try { | ||
|
||
java.awt.Image image = ImageIO.read(MainGui.class.getResource("/resources/image/icon.png")); | ||
trayIcon = new TrayIcon(image); | ||
trayIcon.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
Platform.runLater(new Runnable() { | ||
@Override | ||
public void run() { | ||
primaryStage.show(); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
java.awt.MenuItem openItem = new java.awt.MenuItem("Configuration"); | ||
openItem.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
Platform.runLater(new Runnable() { | ||
@Override | ||
public void run() { | ||
show(); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
java.awt.MenuItem exitItem = new java.awt.MenuItem("Exit"); | ||
exitItem.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
controller.closeServer(); | ||
Platform.exit(); | ||
tray.remove(trayIcon); | ||
} | ||
}); | ||
|
||
PopupMenu popup = new PopupMenu(); | ||
popup.add(openItem); | ||
popup.addSeparator(); | ||
popup.add(exitItem); | ||
trayIcon.setPopupMenu(popup); | ||
trayIcon.setToolTip("Not Connected"); | ||
tray.add(trayIcon); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} catch (AWTException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void show() { | ||
primaryStage.show(); | ||
} | ||
|
||
public void hide() { | ||
primaryStage.hide(); | ||
} | ||
|
||
public void setTooltip(String message) { | ||
if (trayIcon != null) { | ||
trayIcon.setToolTip(message); | ||
} | ||
} | ||
|
||
public void showNotification(String message) { | ||
trayIcon.displayMessage( | ||
"shadowsocks-java", | ||
message, | ||
java.awt.TrayIcon.MessageType.INFO | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.