Skip to content

Commit e9625f2

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

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

app/src/processing/app/UpdateCheck.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,24 @@ 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);
65+
final long ONE_DAY = 24 * 60 * 60 * 1000;
66+
if (when != null) {
6867
if ((now - when) < ONE_DAY) {
6968
// don't annoy the shit outta people
7069
return;
7170
}
7271
}
73-
PreferencesData.set("update.last", String.valueOf(now));
72+
PreferencesData.setLong("update.last", now);
7473

7574
// Set update id
76-
long id;
77-
String idString = PreferencesData.get("update.id");
78-
if (idString != null) {
79-
id = Long.parseLong(idString);
80-
} else {
75+
Long id = PreferencesData.getLong("update.id");
76+
if (id == null) {
8177
// generate a random id in case none exists yet
8278
Random r = new Random();
8379
id = r.nextLong();
84-
PreferencesData.set("update.id", String.valueOf(id));
80+
PreferencesData.setLong("update.id", id);
8581
}
8682

8783
// 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)