Skip to content

Commit

Permalink
feat: add shared version to the log uploader
Browse files Browse the repository at this point in the history
fix: log uploader uploading the wrong data from the settings file
  • Loading branch information
MichaelHillcox committed Mar 23, 2024
1 parent e8e5050 commit 8697530
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
14 changes: 12 additions & 2 deletions subprocess/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,20 @@ dependencies {
// useJUnitPlatform()
//}

// Lazy wrapper for the package.json data.
def packageJsonData = null
def packageJsonHolder = () -> {
if (packageJsonData == null) {
packageJsonData = new JsonSlurper().parse(file("../package.json"))
}

return packageJsonData
}

task processSource(type: Sync) {
from sourceSets.main.java
inputs.property 'version', version
filter(ReplaceTokens, tokens: [APPVERSION: version, WEBVERSION: version, BRANCH: branch, SENTRY: sentryDsn])
filter(ReplaceTokens, tokens: [APPVERSION: version, WEBVERSION: version, SHAREDVERSION: packageJsonHolder().version, BRANCH: branch, SENTRY: sentryDsn])
into "$buildDir/src"
}

Expand Down Expand Up @@ -161,7 +171,7 @@ tasks.register('writeLicenses', Copy) {
tasks.register('writeVersion') {
it.dependsOn 'downloadLicenses'
doLast {
def packageJson = new JsonSlurper().parse(file("../package.json"))
def packageJson = packageJsonHolder()

file("$projectDir/build/libs/meta.json").newWriter().withWriter { w ->
w << JsonOutput.toJson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ public class Constants {
public static final int WEBSOCKET_PORT = 13377;
public static final String APPVERSION = "@APPVERSION@";
public static final String BRANCH = "@BRANCH@";
public static final String SHARED_VERSION = "@SHAREDVERSION@";
public static final String SENTRY_DSN = "@SENTRY@";
public static final String PLATFORM = WORKING_DIR.toAbsolutePath().toString().contains("Overwolf") ? "Overwolf" : "Electron";

public static final String USER_AGENT = "modpacklauncher/" + APPVERSION + " Mozilla/5.0 (" + OS.CURRENT.name() + ") AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.138 Safari/537.36 Vivaldi/1.8.770.56";
private static final Throttler GLOBAL_THROTTLER = new Throttler();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class LogsUploader {
public static String uploadUILogs() {
var obj = new JsonObject();

obj.addProperty("version", "2.0.0");
obj.addProperty("version", "2.0.1");

var metaDetails = new JsonObject();
metaDetails.addProperty("instanceCount", Instances.allInstances().size());
Expand All @@ -65,6 +65,7 @@ public static String uploadUILogs() {
var appDetails = new JsonObject();
appDetails.addProperty("app", Constants.APPVERSION);
appDetails.addProperty("platform", Constants.PLATFORM);
appDetails.addProperty("sharedVersion", Constants.SHARED_VERSION);
obj.add("appDetails", appDetails);

var systemDetails = new JsonObject();
Expand Down Expand Up @@ -95,7 +96,12 @@ public static String uploadUILogs() {
}

private static String getFilteredSettings() {
return uploadIfNotEmpty(GSON.toJson(Settings.getSettings()));
try {
return GSON.toJson(Settings.getSettings());
} catch (Throwable e) {
LOGGER.warn("Failed to get settings", e);
return "settings failed to load";
}
}

private static JsonObject collectLogs() {
Expand All @@ -115,7 +121,7 @@ private static JsonObject collectLogs() {
.entrySet()
.forEach(e -> logs.addProperty(e.getKey(), e.getValue().getAsString()));

getLastTwoDebugLogsFromHistory()
getLastFourDebugLogsFromHistory()
.forEach((key, value) -> logs.addProperty(key, uploadIfNotEmpty(value)));

return logs;
Expand Down Expand Up @@ -256,8 +262,8 @@ public static String getDebugLog() {
return null;
}

public static Map<String, String> getLastTwoDebugLogsFromHistory() {
var files = List.of("debug-1.log.gz", "debug-2.log.gz");
public static Map<String, String> getLastFourDebugLogsFromHistory() {
var files = List.of("debug-1.log.gz", "debug-2.log.gz", "debug-3.log.gz", "debug-4.log.gz");
var existingFiles = files.stream()
.map(Constants.getDataDir().resolve("logs")::resolve)
.filter(Files::exists)
Expand Down

0 comments on commit 8697530

Please sign in to comment.