Skip to content

Commit 4e7caa8

Browse files
committed
Slightly refactored update-check method
Cosmetic-only change that makes the logic of the method clearer
1 parent 190e84a commit 4e7caa8

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

app/src/processing/app/UpdateCheck.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,27 @@
5252
public class UpdateCheck implements Runnable {
5353
Base base;
5454

55-
static final long ONE_DAY = 24 * 60 * 60 * 1000;
56-
57-
5855
public UpdateCheck(Base base) {
5956
Thread thread = new Thread(this);
6057
this.base = base;
6158
thread.start();
6259
}
6360

64-
6561
public void run() {
66-
//System.out.println("checking for updates...");
62+
// Ensure updates-check are made only once per day
63+
String lastString = PreferencesData.get("update.last");
64+
long now = System.currentTimeMillis();
65+
if (lastString != null) {
66+
final long ONE_DAY = 24 * 60 * 60 * 1000;
67+
long when = Long.parseLong(lastString);
68+
if ((now - when) < ONE_DAY) {
69+
// don't annoy the shit outta people
70+
return;
71+
}
72+
}
73+
PreferencesData.set("update.last", String.valueOf(now));
6774

75+
// Set update id
6876
long id;
6977
String idString = PreferencesData.get("update.id");
7078
if (idString != null) {
@@ -76,6 +84,7 @@ public void run() {
7684
PreferencesData.set("update.id", String.valueOf(id));
7785
}
7886

87+
// Check for updates of the IDE
7988
try {
8089
String info;
8190
info = URLEncoder.encode(id + "\t" +
@@ -88,17 +97,6 @@ public void run() {
8897

8998
int latest = readInt("https://www.arduino.cc/latest.txt?" + info);
9099

91-
String lastString = PreferencesData.get("update.last");
92-
long now = System.currentTimeMillis();
93-
if (lastString != null) {
94-
long when = Long.parseLong(lastString);
95-
if (now - when < ONE_DAY) {
96-
// don't annoy the shit outta people
97-
return;
98-
}
99-
}
100-
PreferencesData.set("update.last", String.valueOf(now));
101-
102100
String prompt =
103101
tr("A new version of Arduino is available,\n" +
104102
"would you like to visit the Arduino download page?");

0 commit comments

Comments
 (0)