Skip to content

Commit

Permalink
trying to better catch url opening issues
Browse files Browse the repository at this point in the history
  • Loading branch information
benfry committed Sep 11, 2016
1 parent 0c85d78 commit 405b642
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/processing/mode/p5js/p5jsEditor.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package processing.mode.p5js;

import java.awt.Desktop;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;

import javax.swing.JMenu;
Expand Down Expand Up @@ -284,7 +286,13 @@ public void handleRun() {
restartServer();
}
statusNotice("Server running at " + server.getAddress());
Platform.openURL(server.getAddress());
//Platform.openURL(server.getAddress());

try {
Desktop.getDesktop().browse(new URI(server.getAddress()));
} catch (Exception e) {
statusError(e);
}
}
}

Expand Down Expand Up @@ -394,9 +402,9 @@ public void run() {


/**
* Start the internal server for this sketch.
* @param root the root folder for the server to serve from
* @return true if it was started anew, false if it was running
* Start the internal server for this sketch.
* @param root the root folder for the server to serve from
* @return true if it was started anew, false if it was running
*/
protected void restartServer() {
if (server != null && server.isDead()) {
Expand Down
7 changes: 5 additions & 2 deletions src/processing/mode/p5js/server/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ public class HttpServer {

public HttpServer(p5jsEditor editor) {
this(editor, (int) (8000 + Math.random() * 1000));
//root = editor.getSketch().getFolder();
}


public HttpServer(p5jsEditor editor, final int port) {
public HttpServer(p5jsEditor editor, int port) {
this.editor = editor;
this.port = port;

Expand Down Expand Up @@ -83,7 +82,11 @@ public void run() {
running = true;
ServerSocket socket = null;
try {
// try {
socket = new ServerSocket(port);
// } catch (BindException be) {
// // socket already in use; try another
// }
while (Thread.currentThread() == thread) {
@SuppressWarnings("resource")
Socket s = socket.accept();
Expand Down

0 comments on commit 405b642

Please sign in to comment.