SudokuFX
Loading...
Searching...
No Matches
fr.softsf.sudokufx.service.VersionService Class Reference

Service for checking if the application version is up to date by querying GitHub. More...

+ Collaboration diagram for fr.softsf.sudokufx.service.VersionService:

Public Member Functions

 VersionService (HttpClient httpClient, MyDateTime myDateTime)
 Initializes the VersionService with the provided HttpClient and MyDateTime utility.
 
Task< Boolean > checkLatestVersion ()
 Checks if the current application version is up-to-date by querying the GitHub API.
 
String getGitHubLinkToRepositoryReleases ()
 Gets the GitHub link to the repository releases page.
 

Private Member Functions

int compareVersions (final String version1, final String version2)
 Compares two version strings in the format MAJOR.MINOR.PATCH.
 
boolean parseResponse (String json)
 Parses the JSON response from the GitHub API to extract the latest published version.
 

Private Attributes

final String currentVersion = JVMApplicationProperties.getAppVersion().isEmpty() ? "" : JVMApplicationProperties.getAppVersion().substring(1)
 
final HttpClient httpClient
 
final MyDateTime myDateTime
 

Static Private Attributes

static final String GITHUB_API_URL = "https://api.github.com/"
 
static final String GITHUB_API_URL_REPO_TAGS = GITHUB_API_URL + "repos/" + OWNER + "/" + REPO + "/tags"
 
static final String GITHUB_URL = "https://github.com/"
 
static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
 
static final String OWNER = "Lob2018"
 
static final String REPO = "SudokuFX"
 

Detailed Description

Service for checking if the application version is up to date by querying GitHub.

It retrieves the latest release tag from the GitHub API and compares it with the current version. If an update is available, the result can be used to notify the user.

Constructor & Destructor Documentation

◆ VersionService()

fr.softsf.sudokufx.service.VersionService.VersionService ( HttpClient httpClient,
MyDateTime myDateTime )

Initializes the VersionService with the provided HttpClient and MyDateTime utility.

This service is responsible for checking the latest version by making HTTP requests.

Parameters
httpClientthe HttpClient used to perform HTTP requests.
myDateTimethe utility for handling date and time formatting.

Member Function Documentation

◆ checkLatestVersion()

Task< Boolean > fr.softsf.sudokufx.service.VersionService.checkLatestVersion ( )

Checks if the current application version is up-to-date by querying the GitHub API.

This method runs in the background using a JavaFX Task to avoid blocking the UI thread. It retrieves the latest release version from the repository and compares it with the current application version.

In case of errors (e.g., timeout, interruption, or network issues), it assumes the version is up-to-date and logs the exception details.

Returns
A Task<Boolean> that returns true if the version is up-to-date, or false if an update is available. On error, it defaults to true.
+ Here is the call graph for this function:

◆ compareVersions()

int fr.softsf.sudokufx.service.VersionService.compareVersions ( final String version1,
final String version2 )
private

Compares two version strings in the format MAJOR.MINOR.PATCH.

Parameters
version1the first version string (e.g., "1.2.3").
version2the second version string (e.g., "1.3.0").
Returns
a negative integer if version1 is older, a positive integer if version1 is newer, or 0 if both versions are equal.
Exceptions
NumberFormatExceptionif the version strings are not properly formatted.

◆ getGitHubLinkToRepositoryReleases()

String fr.softsf.sudokufx.service.VersionService.getGitHubLinkToRepositoryReleases ( )

Gets the GitHub link to the repository releases page.

Returns
the URL to the repository releases page.

◆ parseResponse()

boolean fr.softsf.sudokufx.service.VersionService.parseResponse ( String json)
private

Parses the JSON response from the GitHub API to extract the latest published version.

The method retrieves the latest tag name from the response, validates its format, and compares it with the current application version.

Parameters
jsonThe raw JSON response from the GitHub API.
Returns
true if the current version is up to date or if an error occurs, false if an update is available.
+ Here is the call graph for this function:

Member Data Documentation

◆ currentVersion

final String fr.softsf.sudokufx.service.VersionService.currentVersion = JVMApplicationProperties.getAppVersion().isEmpty() ? "" : JVMApplicationProperties.getAppVersion().substring(1)
private

◆ GITHUB_API_URL

final String fr.softsf.sudokufx.service.VersionService.GITHUB_API_URL = "https://api.github.com/"
staticprivate

◆ GITHUB_API_URL_REPO_TAGS

final String fr.softsf.sudokufx.service.VersionService.GITHUB_API_URL_REPO_TAGS = GITHUB_API_URL + "repos/" + OWNER + "/" + REPO + "/tags"
staticprivate

◆ GITHUB_URL

final String fr.softsf.sudokufx.service.VersionService.GITHUB_URL = "https://github.com/"
staticprivate

◆ httpClient

final HttpClient fr.softsf.sudokufx.service.VersionService.httpClient
private

◆ myDateTime

final MyDateTime fr.softsf.sudokufx.service.VersionService.myDateTime
private

◆ OBJECT_MAPPER

final ObjectMapper fr.softsf.sudokufx.service.VersionService.OBJECT_MAPPER = new ObjectMapper()
staticprivate

◆ OWNER

final String fr.softsf.sudokufx.service.VersionService.OWNER = "Lob2018"
staticprivate

◆ REPO

final String fr.softsf.sudokufx.service.VersionService.REPO = "SudokuFX"
staticprivate

The documentation for this class was generated from the following file: