Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit 5a90440

Browse files
committed
🐛 Fix occasional problem where in the theme only partially updates (#18)
Use IntelliJ's Alarm class to schedule updates on the UI thread instead of the async parameter in switchLafAndUpdateUI method
1 parent bfde6a7 commit 5a90440

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = "com.github.gilday"
11-
version = "1.2.4"
11+
version = "1.2.5"
1212

1313
repositories {
1414
mavenCentral()

src/main/java/com/github/gilday/darkmode/DarkModeSync.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.intellij.openapi.components.ServiceManager;
1111
import com.intellij.openapi.diagnostic.Logger;
1212
import com.intellij.openapi.util.SystemInfo;
13+
import com.intellij.util.Alarm;
14+
import com.intellij.util.Alarm.ThreadToUse;
1315
import java.util.concurrent.ScheduledExecutorService;
1416
import java.util.concurrent.ScheduledFuture;
1517
import java.util.concurrent.TimeUnit;
@@ -28,6 +30,7 @@ public final class DarkModeSync implements Disposable {
2830

2931
private final LafManager lafManager;
3032
private final DarkModeSyncThemes themes;
33+
private final Alarm updateOnUIThreadAlarm;
3134

3235
/** @param lafManager IDEA look-and-feel manager for getting and setting the current theme */
3336
public DarkModeSync(final LafManager lafManager) {
@@ -37,17 +40,25 @@ public DarkModeSync(final LafManager lafManager) {
3740
if (!(SystemInfo.isMacOSMojave || SystemInfo.isWin10OrNewer)) {
3841
logger.error("Plugin only supports macOS Mojave and greater or Windows 10 and greater");
3942
scheduledFuture = null;
43+
updateOnUIThreadAlarm = null;
4044
return;
4145
}
42-
ScheduledExecutorService executor = JobScheduler.getScheduler();
46+
final ScheduledExecutorService executor = JobScheduler.getScheduler();
4347
scheduledFuture =
4448
executor.scheduleWithFixedDelay(this::updateLafIfNecessary, 0, 3, TimeUnit.SECONDS);
49+
// initialize this last because it publishes "this"
50+
updateOnUIThreadAlarm = new Alarm(ThreadToUse.SWING_THREAD, this);
4551
}
4652

4753
/** cancels the scheduled task if one exists */
4854
@Override
4955
public void dispose() {
50-
if (scheduledFuture != null) scheduledFuture.cancel(true);
56+
if (scheduledFuture != null) {
57+
scheduledFuture.cancel(true);
58+
}
59+
if (updateOnUIThreadAlarm != null) {
60+
updateOnUIThreadAlarm.cancelAllRequests();
61+
}
5162
}
5263

5364
private void updateLafIfNecessary() {
@@ -71,8 +82,13 @@ private void updateLafIfNecessary() {
7182
}
7283
}
7384

85+
/**
86+
* Uses the {@link #updateOnUIThreadAlarm} to schedule a look and feel update on the Swing UI
87+
* thread
88+
*/
7489
private void updateLaf(final LookAndFeelInfo newLaf) {
75-
QuickChangeLookAndFeel.switchLafAndUpdateUI(lafManager, newLaf, true);
90+
updateOnUIThreadAlarm.addRequest(
91+
() -> QuickChangeLookAndFeel.switchLafAndUpdateUI(lafManager, newLaf, false), 0);
7692
}
7793

7894
private static final Logger logger = Logger.getInstance(DarkModeSync.class);

src/main/resources/META-INF/plugin.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
</vendor>
1010

1111
<change-notes><![CDATA[
12+
v1.2.5
13+
<ul>
14+
<li>Fixed a problem wherein the theme would only partially update on occasion.</li>
15+
</ul>
16+
v1.2.4
17+
<ul>
18+
<li>Fixed incompatibilities with IDEs running on JetBrains Runtime 8 such as Android Studio.</li>
19+
</ul>
1220
v1.2.3
1321
<ul>
1422
<li>Added support IDEA 2020.2.</li>

0 commit comments

Comments
 (0)