mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-2306 jcef: jb/java/jcef/JCEFStartupTest.java unexpectedly exits with the exit code: 0
(cherry picked from commit ff7d7bd43c)
This commit is contained in:
@@ -9,6 +9,7 @@ import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author Anton Tarasov
|
||||
@@ -30,6 +31,8 @@ public abstract class JBCefApp {
|
||||
}
|
||||
|
||||
private static JBCefApp INSTANCE;
|
||||
private static Function<CefApp.CefAppState, Void> ourCefAppStateHandler;
|
||||
|
||||
private final CefApp myCefApp;
|
||||
|
||||
private static final AtomicBoolean ourInitialized = new AtomicBoolean(false);
|
||||
@@ -42,7 +45,16 @@ public abstract class JBCefApp {
|
||||
settings.windowless_rendering_enabled = false;
|
||||
settings.log_severity = CefSettings.LogSeverity.LOGSEVERITY_ERROR;
|
||||
String[] appArgs = applyPlatformSettings(settings);
|
||||
CefApp.addAppHandler(new CefAppHandlerAdapter(appArgs) {});
|
||||
CefApp.addAppHandler(new CefAppHandlerAdapter(appArgs) {
|
||||
@Override
|
||||
public void stateHasChanged(CefApp.CefAppState state) {
|
||||
if (ourCefAppStateHandler != null) {
|
||||
ourCefAppStateHandler.apply(state);
|
||||
return;
|
||||
}
|
||||
super.stateHasChanged(state);
|
||||
}
|
||||
});
|
||||
myCefApp = CefApp.getInstance(settings);
|
||||
}
|
||||
|
||||
@@ -131,6 +143,13 @@ public abstract class JBCefApp {
|
||||
return myCefApp;
|
||||
}
|
||||
|
||||
public static void setCefAppStateHandler(Function<CefApp.CefAppState, Void> stateHandler) {
|
||||
if (ourInitialized.get()) {
|
||||
throw new IllegalStateException("JBCefApp has already been init'ed");
|
||||
}
|
||||
ourCefAppStateHandler = stateHandler;
|
||||
}
|
||||
|
||||
public static double sysScale() {
|
||||
try {
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX();
|
||||
|
||||
@@ -94,7 +94,7 @@ public class JBCefBrowser {
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
myCefBrowser.close(false);
|
||||
// myCefBrowser.close(false);
|
||||
myCefClient.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
import org.cef.CefApp;
|
||||
import org.cef.browser.CefBrowser;
|
||||
import org.cef.browser.CefFrame;
|
||||
import org.cef.handler.CefLoadHandlerAdapter;
|
||||
@@ -21,13 +22,20 @@ public class JCEFStartupTest {
|
||||
static final CountDownLatch LATCH = new CountDownLatch(1);
|
||||
static volatile boolean PASSED;
|
||||
|
||||
static volatile JBCefBrowser BROWSER;
|
||||
static volatile JBCefBrowser ourBrowser;
|
||||
|
||||
JCEFStartupTest() {
|
||||
JFrame frame = new JFrame("JCEF");
|
||||
BROWSER = new JBCefBrowser();
|
||||
final JFrame frame = new JFrame("JCEF");
|
||||
|
||||
BROWSER.getCefClient().addLoadHandler(new CefLoadHandlerAdapter() {
|
||||
JBCefApp.setCefAppStateHandler((state) -> {
|
||||
if (state == CefApp.CefAppState.TERMINATED) {
|
||||
frame.dispose();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
ourBrowser = new JBCefBrowser();
|
||||
ourBrowser.getCefClient().addLoadHandler(new CefLoadHandlerAdapter() {
|
||||
@Override
|
||||
public void onLoadStart(CefBrowser cefBrowser, CefFrame cefFrame, CefRequest.TransitionType transitionType) {
|
||||
System.out.println("onLoadStart");
|
||||
@@ -44,11 +52,10 @@ public class JCEFStartupTest {
|
||||
}
|
||||
});
|
||||
|
||||
frame.add(BROWSER.getComponent());
|
||||
frame.add(ourBrowser.getComponent());
|
||||
|
||||
frame.setSize(640, 480);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
@@ -65,7 +72,7 @@ public class JCEFStartupTest {
|
||||
}
|
||||
|
||||
if (!(args.length > 0 && args[0].equalsIgnoreCase("cmd-q"))) {
|
||||
BROWSER.dispose();
|
||||
ourBrowser.dispose();
|
||||
}
|
||||
JBCefApp.getInstance().getCefApp().dispose();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user