Improve distribution type initialization

This commit is contained in:
crschnick 2023-12-01 23:28:31 +00:00
parent e3265a573d
commit faed51f996
2 changed files with 18 additions and 5 deletions

View file

@ -6,6 +6,7 @@ import io.xpipe.app.core.*;
import io.xpipe.app.issue.*;
import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.app.storage.DataStorage;
import io.xpipe.app.update.XPipeDistributionType;
import io.xpipe.app.util.LicenseProvider;
import io.xpipe.app.util.FileBridge;
import io.xpipe.app.util.LockedSecretValue;
@ -47,6 +48,7 @@ public class BaseMode extends OperationMode {
LicenseProvider.get().init();
AppAntivirusAlert.showIfNeeded();
LocalStore.init();
XPipeDistributionType.init();
AppPrefs.init();
AppCharsets.init();
AppCharsetter.init();

View file

@ -30,13 +30,14 @@ public enum XPipeDistributionType {
this.updateHandlerSupplier = updateHandlerSupplier;
}
public static XPipeDistributionType get() {
public static void init() {
if (type != null) {
return type;
return;
}
if (!ModuleHelper.isImage()) {
return (type = DEVELOPMENT);
type = DEVELOPMENT;
return;
}
if (!XPipeSession.get().isNewBuildSession()) {
@ -47,19 +48,29 @@ public enum XPipeDistributionType {
.findAny()
.orElse(null);
if (cachedType != null) {
return (type = cachedType);
type = cachedType;
return;
}
}
var det = determine();
// Don't cache unknown type
if (det == UNKNOWN) {
return UNKNOWN;
return;
}
type = det;
AppCache.update("dist", type.getId());
TrackEvent.withInfo("Determined distribution type").tag("type",type.getId()).handle();
}
public static XPipeDistributionType get() {
if (type == null) {
TrackEvent.withWarn("Distribution type requested before init").handle();
return UNKNOWN;
}
return type;
}