CanScan
Loading...
Searching...
No Matches
fr.softsf.canscan.service.VersionService Enum Reference

Singleton service for checking application version against GitHub releases. More...

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

Public Member Functions

 VersionService ()
 Initializes the HTTP client with TLS 1.3 and 5-second timeout.
 
SwingWorker< Boolean, Void > checkLatestVersion (String currentVersion, JButton updateButton)
 Asynchronously checks whether the current application version matches the latest GitHub release tag.
 

Public Attributes

 INSTANCE
 

Private Member Functions

SwingWorker< Boolean, Void > npeCheckLatestVersion (String currentVersion, JButton updateButton)
 Validates input for version check.
 
Boolean requestAndVerify (String currentVersion) throws IOException, InterruptedException
 Sends an HTTP request to the GitHub tags API and verifies if the latest release tag matches the current version.
 
void updateButtonState (JButton button, boolean enabled, String tooltip)
 Updates the state and tooltip of the given button based on application logic.
 

Private Attributes

final HttpClient httpClient
 

Static Private Attributes

static final String CLOSE_HTML = "</html>"
 
static final String GITHUB_TAGS_API_URL
 
static final int HTTP_STATUS_CODE_OK = 200
 
static final String LATEST_RELEASES_REPO_URL
 
static final Pattern TAG_PATTERN = Pattern.compile("\"name\"\\s*:\\s*\"([^\"]+)\"")
 

Detailed Description

Singleton service for checking application version against GitHub releases.

Uses the GitHub API to compare the current version with the latest tagged release.

Constructor & Destructor Documentation

◆ VersionService()

fr.softsf.canscan.service.VersionService.VersionService ( )

Initializes the HTTP client with TLS 1.3 and 5-second timeout.

Sets httpClient to null if initialization fails.

Member Function Documentation

◆ checkLatestVersion()

SwingWorker< Boolean, Void > fr.softsf.canscan.service.VersionService.checkLatestVersion ( String currentVersion,
JButton updateButton )

Asynchronously checks whether the current application version matches the latest GitHub release tag.

If an update is available, the specified button is made enabled; otherwise, it remains disabled.

Parameters
currentVersionthe current version of the application (e.g., "1.0.0.0")
updateButtonthe button to toggle enabled state based on update status
Returns
a SwingWorker that returns true if the version is up-to-date,
false
if an update is available
+ Here is the call graph for this function:

◆ npeCheckLatestVersion()

SwingWorker< Boolean, Void > fr.softsf.canscan.service.VersionService.npeCheckLatestVersion ( String currentVersion,
JButton updateButton )
private

Validates input for version check.

If null, returns a fallback SwingWorker that disables the update button; otherwise returns null.

Parameters
currentVersioncurrent app version
updateButtonbutton to toggle state
Returns
fallback worker if input is null; null otherwise
+ Here is the call graph for this function:

◆ requestAndVerify()

Boolean fr.softsf.canscan.service.VersionService.requestAndVerify ( String currentVersion) throws IOException, InterruptedException
private

Sends an HTTP request to the GitHub tags API and verifies if the latest release tag matches the current version.

Parameters
currentVersionthe current version of the application
Returns
true if the version is up-to-date or if verification fails; false if an update is available
Exceptions
IOExceptionif the request fails due to network issues
InterruptedExceptionif the thread is interrupted during the request

◆ updateButtonState()

void fr.softsf.canscan.service.VersionService.updateButtonState ( JButton button,
boolean enabled,
String tooltip )
private

Updates the state and tooltip of the given button based on application logic.

Parameters
buttonthe JButton to update
enabledwhether the button should be enabled
tooltipthe tooltip text to display on hover

Member Data Documentation

◆ CLOSE_HTML

final String fr.softsf.canscan.service.VersionService.CLOSE_HTML = "</html>"
staticprivate

◆ GITHUB_TAGS_API_URL

final String fr.softsf.canscan.service.VersionService.GITHUB_TAGS_API_URL
staticprivate
Initial value:
=
"https://api.github.com/repos/Lob2018/CanScan/tags"

◆ HTTP_STATUS_CODE_OK

final int fr.softsf.canscan.service.VersionService.HTTP_STATUS_CODE_OK = 200
staticprivate

◆ httpClient

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

◆ INSTANCE

fr.softsf.canscan.service.VersionService.INSTANCE

◆ LATEST_RELEASES_REPO_URL

final String fr.softsf.canscan.service.VersionService.LATEST_RELEASES_REPO_URL
staticprivate
Initial value:
=
"https://github.com/Lob2018/CanScan/releases/latest"

◆ TAG_PATTERN

final Pattern fr.softsf.canscan.service.VersionService.TAG_PATTERN = Pattern.compile("\"name\"\\s*:\\s*\"([^\"]+)\"")
staticprivate

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