Skip to content

Commit eb20b1b

Browse files
committed
Allow splash image to be updated via network
1 parent d5d4751 commit eb20b1b

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

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

+20-1
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

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

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

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

0 commit comments

Comments
 (0)