Skip to content

Commit

Permalink
Unify duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
caalador committed Apr 29, 2024
1 parent dc500e0 commit 7ed6fb1
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,22 @@ private boolean isLaunched() {
if (launchFile.exists()
&& TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis()
- launchFile.lastModified()) < lastModifiedDelay) {
try {
Files.writeString(launchFile.toPath(),
"" + System.currentTimeMillis());
} catch (IOException e) {
LoggerFactory.getLogger(BrowserLauncher.class)
.debug("Failed to write browser launched file.", e);
}
writeLaunchFile(launchFile);
return true;
}
return LAUNCHED_VALUE.equals(System.getProperty(LAUNCH_TRACKER));
}

private void writeLaunchFile(File launchFile) {
try {
Files.writeString(launchFile.toPath(),
Long.toString(System.currentTimeMillis()));
} catch (IOException e) {
getLogger()
.debug("Failed to write browser launched file.", e);
}
}

private File getLaunchFile() {
ApplicationConfiguration applicationConfiguration = ApplicationConfiguration
.get(context);
Expand All @@ -92,13 +96,7 @@ private File getLaunchFile() {

private void setLaunched() {
// write launch file and update modified timestamp.
try {
Files.writeString(getLaunchFile().toPath(),
"" + System.currentTimeMillis());
} catch (IOException e) {
LoggerFactory.getLogger(BrowserLauncher.class)
.debug("Failed to write browser launched file.", e);
}
writeLaunchFile(getLaunchFile());
System.setProperty(LAUNCH_TRACKER, LAUNCHED_VALUE);
}

Expand Down

0 comments on commit 7ed6fb1

Please sign in to comment.