revise JCEF startup

GitOrigin-RevId: c6bd239a1ddd7f84b0a049b64f5e05e9a52db85c
This commit is contained in:
Gregory.Shrago
2020-04-16 03:08:10 +00:00
committed by intellij-monorepo-bot
parent b57eab1e37
commit 83b36e6071
2 changed files with 33 additions and 12 deletions
@@ -3,6 +3,7 @@ package com.intellij.ui.jcef;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.registry.Registry;
@@ -44,7 +45,8 @@ import static com.intellij.ui.jcef.JBCefFileSchemeHandler.FILE_SCHEME_NAME;
*/
@ApiStatus.Experimental
public abstract class JBCefApp {
private static JBCefApp INSTANCE;
private static final Logger LOG = Logger.getInstance(JBCefApp.class);
@NotNull private final CefApp myCefApp;
@NotNull private final Disposable myDisposable = new Disposable() {
@@ -110,21 +112,37 @@ public abstract class JBCefApp {
if (!isEnabled()) {
throw new IllegalStateException("JCEF is disabled");
}
if (!ourInitialized.getAndSet(true)) {
if (Holder.instance == null) {
throw new IllegalStateException("JCEF is not available or failed to initialize");
}
return Holder.instance;
}
private static class Holder {
static final JBCefApp instance = initInstance();
}
@Nullable
private static JBCefApp initInstance() {
ourInitialized.set(true);
try {
if (SystemInfo.isMac) {
INSTANCE = new JBCefAppMac();
return new JBCefAppMac();
}
else if (SystemInfo.isLinux) {
INSTANCE = new JBCefAppLinux();
return new JBCefAppLinux();
}
else if (SystemInfo.isWindows) {
INSTANCE = new JBCefAppWindows();
}
else {
throw new IllegalStateException("JCEF is initialized on unsupported platform");
return new JBCefAppWindows();
}
}
return INSTANCE;
catch (UnsatisfiedLinkError e) {
LOG.warn(e.toString());
}
catch (Throwable e) {
LOG.warn(e);
}
return null;
}
/**
@@ -13,9 +13,12 @@ final class JBCefStartup {
// os=mac
JBCefStartup() {
if (RegistryManager.getInstance().is("ide.browser.jcef.enabled") &&
RegistryManager.getInstance().is("ide.browser.jcef.preinit"))
{
STARTUP_CLIENT = JBCefApp.getInstance().createClient();
RegistryManager.getInstance().is("ide.browser.jcef.preinit")) {
try {
STARTUP_CLIENT = JBCefApp.getInstance().createClient();
}
catch (IllegalStateException ignore) {
}
}
}
}