Skip to content

Commit

Permalink
Add "update available" indicator to footer (#517)
Browse files Browse the repository at this point in the history
This checks the latest released version of Whoogle against
the current app version, and shows an "update available"
message if the current version num < latest release num.

Closes #305
  • Loading branch information
vacom13 authored Nov 2, 2021
1 parent b73c14c commit 3784d89
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
2 changes: 2 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
app.config['BANG_FILE'] = os.path.join(
app.config['BANG_PATH'],
'bangs.json')
app.config['RELEASES_URL'] = 'https://github.com/' \
'benbusby/whoogle-search/releases'

# The alternative to Google Translate is treated a bit differently than other
# social media site alternatives, in that it is used for any translation
Expand Down
14 changes: 13 additions & 1 deletion app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@
from bs4 import BeautifulSoup as bsoup
from flask import jsonify, make_response, request, redirect, render_template, \
send_file, session, url_for
from requests import exceptions
from requests import exceptions, get

# Load DDG bang json files only on init
bang_json = json.load(open(app.config['BANG_FILE']))


# Check the newest version of WHOOGLE
update = bsoup(get(app.config['RELEASES_URL']).text, 'html.parser')
newest_version = update.select_one('[class="Link--primary"]').string[1:]
current_version = int(''.join(filter(str.isdigit,
app.config['VERSION_NUMBER'])))
newest_version = int(''.join(filter(str.isdigit, newest_version)))
newest_version = '' if current_version >= newest_version \
else newest_version


def auth_required(f):
@wraps(f)
def decorated(*args, **kwargs):
Expand Down Expand Up @@ -137,6 +147,7 @@ def index():
return render_template('error.html', error_message=error_message)

return render_template('index.html',
newest_version=newest_version,
languages=app.config['LANGUAGES'],
countries=app.config['COUNTRIES'],
themes=app.config['THEMES'],
Expand Down Expand Up @@ -261,6 +272,7 @@ def search():

return render_template(
'display.html',
newest_version=newest_version,
query=urlparse.unquote(query),
search_type=search_util.search_type,
config=g.user_config,
Expand Down
2 changes: 1 addition & 1 deletion app/static/css/dark-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,6 @@ path {
color: var(--whoogle-dark-text) !important;
}

.ip-text-div{
.ip-text-div, .update_available {
color: var(--whoogle-dark-secondary-text) !important;
}
2 changes: 1 addition & 1 deletion app/static/css/light-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,6 @@ path {
border-bottom: 0px;
}

.ip-text-div{
.ip-text-div, .update_available {
color: var(--whoogle-secondary-text) !important;
}
7 changes: 1 addition & 6 deletions app/templates/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@
{% endif %}
{{ response|safe }}
</body>
<footer>
<p class="footer">
Whoogle Search v{{ version_number }} ||
<a id="gh-link" href="https://github.com/benbusby/whoogle-search">{{ translation['github-link'] }}</a>
</p>
</footer>
{% include 'footer.html' %}
<script src="{{ cb_url('autocomplete.js') }}"></script>
<script src="{{ cb_url('utils.js') }}"></script>
<script src="{{ cb_url('keyboard.js') }}"></script>
Expand Down
9 changes: 9 additions & 0 deletions app/templates/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<footer>
<p class="footer">
Whoogle Search v{{ version_number }} ||
<a id="gh-link" href="https://github.com/benbusby/whoogle-search">{{ translation['github-link'] }}</a>
{% if newest_version %}
|| <span class="update_available">Update Available 🟢</span>
{% endif %}
</p>
</footer>
7 changes: 1 addition & 6 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,6 @@
</div>
{% endif %}
</div>
<footer>
<p class="footer">
Whoogle Search v{{ version_number }} ||
<a id="gh-link" href="https://github.com/benbusby/whoogle-search">{{ translation['github-link'] }}</a>
</p>
</footer>
{% include 'footer.html' %}
</body>
</html>

0 comments on commit 3784d89

Please sign in to comment.