Skip to content

Commit b48573c

Browse files
committed
style: 应用安装二维码支持黑暗模式
1 parent ae7147d commit b48573c

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

app/controllers/releases/qrcode_controller.rb

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,42 @@
33
class Releases::QrcodeController < ApplicationController
44
before_action :set_release
55

6-
LIGHT_BACKGROUND_COLOR = 'FFFFFF'
7-
LIGHT_COLOR = '465960'
6+
THEMES = {
7+
light: {
8+
fill: '#FFFFFF',
9+
color: '#465960'
10+
},
11+
dark: {
12+
fill: '#343a40',
13+
color: '#F0F4Fb'
14+
},
15+
}
816

917
##
1018
# 显示应用的二维码
1119
# GET /apps/:slug/(:version)/qrcode
1220
def show
13-
options = {
14-
module_px_size: qrcode_size,
15-
fill: "##{params.fetch(:fill, LIGHT_BACKGROUND_COLOR)}",
16-
color: "##{params.fetch(:color, LIGHT_COLOR)}"
17-
}
18-
1921
render qrcode: friendly_channel_release_url(@release.channel, @release), **options
2022
end
2123

2224
private
2325

24-
def qrcode_size
26+
def options
27+
{
28+
module_px_size: px_size,
29+
fill: theme[:fill],
30+
color: theme[:color]
31+
}
32+
end
33+
34+
def theme
35+
@theme ||= -> do
36+
name = params.fetch(:theme, 'light') == 'light' ? :light : :dark
37+
THEMES[name]
38+
end.call
39+
end
40+
41+
def px_size
2542
case params[:size]
2643
when 'thumb'
2744
3

app/helpers/apps_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,18 @@ def channel_platform(channel)
8282
def changelog_format(changelog, **options)
8383
simple_format changelog, **options
8484
end
85+
86+
def qrcode_image_tag(release)
87+
logger.debug Setting.site_appearance
88+
logger.debug "Sdfsafasdfasdfsadfd"
89+
if Setting.site_appearance != 'auto'
90+
return image_tag channel_release_qrcode_path(@release.channel, @release, size: :large, theme: Setting.site_appearance)
91+
end
92+
93+
content_tag(:picture) do
94+
content_tag(:source, media: "(prefers-color-scheme: dark)", srcset: channel_release_qrcode_path(release.channel, release, size: :large, theme: :dark)) do
95+
image_tag channel_release_qrcode_path(release.channel, release, size: :large)
96+
end
97+
end
98+
end
8599
end

app/views/releases/sidebar/_qrcode.html.slim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
i.fas.fa-minus
99
.card-body.text-center.p-0
1010
.qr_code
11-
= image_tag channel_release_qrcode_path(@release.channel, @release, size: :large)
11+
= qrcode_image_tag(@release)
12+
/ picture
13+
/ source srcset="#{channel_release_qrcode_path(@release.channel, @release, size: :large, theme: :dark)}" media="(prefers-color-scheme: dark)"
14+
/ = image_tag channel_release_qrcode_path(@release.channel, @release, size: :large)
1215
.card-footer.text-center = t('releases.show.scan_qrcode_with_any_suppprted_app')

0 commit comments

Comments
 (0)