Skip to content

Commit 6d304c2

Browse files
committed
Added PreferencesData.setLong/getLong helpers
1 parent 4e7caa8 commit 6d304c2

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

app/src/processing/app/UpdateCheck.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,22 @@ public UpdateCheck(Base base) {
6060

6161
public void run() {
6262
// Ensure updates-check are made only once per day
63-
String lastString = PreferencesData.get("update.last");
63+
Long when = PreferencesData.getLong("update.last");
6464
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-
}
65+
final long ONE_DAY = 24 * 60 * 60 * 1000;
66+
if (when != null && (now - when) < ONE_DAY) {
67+
// don't annoy the shit outta people
68+
return;
7269
}
73-
PreferencesData.set("update.last", String.valueOf(now));
70+
PreferencesData.setLong("update.last", now);
7471

7572
// Set update id
76-
long id;
77-
String idString = PreferencesData.get("update.id");
78-
if (idString != null) {
79-
id = Long.parseLong(idString);
80-
} else {
73+
Long id = PreferencesData.getLong("update.id");
74+
if (id == null) {
8175
// generate a random id in case none exists yet
8276
Random r = new Random();
8377
id = r.nextLong();
84-
PreferencesData.set("update.id", String.valueOf(id));
78+
PreferencesData.setLong("update.id", id);
8579
}
8680

8781
// Check for updates of the IDE

arduino-core/src/processing/app/PreferencesData.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,16 @@ public static boolean areInsecurePackagesAllowed() {
282282
}
283283
return getBoolean(Constants.PREF_CONTRIBUTIONS_TRUST_ALL, false);
284284
}
285+
286+
public static void setLong(String k, long v) {
287+
set(k, String.valueOf(v));
288+
}
289+
290+
public static Long getLong(String k) {
291+
try {
292+
return Long.parseLong(get(k));
293+
} catch (NumberFormatException e) {
294+
return null;
295+
}
296+
}
285297
}

0 commit comments

Comments
 (0)