mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-12 21:36:21 -04:00
Update memory status every 1s, fix #3440
This commit also fixes Lang.getTimer() returns a non-daemon Timer, preventing Java from exiting after closing the launcher.
This commit is contained in:
parent
7d12ef6b09
commit
78e15d130b
@ -57,10 +57,27 @@ import java.util.*;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.ui.FXUtils.stringConverter;
|
import static org.jackhuang.hmcl.ui.FXUtils.stringConverter;
|
||||||
|
import static org.jackhuang.hmcl.util.Lang.getTimer;
|
||||||
import static org.jackhuang.hmcl.util.Pair.pair;
|
import static org.jackhuang.hmcl.util.Pair.pair;
|
||||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||||
|
|
||||||
public final class VersionSettingsPage extends StackPane implements DecoratorPage, VersionPage.VersionLoadable, PageAware {
|
public final class VersionSettingsPage extends StackPane implements DecoratorPage, VersionPage.VersionLoadable, PageAware {
|
||||||
|
|
||||||
|
private static final ObjectProperty<OperatingSystem.PhysicalMemoryStatus> memoryStatus = new SimpleObjectProperty<>(OperatingSystem.PhysicalMemoryStatus.INVALID);
|
||||||
|
private static TimerTask memoryStatusUpdateTask;
|
||||||
|
private static void initMemoryStatusUpdateTask() {
|
||||||
|
FXUtils.checkFxUserThread();
|
||||||
|
if (memoryStatusUpdateTask != null)
|
||||||
|
return;
|
||||||
|
memoryStatusUpdateTask = new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Platform.runLater(() -> memoryStatus.set(OperatingSystem.getPhysicalMemoryStatus()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
getTimer().scheduleAtFixedRate(memoryStatusUpdateTask, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
private final ReadOnlyObjectWrapper<State> state = new ReadOnlyObjectWrapper<>(new State("", null, false, false, false));
|
private final ReadOnlyObjectWrapper<State> state = new ReadOnlyObjectWrapper<>(new State("", null, false, false, false));
|
||||||
|
|
||||||
private AdvancedVersionSettingPage advancedVersionSettingPage;
|
private AdvancedVersionSettingPage advancedVersionSettingPage;
|
||||||
@ -102,7 +119,6 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
|
|||||||
private final BooleanProperty navigateToSpecificSettings = new SimpleBooleanProperty(false);
|
private final BooleanProperty navigateToSpecificSettings = new SimpleBooleanProperty(false);
|
||||||
private final BooleanProperty enableSpecificSettings = new SimpleBooleanProperty(false);
|
private final BooleanProperty enableSpecificSettings = new SimpleBooleanProperty(false);
|
||||||
private final IntegerProperty maxMemory = new SimpleIntegerProperty();
|
private final IntegerProperty maxMemory = new SimpleIntegerProperty();
|
||||||
private final ObjectProperty<OperatingSystem.PhysicalMemoryStatus> memoryStatus = new SimpleObjectProperty<>(OperatingSystem.PhysicalMemoryStatus.INVALID);
|
|
||||||
private final BooleanProperty modpack = new SimpleBooleanProperty();
|
private final BooleanProperty modpack = new SimpleBooleanProperty();
|
||||||
|
|
||||||
public VersionSettingsPage(boolean globalSetting) {
|
public VersionSettingsPage(boolean globalSetting) {
|
||||||
@ -470,6 +486,8 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
|
|||||||
|
|
||||||
memoryStatus.set(OperatingSystem.getPhysicalMemoryStatus());
|
memoryStatus.set(OperatingSystem.getPhysicalMemoryStatus());
|
||||||
componentList.disableProperty().bind(enableSpecificSettings.not());
|
componentList.disableProperty().bind(enableSpecificSettings.not());
|
||||||
|
|
||||||
|
initMemoryStatusUpdateTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -389,7 +389,7 @@ public final class Lang {
|
|||||||
|
|
||||||
public static synchronized Timer getTimer() {
|
public static synchronized Timer getTimer() {
|
||||||
if (timer == null) {
|
if (timer == null) {
|
||||||
timer = new Timer();
|
timer = new Timer(true);
|
||||||
}
|
}
|
||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user