Feature - Implemented "relay" CLI command should not attempt to launch a browser window when headless

bleary

Member
"relay" CLI command should not attempt to launch a browser window when headless

I think this patch ought to achieve the intended result.

Code:
--- RelayLoader.java    (revision 10904)
+++ RelayLoader.java    (working copy)
@@ -46,6 +46,8 @@

 import net.sourceforge.kolmafia.utilities.PauseObject;

+import net.sourceforge.kolmafia.StaticEntity;
+
 public class RelayLoader
        extends Thread
 {
@@ -124,7 +126,8 @@
                                pauser.pause( 200 );
                        }

-                       BrowserLauncher.openURL( "http://127.0.0.1:" + RelayServer.getPort() + this.location );
+                       if (!StaticEntity.isHeadless())
+                           BrowserLauncher.openURL( "http://127.0.0.1:" + RelayServer.getPort() + this.location );
                }
                else
                {
 

Theraze

Active member
Doesn't it make sense that, even if headless, if you wanted to run the relay browser through your script, it should be possible? If you don't want to launch the relay browser while headless, don't call it...
 

fronobulax

Developer
Staff member
I'm with Theraze. If you are headless you are presumably running a script and so you should have the ability to not launch the browser if that is what you want. If KoLmafia is automagically launching the browser during circumstances not under your script's control then that should be addressed but you have not really described a situation I recognize as something to be addressed in KoLmafia.
 

bleary

Member
I might be an edge case. Sometimes I ssh into my home computer, and launch mafia from the command line with "-Djava.awt.headless=true" and "--CLI". I'll then tunnel a connection to the relay browser through my ssh connection. Then I type "relay" into the CLI. This lets me play at work from behind our stupid firewall. (Sssh, don't tell my boss.) The one annoying thing it does is attempt to launch a browser window on my home computer, which is unnecessary, and causes problems sometimes when it fails. All I want "relay" to do when headless is start the process that responds to relay requests, not open a new browser window.
 

fronobulax

Developer
Staff member
Aha! That makes sense and now so does your request. I'd like some feedback that no one sees any harm in your proposed change but if it passes muster I'll commit it by and by.
 

Theraze

Active member
Or alternatively, if this is just an edge case it may stay better as a personal tweak. It depends if we have anyone running headless who uses a relay browser. I seem to remember someone saying they used it that way a few years back, but not sure if they're still doing it.
 

roippi

Developer
That's pretty much the only way of opening the relay browser if you're headless, ya? I don't think that functionality should be taken away from the relay command, which is essentially used for expressly that purpose.

Now, you're using the command for what I'd consider a side-effect of the command. Which is fine, but I'd rather we add a nobrowser argument to the command to turn the side effect into a main effect. If that makes sense.
 

bleary

Member
That's pretty much the only way of opening the relay browser if you're headless, ya? I don't think that functionality should be taken away from the relay command, which is essentially used for expressly that purpose.

Now, you're using the command for what I'd consider a side-effect of the command. Which is fine, but I'd rather we add a nobrowser argument to the command to turn the side effect into a main effect. If that makes sense.

I view "telling firefox to go ahead and open up http://127.0.0.1:60080/game.php" as the side-effect, and "starting the process that responds to http requests on local port 60080" as the main effect. I can always open up firefox and paste in a URL, I don't need mafia to do that for me.
 

Theraze

Active member
That does sound like a better option... having a way to spawn the server without immediately launching a client out of it. Could also be useful for people who use multiple browsers for their mafia experience and who want to use a different browser than their mafia default for some reason, such as testing a GM script which they'd normally be avoiding.

And bleary, I believe you're just agreeing with him. While you view that as the minor effect, other people using headless java who actually are on that machine might need that functionality and completely removing it from them eliminates the possibility. By allowing you to avoid it by launching "relay nobrowser" you get to avoid the major functionality but still launch the relay server, which you see as the only part of that which you actually desire.
 
Last edited:

Bale

Minion
That does sound like a better option... having a way to spawn the server without immediately launching a client out of it.

Setting the relay browser as a startup tab will start the server without launching a window. I gather that won't work in headless mode though?
 

roippi

Developer
r11617 adds the "nobrowser" argument. I'll change this to a feature request and mark implemented.
 

Catch-22

Active member
Doesn't it make sense that, even if headless, if you wanted to run the relay browser through your script, it should be possible? If you don't want to launch the relay browser while headless, don't call it...

Well moot point now, but no, it doesn't really make sense. Headless mode shouldn't be confused with CLI mode. In headless mode, the awt functions of Java are all changed because a headless PC was originally one without a monitor, not intended for user interaction.

When you're in headless mode a lot of the Java AWT fuctionality becomes effectively disabled, including getDesktop() (throws a java.awt.HeadlessException) which is how we recently migrated to launching your default browser if your Java version supports it. There's a reason Java throws an exception if you try getDesktop() in headless mode, the reason being it doesn't make sense to be launching a browser when you're in headless mode.
 
Top