mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
activate built-in web server only on real open invocation
This commit is contained in:
+1
-6
@@ -18,7 +18,6 @@ package org.jetbrains.builtInWebServer;
|
||||
import com.intellij.ide.browsers.OpenInBrowserRequest;
|
||||
import com.intellij.ide.browsers.WebBrowserService;
|
||||
import com.intellij.ide.browsers.WebBrowserUrlProvider;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -70,11 +69,7 @@ public class BuiltInWebBrowserUrlProvider extends WebBrowserUrlProvider implemen
|
||||
urls.add(Urls.newHttpUrl(defaultAuthority, '/' + project.getName() + '/' + path2, query));
|
||||
}
|
||||
}
|
||||
|
||||
if (BuiltInWebServerKt.isActivatable()) {
|
||||
PropertiesComponent.getInstance().setValue("ide.built.in.web.server.active", true);
|
||||
}
|
||||
|
||||
|
||||
return urls;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,22 +20,80 @@ import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.util.ExecUtil;
|
||||
import com.intellij.ide.GeneralSettings;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.AppUIUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Url;
|
||||
import com.intellij.util.Urls;
|
||||
import com.intellij.util.net.NetUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.builtInWebServer.BuiltInServerOptions;
|
||||
import org.jetbrains.ide.BuiltInServerManager;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
final class BrowserLauncherImpl extends BrowserLauncherAppless {
|
||||
public final class BrowserLauncherImpl extends BrowserLauncherAppless {
|
||||
@Override
|
||||
public void browse(@NotNull String url, @Nullable WebBrowser browser, @Nullable Project project) {
|
||||
if (Registry.is("ide.built.in.web.server.activatable", false)) {
|
||||
Url parsedUrl = Urls.parse(url, false);
|
||||
if (parsedUrl != null && parsedUrl.getAuthority() != null && isOnBuiltInWebServerByAuthority(parsedUrl.getAuthority())) {
|
||||
PropertiesComponent.getInstance().setValue("ide.built.in.web.server.active", true);
|
||||
}
|
||||
}
|
||||
|
||||
super.browse(url, browser, project);
|
||||
}
|
||||
|
||||
public static boolean isOnBuiltInWebServerByAuthority(@NotNull String authority) {
|
||||
int portIndex = authority.indexOf(':');
|
||||
if (portIndex < 0 || portIndex == authority.length() - 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int port;
|
||||
try {
|
||||
port = Integer.parseInt(authority.substring(portIndex + 1));
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (BuiltInServerOptions.getInstance().builtInServerPort != port && BuiltInServerManager.getInstance().getPort() != port) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String host = authority.substring(0, portIndex);
|
||||
if (NetUtils.isLocalhost(host)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
InetAddress inetAddress;
|
||||
try {
|
||||
inetAddress = InetAddress.getByName(host);
|
||||
}
|
||||
catch (UnknownHostException ignored) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inetAddress == null) {
|
||||
return false;
|
||||
}
|
||||
return inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void browseUsingNotSystemDefaultBrowserPolicy(@NotNull URI uri, @NotNull GeneralSettings settings, @Nullable Project project) {
|
||||
WebBrowserManager browserManager = WebBrowserManager.getInstance();
|
||||
|
||||
+2
-2
@@ -23,11 +23,11 @@
|
||||
<orderEntry type="module" module-name="xml-structure-view-impl" exported="" />
|
||||
<orderEntry type="library" name="Netty" level="project" />
|
||||
<orderEntry type="module" module-name="xdebugger-api" />
|
||||
<orderEntry type="module" module-name="built-in-server" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
<setting name="state" value="1" />
|
||||
</Base>
|
||||
</component>
|
||||
</module>
|
||||
|
||||
</module>
|
||||
Reference in New Issue
Block a user