mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-06-28 19:10:57 +12:00
Make theme detection error resistant
This commit is contained in:
parent
16de992c29
commit
7521f08512
|
@ -70,35 +70,39 @@ public class AppTheme {
|
|||
return;
|
||||
}
|
||||
|
||||
OsThemeDetector detector = OsThemeDetector.getDetector();
|
||||
if (AppPrefs.get().theme.getValue() == null) {
|
||||
try {
|
||||
setDefault(detector.isDark());
|
||||
} catch (Throwable ex) {
|
||||
ErrorEvent.fromThrowable(ex).omit().handle();
|
||||
setDefault(false);
|
||||
try {
|
||||
OsThemeDetector detector = OsThemeDetector.getDetector();
|
||||
if (AppPrefs.get().theme.getValue() == null) {
|
||||
try {
|
||||
setDefault(detector.isDark());
|
||||
} catch (Throwable ex) {
|
||||
ErrorEvent.fromThrowable(ex).omit().handle();
|
||||
setDefault(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
var t = AppPrefs.get().theme.getValue();
|
||||
|
||||
// The gnome detector sometimes runs into issues, also it's not that important
|
||||
if (!OsType.getLocal().equals(OsType.LINUX)) {
|
||||
detector.registerListener(dark -> {
|
||||
PlatformThread.runLaterIfNeeded(() -> {
|
||||
if (dark && !AppPrefs.get().theme.getValue().isDark()) {
|
||||
AppPrefs.get().theme.setValue(Theme.getDefaultDarkTheme());
|
||||
}
|
||||
|
||||
if (!dark && AppPrefs.get().theme.getValue().isDark()) {
|
||||
AppPrefs.get().theme.setValue(Theme.getDefaultLightTheme());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
ErrorEvent.fromThrowable(t).omit().handle();
|
||||
}
|
||||
|
||||
var t = AppPrefs.get().theme.getValue();
|
||||
t.apply();
|
||||
TrackEvent.debug("Set theme " + t.getId() + " for scene");
|
||||
|
||||
// The gnome detector sometimes runs into issues, also it's not that important
|
||||
if (!OsType.getLocal().equals(OsType.LINUX)) {
|
||||
detector.registerListener(dark -> {
|
||||
PlatformThread.runLaterIfNeeded(() -> {
|
||||
if (dark && !AppPrefs.get().theme.getValue().isDark()) {
|
||||
AppPrefs.get().theme.setValue(Theme.getDefaultDarkTheme());
|
||||
}
|
||||
|
||||
if (!dark && AppPrefs.get().theme.getValue().isDark()) {
|
||||
AppPrefs.get().theme.setValue(Theme.getDefaultLightTheme());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
AppPrefs.get().theme.addListener((c, o, n) -> {
|
||||
changeTheme(n);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue