From 24fc59daa6da3c48544d2d8aec5606a2089f64d5 Mon Sep 17 00:00:00 2001 From: syeyoung <42869671+cyoung06@users.noreply.github.com> Date: Thu, 16 Nov 2023 18:20:14 +0900 Subject: Automatically collect Dungeons Guide stack traces with user approval. (#446) * - fix error handling, don't use throwables like amateur Signed-off-by: syeyoung * - no need for hack to stop Signed-off-by: syeyoung * - gui error handling Signed-off-by: syeyoung * - remote logging error Signed-off-by: syeyoung * - remote logging error Signed-off-by: syeyoung * - testing privacy policy Signed-off-by: syeyoung * - send traces Signed-off-by: syeyoung * - show collect diagnostic? prompt Signed-off-by: syeyoung --------- Signed-off-by: syeyoung --- .../kr/syeyoung/dungeonsguide/launcher/Main.java | 11 +++ .../gui/screen/WidgetPrivacyPolicyLocal.java | 94 ++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/WidgetPrivacyPolicyLocal.java (limited to 'loader/src/main/java/kr/syeyoung/dungeonsguide') diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java index fb6acadf..6ea7bbfa 100755 --- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java +++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java @@ -23,6 +23,8 @@ import kr.syeyoung.dungeonsguide.launcher.branch.UpdateRetrieverUtil; import kr.syeyoung.dungeonsguide.launcher.exceptions.*; import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiDisplayer; import kr.syeyoung.dungeonsguide.launcher.gui.screen.WidgetError; +import kr.syeyoung.dungeonsguide.launcher.gui.screen.WidgetPrivacyPolicy; +import kr.syeyoung.dungeonsguide.launcher.gui.screen.WidgetPrivacyPolicyLocal; import kr.syeyoung.dungeonsguide.launcher.gui.screen.version.WidgetChooseVersion; import kr.syeyoung.dungeonsguide.launcher.gui.tooltip.Notification; import kr.syeyoung.dungeonsguide.launcher.gui.tooltip.NotificationManager; @@ -332,6 +334,15 @@ public class Main if (dgInterface != null) dgInterface.onResourceReload(a); DefaultFontRenderer.DEFAULT_RENDERER.onResourceManagerReload(); }); +// UUID uid = UUID.randomUUID(); +// NotificationManager.getInstance().updateNotification(uid, new WidgetNotification(uid, Notification.builder() +// .title("Privacy Policy") +// .description("Please accept Dungeons Guide\nPrivacy Policy to enjoy server based\nfeatures of Dungeons Guide\n\n(Including Auto-Update/Remote-Jar)") +// .titleColor(0xFFFF0000) +// .onClick(() -> { +// GuiDisplayer.INSTANCE.displayGui(new GuiScreenAdapter(new GlobalHUDScale(new WidgetPrivacyPolicyLocal()))); +// }) +// .build())); } public static Main getMain() { diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/WidgetPrivacyPolicyLocal.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/WidgetPrivacyPolicyLocal.java new file mode 100644 index 00000000..eb5eca2f --- /dev/null +++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/WidgetPrivacyPolicyLocal.java @@ -0,0 +1,94 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.launcher.gui.screen; + +import kr.syeyoung.dungeonsguide.launcher.LetsEncrypt; +import kr.syeyoung.dungeonsguide.launcher.LoaderMeta; +import kr.syeyoung.dungeonsguide.launcher.Main; +import kr.syeyoung.dungeonsguide.launcher.auth.AuthManager; +import kr.syeyoung.dungeonsguide.launcher.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.launcher.guiv2.Widget; +import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.AnnotatedImportOnlyWidget; +import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.DomElementRegistry; +import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.ParsedWidgetConverter; +import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.annotations.On; +import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.data.ParserElement; +import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.data.W3CBackedParser; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.util.ResourceLocation; + +import javax.net.ssl.HttpsURLConnection; +import java.net.URL; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class WidgetPrivacyPolicyLocal extends AnnotatedImportOnlyWidget { + public static final ExecutorService executor = Executors.newSingleThreadExecutor(); + @Bind(variableName = "policy") + public final BindableAttribute policy = new BindableAttribute<>(Widget.class); + @Bind(variableName = "policyVisibility") + public final BindableAttribute policyVisibility = new BindableAttribute<>(String.class, "loading"); + + @Bind(variableName = "policyVersion") + public final BindableAttribute version = new BindableAttribute<>(Integer.class, 0); + + public WidgetPrivacyPolicyLocal() { + super(new ResourceLocation("dungeons_guide_loader:gui/privacyPolicy/privacyPolicy.gui")); + reload0(); + } + + @On(functionName = "accept") + public void accept() { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + AuthManager.getInstance().acceptPrivacyPolicy(version.getValue()); + Minecraft.getMinecraft().displayGuiScreen(null); + } + @On(functionName = "deny") + public void deny() { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + Minecraft.getMinecraft().displayGuiScreen(null); + } + + + public void reload0() { + policyVisibility.setValue("loading"); + executor.submit(() -> { + try { + + try (W3CBackedParser parser = new W3CBackedParser(WidgetPrivacyPolicyLocal.class.getResourceAsStream("/privacyPolicyTest.gui"))) { + ParserElement element = parser.getRootNode(); + ParsedWidgetConverter converter = DomElementRegistry.obtainConverter(element.getNodeName()); + Widget w = converter.convert(this, element); + policy.setValue(w); + policyVisibility.setValue("loaded"); + } + } catch (Exception e) { + e.printStackTrace(); + policyVisibility.setValue("failed"); + } + }); + } + @On(functionName = "reload") + public void reload() { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + reload0(); + } +} -- cgit