Added option to only notify about important updates

Added option to only notify about major updates. This setting is now the default and can be changed in the config by changing the setting "NOTIFY_UPDATES" from "major" to "all".

This setting was achieves by turning the previous if statement into an if-else statement with the new option. For this, I utilized a function that gets the latest tag from the GitHub repository.

I wasn't able to implement the 'if URL exists' check, the URL would just not return an error negating the function. I will probably fix this in the future, but as it is now, if the GitHub API server can't be reached this might trow an error.

The major release is still the previous update version retreated from the GitHub repository. This means I will only update that version for major or otherwise important updates. 

I implemented this feature because I didn't want to spam new users with a new update notification every other day.
This commit is contained in:
Julian Prieber 2022-04-04 17:46:32 +02:00
parent 5da15c0d65
commit 877dd8373f
3 changed files with 29 additions and 6 deletions

6
.env
View File

@ -2,9 +2,11 @@
#=REGISTER_AUTH either auth or verified. If auth is selected, no verification is required. Default is verified.
REGISTER_AUTH=verified
#Internal notifications=Notify if update is available or and event is happening such as a poll about the future of this project.
#Internal notifications=Changes if certain messages should be displayed or not
#=NOTIFY_EVENTS notifies admins if an important event is happening, such as polls about the future of this project or security vulnerabilities.
NOTIFY_EVENTS=true
NOTIFY_UPDATES=true
#=NOTIFY_UPDATES either all, major or false. All notifies about all updates, major only notifies about major or important updates, false does not notify about any updates.
NOTIFY_UPDATES=major
DISPLAY_FOOTER=true
DISPLAY_CREDIT=true

View File

@ -154,8 +154,27 @@
<div class="row">
<! #### begin update detection #### >
@if(env('NOTIFY_UPDATES') === true)
<?php // Checks if URL exists
@if(env('NOTIFY_UPDATES') == 'all' or env('NOTIFY_UPDATES') == 'true')
<! Checks if file version.json exists to continue (without this PHP will throw ErrorException ) >
@if(file_exists(base_path("version.json")))
<?php // Requests newest version from server and sets it as variable
ini_set('user_agent', 'Mozilla/4.0 (compatible; MSIE 6.0)');
$json = file_get_contents("https://api.github.com/repos/julianprieber/littlelink-custom/releases/latest") ;
$myObj = json_decode($json);
$Vgit = $myObj->tag_name;
// Requests current version from the local version file and sets it as variable
$Vlocal = 'v' . file_get_contents(base_path("version.json"));
?>
<! If user has role admin AND newest GitHub release version is higher than the local one an update notice will be displayed >
@if(auth()->user()->role == 'admin' and $Vgit > $Vlocal)
<a style="color:#007bff" class="nav-link" href="https://littlelink-custom.com/how-to-update.html" target="_blank" title="Click here to learn more about how to update">An update is available</a>
@endif
@endif
@elseif(env('NOTIFY_UPDATES') == 'major')
<?php // Checks if URL exists
try {
function URL_exists(string $url): bool
{

View File

@ -2,9 +2,11 @@
#=REGISTER_AUTH either auth or verified. If auth is selected, no verification is required. Default is verified.
REGISTER_AUTH=verified
#Internal notifications=Notify if update is available or and event is happening such as a poll about the future of this project.
#Internal notifications=Changes if certain messages should be displayed or not
#=NOTIFY_EVENTS notifies admins if an important event is happening, such as polls about the future of this project or security vulnerabilities.
NOTIFY_EVENTS=true
NOTIFY_UPDATES=true
#=NOTIFY_UPDATES either all, major or false. All notifies about all updates, major only notifies about major or important updates, false does not notify about any updates.
NOTIFY_UPDATES=major
DISPLAY_FOOTER=true
DISPLAY_CREDIT=true