mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-29 19:50:51 +01:00
Add shutdown hook to ensure system proxy is unregistered
This commit is contained in:
parent
09105e956b
commit
cc7dece9a4
@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
public class NitroHttpProxy {
|
||||
|
||||
private static final String ADMIN_WARNING_KEY = "admin_warning_dialog";
|
||||
private static final AtomicBoolean SHUTDOWN_HOOK = new AtomicBoolean();
|
||||
|
||||
private final Authority authority;
|
||||
private final NitroOsFunctions osFunctions;
|
||||
@ -89,6 +90,8 @@ public class NitroHttpProxy {
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
setupShutdownHook();
|
||||
|
||||
try {
|
||||
proxyServer = DefaultHttpProxyServer.bootstrap()
|
||||
.withPort(NitroConstants.HTTP_PORT)
|
||||
@ -133,4 +136,18 @@ public class NitroHttpProxy {
|
||||
proxyServer.stop();
|
||||
proxyServer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the system proxy is removed when G-Earth exits.
|
||||
* Otherwise, users might complain that their browsers / discord stop working when closing G-Earth incorrectly.
|
||||
*/
|
||||
private static void setupShutdownHook() {
|
||||
if (SHUTDOWN_HOOK.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SHUTDOWN_HOOK.compareAndSet(false, true)) {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> NitroOsFunctionsFactory.create().unregisterSystemProxy()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user