Prevents the browser from locking on shutdown if the browser ran into a startup error.

This commit is contained in:
Markil3
2021-09-15 09:35:16 -06:00
parent f7370ba08a
commit f8be50af9d
3 changed files with 20 additions and 4 deletions

View File

@@ -69,6 +69,7 @@ public class Browser extends MessageRunner
logger.error(scanner.nextLine()); logger.error(scanner.nextLine());
} }
} }
notifyAllInstance();
throw new IOException("Error in browser launch (exit code " + startExit + ")"); throw new IOException("Error in browser launch (exit code " + startExit + ")");
} }
} }
@@ -157,6 +158,14 @@ public class Browser extends MessageRunner
} }
} }
/**
*
*/
public void stop()
{
this.running = false;
}
/** /**
* Utility method for launching a browser instance * Utility method for launching a browser instance
* *

View File

@@ -46,6 +46,7 @@ public class PlayerEnvironment
*/ */
public static void main(String[] args) public static void main(String[] args)
{ {
logger.info("MAIN FOREVER");
LinkedHashMap<String, Object> ops = new LinkedHashMap<>(); LinkedHashMap<String, Object> ops = new LinkedHashMap<>();
ArrayList<String> params = new ArrayList<>(); ArrayList<String> params = new ArrayList<>();
parseArgs(args, ops, params); parseArgs(args, ops, params);

View File

@@ -33,6 +33,7 @@ public class BrowserPlayer implements Player<InternetSong>, UpdateListener
.getLogger(BrowserPlayer.class); .getLogger(BrowserPlayer.class);
private final LinkedList<PlaybackListener> listeners = new LinkedList<>(); private final LinkedList<PlaybackListener> listeners = new LinkedList<>();
private boolean error = false;
private InternetSong currentSong; private InternetSong currentSong;
@@ -40,9 +41,9 @@ public class BrowserPlayer implements Player<InternetSong>, UpdateListener
private Browser getBrowser() private Browser getBrowser()
{ {
if (browserRef == null) if (browserRef == null && !this.error)
{ {
while (Browser.getInstance() == null) if (Browser.getInstance() == null)
{ {
try try
{ {
@@ -53,8 +54,11 @@ public class BrowserPlayer implements Player<InternetSong>, UpdateListener
logger.error("Interrupted while waiting for browser to initialize.", e); logger.error("Interrupted while waiting for browser to initialize.", e);
} }
} }
Browser.getInstance().addUpdateListener(this); if (Browser.getInstance() != null)
browserRef = Browser.getInstance(); {
Browser.getInstance().addUpdateListener(this);
browserRef = Browser.getInstance();
}
} }
return browserRef; return browserRef;
} }
@@ -70,6 +74,8 @@ public class BrowserPlayer implements Player<InternetSong>, UpdateListener
catch (IOException | InterruptedException e) catch (IOException | InterruptedException e)
{ {
logger.error("Could not initialize browser", e); logger.error("Could not initialize browser", e);
this.error = true;
Browser.notifyAllInstance();
} }
}); });
browserThread.start(); browserThread.start();