Skip to content

Commit b907ea5

Browse files
committed
Allow splash image to be updated via network
1 parent 864cea6 commit b907ea5

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

app/src/cc/arduino/view/SplashScreenHelper.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@
3131

3232
package cc.arduino.view;
3333

34-
import java.awt.*;
34+
import java.awt.Color;
35+
import java.awt.FontMetrics;
36+
import java.awt.Graphics2D;
37+
import java.awt.SplashScreen;
38+
import java.awt.Toolkit;
3539
import java.awt.geom.Rectangle2D;
40+
import java.io.File;
41+
import java.io.IOException;
3642
import java.util.Map;
3743

3844
import processing.app.Theme;
45+
import processing.app.UpdateCheck;
3946

4047
public class SplashScreenHelper {
4148

@@ -57,6 +64,10 @@ public SplashScreenHelper(SplashScreen splash) {
5764
} else {
5865
desktopHints = null;
5966
}
67+
File image = UpdateCheck.getUpdatedSplashImageFile();
68+
if (image != null) {
69+
splashImage(image);
70+
}
6071
}
6172

6273
public void splashText(String text) {
@@ -120,4 +131,12 @@ private void printText(String str) {
120131
System.err.println(str);
121132
}
122133

134+
public void splashImage(File f) {
135+
try {
136+
splash.setImageURL(f.toURI().toURL());
137+
} catch (NullPointerException | IllegalStateException | IOException e) {
138+
e.printStackTrace();
139+
}
140+
}
141+
123142
}

app/src/processing/app/UpdateCheck.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,44 @@ public void run() {
124124
//e.printStackTrace();
125125
//System.err.println("Error while trying to check for an update.");
126126
}
127+
128+
try {
129+
// Check for updates of the splash screen
130+
List<String> lines = readFileFromURL("https://go.bug.st/latest_splash.txt");
131+
if (lines.size() > 0) {
132+
// if the splash image has been changed download the new file
133+
String newSplashUrl = lines.get(0);
134+
String oldSplashUrl = PreferencesData.get("splash.imageurl");
135+
if (!newSplashUrl.equals(oldSplashUrl)) {
136+
File tmpFile = BaseNoGui.getSettingsFile("splash.png.tmp");
137+
downloadFileFromURL(newSplashUrl, tmpFile);
138+
File destFile = BaseNoGui.getSettingsFile("splash.png");
139+
Files.move(tmpFile.toPath(), destFile.toPath(),
140+
StandardCopyOption.REPLACE_EXISTING);
141+
PreferencesData.set("splash.imageurl", newSplashUrl);
142+
}
143+
144+
// extend expiration by 24h
145+
PreferencesData.setLong("splash.expire", now + ONE_DAY);
146+
}
147+
} catch (Exception e) {
148+
// e.printStackTrace();
149+
}
127150
}
128151

152+
public static File getUpdatedSplashImageFile() {
153+
if (PreferencesData.has("splash.expire")) {
154+
Long expire = PreferencesData.getLong("splash.expire");
155+
long now = System.currentTimeMillis();
156+
if (expire != null && now < expire) {
157+
File f = BaseNoGui.getSettingsFile("splash.png");
158+
if (f.isFile()) {
159+
return f;
160+
}
161+
}
162+
}
163+
return null;
164+
}
129165

130166
protected int readIntFromURL(String _url) throws Exception {
131167
List<String> lines = readFileFromURL(_url);

0 commit comments

Comments
 (0)