迁移崩溃收集

改进推荐内容关闭策略
This commit is contained in:
南宫临风 2016-08-25 14:33:40 +08:00
parent 90451e6da9
commit c0b935e3f1
2 changed files with 47 additions and 27 deletions

View File

@ -19,7 +19,6 @@ package org.jackhuang.hellominecraft.launcher.ui;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Image; import java.awt.Image;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -37,12 +36,10 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.launcher.Main; import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.launcher.setting.Settings; import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.NetUtils; import org.jackhuang.hellominecraft.util.NetUtils;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.ui.SwingUtils; import org.jackhuang.hellominecraft.util.ui.SwingUtils;
@ -65,7 +62,7 @@ public class RecommendPanel extends JPanel {
private boolean ignoreSwitch = false; private boolean ignoreSwitch = false;
private List<RecommendInfo> recommends; private List<RecommendInfo> recommends;
public ScheduledExecutorService scheduledexec = Executors.newScheduledThreadPool(1); public final ScheduledExecutorService scheduledexec = Executors.newScheduledThreadPool(1);
public RecommendPanel() { public RecommendPanel() {
initComponents(); initComponents();
@ -89,17 +86,7 @@ public class RecommendPanel extends JPanel {
closeButton.setRolloverIcon(Main.getIcon("re_close_enter.png")); closeButton.setRolloverIcon(Main.getIcon("re_close_enter.png"));
closeButton.setBorder(BorderFactory.createEmptyBorder()); closeButton.setBorder(BorderFactory.createEmptyBorder());
closeButton.setContentAreaFilled(false); closeButton.setContentAreaFilled(false);
closeButton.addActionListener((e) -> { closeButton.addActionListener((e) -> ignoreTheRecommend(imageKey));
synchronized(RecommendPanel.class) {
if (StrUtils.isNotBlank(imageKey)) {
Settings.getInstance().getIgnoreRecommend().add(imageKey);
Settings.save();
ignoreSwitch = true;
showNext();
}
}
});
closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
closeButton.setFocusable(false); closeButton.setFocusable(false);
closeButton.setBounds(0, 0, 12, 12); closeButton.setBounds(0, 0, 12, 12);
@ -107,12 +94,27 @@ public class RecommendPanel extends JPanel {
this.add(closeButton); this.add(closeButton);
} }
private void ignoreTheRecommend(String url) {
synchronized(RecommendPanel.class) {
if (StrUtils.isNotBlank(url)) {
Settings.getInstance().getIgnoreRecommend().add(url);
Settings.save();
ignoreSwitch = true;
showNext();
}
}
}
private void MouseClicked(MouseEvent evt) { private void MouseClicked(MouseEvent evt) {
if (imageKey == null) { if (imageKey == null) {
return; return;
} }
RecommendInfo info = recommends.get(getCurrentImageIndex()); RecommendInfo info = recommends.get(getCurrentImageIndex());
if (info.link != null && !info.link.equals("")) { if (StrUtils.isNotBlank(info.link)) {
if (info.once) {
ignoreTheRecommend(info.url);
}
SwingUtils.openLink(info.link); SwingUtils.openLink(info.link);
} }
} }
@ -191,6 +193,7 @@ public class RecommendPanel extends JPanel {
private void showNext() { private void showNext() {
if (getCanShowImageCount() == 0) { if (getCanShowImageCount() == 0) {
setVisible(false); setVisible(false);
scheduledexec.shutdown();
} else { } else {
int showIndex = getNextImageIndex(); int showIndex = getNextImageIndex();
RecommendInfo info = recommends.get(showIndex); RecommendInfo info = recommends.get(showIndex);
@ -199,6 +202,9 @@ public class RecommendPanel extends JPanel {
} }
private boolean ignoreShowUrl(String url) { private boolean ignoreShowUrl(String url) {
if (StrUtils.isBlank(url)) {
return true;
}
return Settings.getInstance().getIgnoreRecommend().contains(url); return Settings.getInstance().getIgnoreRecommend().contains(url);
} }
@ -236,7 +242,7 @@ public class RecommendPanel extends JPanel {
int currIndex = 0; int currIndex = 0;
for (int i = 0; i < recommends.size(); i++) { for (int i = 0; i < recommends.size(); i++) {
RecommendInfo info = recommends.get(i); RecommendInfo info = recommends.get(i);
if (imageKey != null && info.url.equals(imageKey)) { if (StrUtils.isNotBlank(imageKey) && info.url.equals(imageKey)) {
currIndex = i; currIndex = i;
break; break;
} }
@ -268,16 +274,17 @@ public class RecommendPanel extends JPanel {
static class RecommendInfo { static class RecommendInfo {
String url; String url;
String link; String link;
boolean once;
Image image; Image image;
} }
class LoadImages extends SwingWorker<List<Map<String, String>>, Void> { class LoadImages extends SwingWorker<List<Map<String, Object>>, Void> {
private static final String RECOMMEND_URL = "http://client.api.mcgogogo.com:81/recommend.php"; private static final String RECOMMEND_URL = "http://client.api.mcgogogo.com:81/recommend.php";
@Override @Override
protected List<Map<String, String>> doInBackground() throws Exception { protected List<Map<String, Object>> doInBackground() throws Exception {
List<Map<String, String>> infos = null; List<Map<String, Object>> infos = null;
do { do {
String content = NetUtils.get(RECOMMEND_URL); String content = NetUtils.get(RECOMMEND_URL);
if (content == null || content.equals("")) { if (content == null || content.equals("")) {
@ -290,7 +297,7 @@ public class RecommendPanel extends JPanel {
break; break;
} }
infos = (List<Map<String, String>>) data.get("data"); infos = (List<Map<String, Object>>) data.get("data");
} while (false); } while (false);
return infos; return infos;
} }
@ -298,14 +305,27 @@ public class RecommendPanel extends JPanel {
@Override @Override
protected void done() { protected void done() {
try { try {
List<Map<String, String>> infos = this.get(); List<Map<String, Object>> infos = this.get();
if (infos == null) { if (infos == null) {
return; return;
} }
for (Map<String, String> info : infos) { for (Map<String, Object> info : infos) {
RecommendInfo recommend = new RecommendInfo(); RecommendInfo recommend = new RecommendInfo();
recommend.url = info.get("url"); if (info.get("url") != null) {
recommend.link = info.get("link"); recommend.url = (String) info.get("url");
} else {
recommend.url = "";
}
if (info.get("link") != null) {
recommend.link = (String) info.get("link");
} else {
recommend.link = "";
}
if (info.get("once") != null) {
recommend.once = (boolean) info.get("once");
} else {
recommend.once = false;
}
recommend.image = null; recommend.image = null;
recommends.add(recommend); recommends.add(recommend);
} }

View File

@ -138,7 +138,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
map.put("CrashReport", text); map.put("CrashReport", text);
try { try {
NetUtils.post(NetUtils.constantURL("http://huangyuhui.duapp.com/crash.php"), map); NetUtils.post(NetUtils.constantURL("http://client.api.mcgogogo.com:81/crash_report.php"), map);
} catch (Throwable error) { } catch (Throwable error) {
LOGGER.log(Level.SEVERE, "Failed to post HMCL server.", error); LOGGER.log(Level.SEVERE, "Failed to post HMCL server.", error);
} }