use of com.github.mob41.osumer.io.queue.QueueManager in project osumer by mob41.
the class Main method runUi.
private static void runUi(Config config, String[] args, ArgParser ap) {
if (!SockThread.testPortFree(SockThread.PORT)) {
// osumer to work
try {
Socket socket = new Socket(InetAddress.getLoopbackAddress().getHostName(), SockThread.PORT);
socket.setSoTimeout(5000);
PrintWriter writer = new PrintWriter(socket.getOutputStream());
writer.println("RUN " + buildArgStr(args));
writer.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line = reader.readLine();
if (line == null || !line.equals("OK")) {
reader.close();
socket.close();
System.out.println("Not OK: " + line);
DebugDump dump = new DebugDump(null, null, "Asking BG osumer to run with args: \"" + buildArgStr(args) + "\"", null, false, "Could not start up BG osumer sucessfully. Destination did not response \"OK\": " + line);
DumpManager.getInstance().addDump(dump);
ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
dialog.setModal(true);
dialog.setVisible(true);
return;
}
reader.close();
socket.close();
System.exit(0);
return;
} catch (IOException e) {
e.printStackTrace();
DebugDump dump = new DebugDump(null, null, "Opening connection to BG osumer socket", null, "Could not open socket at 46725 for BG call. Not osumer running at that port?", false, e);
DumpManager.getInstance().addDump(dump);
ErrorDumpDialog dialog = new ErrorDumpDialog(dump);
dialog.setModal(true);
dialog.setVisible(true);
System.exit(-1);
return;
}
} else {
String urlStr = null;
for (int i = 0; i < args.length; i++) {
if (Osums.isVaildBeatMapUrl(args[i])) {
urlStr = args[i];
break;
}
}
boolean runUi = true;
if (args.length > 0 && urlStr == null && !ap.isDaemonFlag()) {
if (config.isSwitchToBrowserIfWithoutUiArg()) {
System.out.println("Configuration specified that switch to browser if an \"-ui\" arugment wasn't specified.");
if (runUi = ap.isUiFlag() && !ap.isNoUiFlag()) {
System.out.println("An \"-ui\" argument was specified. Launching UI.");
} else {
System.out.println("An \"-ui\" argument wasn't specified. Opening the default browser instead.");
runBrowser(config, args);
return;
}
} else {
System.out.println("Non-beatmap URL detected.");
if (!config.isAutoSwitchBrowser()) {
System.out.println("Auto switch to default browser is off. Nothing to do with such URL.");
return;
} else {
System.out.println("Switching to default browser with the URL.");
runBrowser(config, args);
}
}
}
// Initialize JFX toolkit
new JFXPanel();
TrayIcon icon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(UIFrame.class.getResource("/com/github/mob41/osumer/ui/osumerIcon_16px.png")));
UIFrame frame = new UIFrame(config, new QueueManager(config), icon);
if (ap.isDaemonFlag()) {
if (!SystemTray.isSupported()) {
JOptionPane.showMessageDialog(null, "Your operating system does not support System Tray.\nAs a result, you are not able to start osumer from the tray.", "Warning", JOptionPane.WARNING_MESSAGE);
return;
}
frame.setDaemonMode(true);
SystemTray tray = SystemTray.getSystemTray();
icon.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
frame.setVisible(!frame.isVisible());
if (!frame.isVisible()) {
icon.displayMessage("osumer2", "osumer2 is now running in background.", TrayIcon.MessageType.INFO);
}
}
});
icon.setToolTip("osumer2");
try {
tray.add(icon);
icon.displayMessage("osumer2", "osumer2 is now running in background.", TrayIcon.MessageType.INFO);
} catch (AWTException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Error when adding tray icon: " + e + "\nAs a result, you are not able to start osumer from the tray.", "Warning", JOptionPane.WARNING_MESSAGE);
return;
}
} else {
frame.setVisible(true);
new Thread() {
public void run() {
JOptionPane.showMessageDialog(frame, "The osumer2 daemon (background process) is not running.\nThis might slow down further osumerExpress downloads.\nNow this process is listening for more queues till it is stopped.\n\nPlease check \"Help\" for more details.", "Warning", JOptionPane.WARNING_MESSAGE);
}
}.start();
}
if (urlStr != null) {
frame.addBtQueue(urlStr, false);
}
}
}
Aggregations