Skip to content

Commit

Permalink
Clear lock for JCEF preview to prevent a blank preview every time you…
Browse files Browse the repository at this point in the history
… open an AsciiDoc file (#1610)
  • Loading branch information
ahus1 committed Oct 26, 2024
1 parent e1fa6d3 commit 4dc56fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This document provides a high-level view of the changes introduced by release.

=== 0.43.3

...
- Clear lock for JCEF preview to prevent a blank preview every time you open an AsciiDoc file (#1610)

=== 0.43.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class AsciiDocJCEFHtmlPanelProvider extends AsciiDocHtmlPanelProvider {
public static final ProviderInfo INFO = new ProviderInfo("JCEF Browser", AsciiDocJCEFHtmlPanelProvider.class.getName());

private static final Logger LOG = Logger.getInstance(AsciiDocDownloaderUtil.class);
private static boolean staleCheckComplete;

@NotNull
@Override
Expand All @@ -32,23 +31,21 @@ public AsciiDocHtmlPanel createHtmlPanel(Document document, Path imagesPath, Run
private static synchronized void clearStaleJCEFlock() {
// Workaround for https://youtrack.jetbrains.com/issue/IJPL-148653,
// when a lock file remains which the name of the old host name
if (!staleCheckComplete) {
staleCheckComplete = true;
Path jcefCache = PathManager.getSystemDir().resolve("jcef_cache");
if (jcefCache.toFile().exists()) {
Path singletonLock = jcefCache.resolve("SingletonLock");
try {
String hostName = InetAddress.getLocalHost().getHostName();
String lockFile = Files.readSymbolicLink(singletonLock).toFile().getName();
if (!lockFile.matches(Pattern.quote(hostName) + "-[0-9]*")) {
// delete the stale lock to prevent the preview from appearing blank
Files.delete(singletonLock);
}
} catch (NoSuchFileException ignore) {
// nop
} catch (IOException e) {
LOG.warn("Can't check lock", e);
// Run this check everytime an AsciiDoc editor is opened to prevent problems, for example, after a computer comes back from suspend mode.
Path jcefCache = PathManager.getSystemDir().resolve("jcef_cache");
if (jcefCache.toFile().exists()) {
Path singletonLock = jcefCache.resolve("SingletonLock");
try {
String hostName = InetAddress.getLocalHost().getHostName();
String lockFile = Files.readSymbolicLink(singletonLock).toFile().getName();
if (!lockFile.matches(Pattern.quote(hostName) + "-[0-9]*")) {
// delete the stale lock to prevent the preview from appearing blank
Files.delete(singletonLock);
}
} catch (NoSuchFileException ignore) {
// nop
} catch (IOException e) {
LOG.warn("Can't check lock", e);
}
}
}
Expand Down

0 comments on commit 4dc56fb

Please sign in to comment.