mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Implement version check from github with 24 cache
This commit is contained in:
parent
bdfa75cf70
commit
efb4ecf19b
5 changed files with 31 additions and 2 deletions
1
.app_version
Normal file
1
.app_version
Normal file
|
|
@ -0,0 +1 @@
|
|||
0.1.7.4
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -56,4 +56,10 @@ module ApplicationHelper
|
|||
timestamp: DateTime.new(year, month).beginning_of_month..DateTime.new(year, month).end_of_month
|
||||
).exists?
|
||||
end
|
||||
|
||||
def new_version_available?
|
||||
Rails.cache.fetch('dawarich/app-version-check', expires_in: 1.day) do
|
||||
CheckAppVersion.new.call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
13
app/services/check_app_version.rb
Normal file
13
app/services/check_app_version.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CheckAppVersion
|
||||
def initialize
|
||||
@repo_url = 'https://api.github.com/repos/Freika/dawarich/tags'
|
||||
@app_version = File.read('.app_version').strip
|
||||
end
|
||||
|
||||
def call
|
||||
latest_version = JSON.parse(Net::HTTP.get(URI.parse(@repo_url)))[0]['name']
|
||||
latest_version == @app_version
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,16 @@
|
|||
</ul>
|
||||
</div>
|
||||
<%= link_to 'DaWarIch', root_path, class: 'btn btn-ghost normal-case text-xl'%>
|
||||
<div class="badge badge-neutral mx-4">0.1.7.3</div>
|
||||
<div class="badge mx-4 <%= 'badge-outline' if new_version_available? %> ">
|
||||
<a href="https://github.com/Freika/dawarich/releases/latest" target="_blank">
|
||||
0.1.7.3
|
||||
<% if new_version_available? %>
|
||||
<span class="tooltip tooltip-bottom" data-tip="Check out Github releases!">
|
||||
 New version available
|
||||
</span>
|
||||
<% end %>
|
||||
</a>
|
||||
</div>
|
||||
<label class="flex cursor-pointer gap-2">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="5"/><path d="M12 1v2M12 21v2M4.2 4.2l1.4 1.4M18.4 18.4l1.4 1.4M1 12h2M21 12h2M4.2 19.8l1.4-1.4M18.4 5.6l1.4-1.4"/></svg>
|
||||
<input type="checkbox" value="light" class="toggle theme-controller"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue