Skip to content

Commit d67d70e

Browse files
committed
handle if github api is down
1 parent 7c2331e commit d67d70e

File tree

1 file changed

+47
-37
lines changed
  • src/main/java/lol/hyper/customlauncher

1 file changed

+47
-37
lines changed

src/main/java/lol/hyper/customlauncher/Main.java

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import lol.hyper.customlauncher.accounts.JSONManager;
2121
import lol.hyper.customlauncher.accounts.windows.MainWindow;
2222
import lol.hyper.customlauncher.fieldofficetracker.FieldOfficeTracker;
23+
import lol.hyper.customlauncher.generic.ErrorWindow;
2324
import lol.hyper.customlauncher.invasiontracker.InvasionTracker;
2425
import lol.hyper.customlauncher.ttrupdater.TTRUpdater;
2526
import lol.hyper.customlauncher.updater.UpdateChecker;
@@ -107,43 +108,52 @@ public static void main(String[] args) throws IOException, InterruptedException
107108
}
108109

109110
// check for updates using my own api
110-
GitHubReleaseAPI api = new GitHubReleaseAPI("CustomLauncherRewrite", "hyperdefined");
111-
GitHubRelease latest = api.getLatestVersion();
112-
String latestVersion = latest.getTagVersion();
113-
GitHubRelease current = api.getReleaseByTag(VERSION);
114-
int behind = api.getBuildsBehind(current);
115-
UpdateChecker updateChecker = new UpdateChecker(api);
116-
StringBuilder updates = new StringBuilder();
117-
// if the user is 1 or more build behind, ask to update
118-
if (behind > 0) {
119-
JTextArea textArea = new JTextArea();
120-
JScrollPane scrollPane = new JScrollPane(textArea);
121-
textArea.setLineWrap(true);
122-
textArea.setWrapStyleWord(true);
123-
scrollPane.setPreferredSize(new Dimension(500, 500));
124-
updates.append("You are running an outdated version! You are running ")
125-
.append(VERSION)
126-
.append(" currently.");
127-
updates.append(" Would you like to update?\n\n");
128-
for (int i = behind - 1; i >= 0; i--) {
129-
String tag = api.getAllReleases().get(i).getTagVersion();
130-
updates.append("----------------------------------------\nVersion: ")
131-
.append(tag)
132-
.append("\n")
133-
.append(api.getReleaseByTag(tag).getReleaseNotes())
134-
.append("\n");
135-
}
136-
textArea.setText(updates.toString());
137-
logger.info("A new version is available! Version: " + latestVersion);
138-
139-
int dialogResult =
140-
JOptionPane.showConfirmDialog(
141-
null, scrollPane, "Updates", JOptionPane.YES_NO_OPTION);
142-
if (dialogResult == JOptionPane.YES_OPTION) {
143-
// download the latest version and run it
144-
updateChecker.downloadLatestVersion();
145-
updateChecker.launchNewVersion(latestVersion);
146-
System.exit(0);
111+
GitHubReleaseAPI api;
112+
try {
113+
api = new GitHubReleaseAPI("CustomLauncherRewrite", "hyperdefined");
114+
} catch (IOException e) {
115+
api = null;
116+
ErrorWindow errorWindow = new ErrorWindow(null, e);
117+
errorWindow.dispose();
118+
}
119+
if (api != null) {
120+
GitHubRelease latest = api.getLatestVersion();
121+
String latestVersion = latest.getTagVersion();
122+
GitHubRelease current = api.getReleaseByTag(VERSION);
123+
int behind = api.getBuildsBehind(current);
124+
UpdateChecker updateChecker = new UpdateChecker(api);
125+
StringBuilder updates = new StringBuilder();
126+
// if the user is 1 or more build behind, ask to update
127+
if (behind > 0) {
128+
JTextArea textArea = new JTextArea();
129+
JScrollPane scrollPane = new JScrollPane(textArea);
130+
textArea.setLineWrap(true);
131+
textArea.setWrapStyleWord(true);
132+
scrollPane.setPreferredSize(new Dimension(500, 500));
133+
updates.append("You are running an outdated version! You are running ")
134+
.append(VERSION)
135+
.append(" currently.");
136+
updates.append(" Would you like to update?\n\n");
137+
for (int i = behind - 1; i >= 0; i--) {
138+
String tag = api.getAllReleases().get(i).getTagVersion();
139+
updates.append("----------------------------------------\nVersion: ")
140+
.append(tag)
141+
.append("\n")
142+
.append(api.getReleaseByTag(tag).getReleaseNotes())
143+
.append("\n");
144+
}
145+
textArea.setText(updates.toString());
146+
logger.info("A new version is available! Version: " + latestVersion);
147+
148+
int dialogResult =
149+
JOptionPane.showConfirmDialog(
150+
null, scrollPane, "Updates", JOptionPane.YES_NO_OPTION);
151+
if (dialogResult == JOptionPane.YES_OPTION) {
152+
// download the latest version and run it
153+
updateChecker.downloadLatestVersion();
154+
updateChecker.launchNewVersion(latestVersion);
155+
System.exit(0);
156+
}
147157
}
148158
}
149159

0 commit comments

Comments
 (0)