|
5 | 5 | */ |
6 | 6 | package io.flutter.jxbrowser; |
7 | 7 |
|
8 | | -import com.intellij.openapi.application.ApplicationListener; |
| 8 | +import com.intellij.openapi.Disposable; |
9 | 9 | import com.intellij.openapi.application.ApplicationManager; |
10 | 10 | import com.intellij.openapi.diagnostic.Logger; |
11 | 11 | import com.intellij.openapi.util.SystemInfo; |
| 12 | +import io.flutter.utils.OpenApiUtils; |
12 | 13 | import com.teamdev.jxbrowser.engine.Engine; |
13 | 14 | import com.teamdev.jxbrowser.engine.EngineOptions; |
14 | 15 | import com.teamdev.jxbrowser.engine.PasswordStore; |
|
22 | 23 | import static com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED; |
23 | 24 | import static com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN; |
24 | 25 |
|
25 | | -public class EmbeddedBrowserEngine { |
| 26 | +public class EmbeddedBrowserEngine implements Disposable { |
26 | 27 | private static final @NotNull Logger LOG = PluginLogger.createLogger(EmbeddedBrowserEngine.class); |
27 | 28 | private final Engine engine; |
28 | 29 |
|
@@ -60,22 +61,22 @@ public EmbeddedBrowserEngine() { |
60 | 61 | } |
61 | 62 | engine = temp; |
62 | 63 |
|
63 | | - ApplicationManager.getApplication().addApplicationListener(new ApplicationListener() { |
64 | | - @Override |
65 | | - public boolean canExitApplication() { |
66 | | - try { |
67 | | - if (engine != null && !engine.isClosed()) { |
68 | | - engine.close(); |
69 | | - } |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public void dispose() { |
| 68 | + OpenApiUtils.safeExecuteOnPooledThread(() -> { |
| 69 | + try { |
| 70 | + if (engine != null && !engine.isClosed()) { |
| 71 | + engine.close(); |
70 | 72 | } |
71 | | - catch (Exception ex) { |
72 | | - if (FlutterSettings.getInstance().isFilePathLoggingEnabled()) { |
73 | | - LOG.info(ex); |
74 | | - } else { |
75 | | - LOG.info("Exception when closing JX Browser engine: " + ex.getMessage()); |
76 | | - } |
| 73 | + } |
| 74 | + catch (Exception ex) { |
| 75 | + if (FlutterSettings.getInstance().isFilePathLoggingEnabled()) { |
| 76 | + LOG.info(ex); |
| 77 | + } else { |
| 78 | + LOG.info("Exception when closing JX Browser engine: " + ex.getMessage()); |
77 | 79 | } |
78 | | - return true; |
79 | 80 | } |
80 | 81 | }); |
81 | 82 | } |
|
0 commit comments