Add the theme option #InstanceTicker

This commit is contained in:
noellabo 2022-02-21 06:32:59 +09:00
parent 9232ce30f3
commit b5ae6d4b27
15 changed files with 73 additions and 7 deletions

View file

@ -78,6 +78,7 @@ class Settings::PreferencesController < Settings::BaseController
:setting_hide_followers_count,
:setting_disable_joke_appearance,
:setting_new_features_policy,
:setting_theme_instance_ticker,
notification_emails: %i(follow follow_request reblog favourite emoji_reaction mention digest report pending_account trending_tag),
interactions: %i(must_be_follower must_be_following must_be_following_dm)
)

View file

@ -169,6 +169,18 @@ module ApplicationHelper
text.split("\n").map { |line| '> ' + line }.join("\n")
end
INSTANCE_TICKER_URL = {
'none' => '',
'type-0' => 'https://34.si/330/0.css',
'type-1' => 'https://34.si/330/1.css',
'type-2' => 'https://34.si/330/2.css',
'type-3' => 'https://34.si/330/3.css',
}.freeze
def instance_ticker_css
INSTANCE_TICKER_URL[current_user&.setting_theme_instance_ticker]
end
def render_initial_state
state_params = {
settings: {

View file

@ -72,6 +72,7 @@ class UserSettingsDecorator
user.settings['hide_followers_count'] = hide_followers_count_preference if change?('setting_hide_followers_count')
user.settings['disable_joke_appearance'] = disable_joke_appearance_preference if change?('setting_disable_joke_appearance')
user.settings['new_features_policy'] = new_features_policy if change?('setting_new_features_policy')
user.settings['theme_instance_ticker'] = theme_instance_ticker if change?('setting_theme_instance_ticker')
end
def merged_notification_emails
@ -246,6 +247,10 @@ class UserSettingsDecorator
settings['setting_new_features_policy']
end
def theme_instance_ticker
settings['setting_theme_instance_ticker']
end
def boolean_cast_setting(key)
ActiveModel::Type::Boolean.new.cast(settings[key])
end

View file

@ -133,6 +133,7 @@ class User < ApplicationRecord
:show_reply_tree_button,
:hide_statuses_count, :hide_following_count, :hide_followers_count, :disable_joke_appearance,
:new_features_policy,
:theme_instance_ticker,
to: :settings, prefix: :setting, allow_nil: false

View file

@ -57,6 +57,7 @@ class InitialStateSerializer < ActiveModel::Serializer
store[:show_reply_tree_button] = object.current_account.user.setting_show_reply_tree_button
store[:disable_joke_appearance] = object.current_account.user.setting_disable_joke_appearance
store[:new_features_policy] = object.current_account.user.setting_new_features_policy
store[:theme_instance_ticker] = object.current_account.user.setting_theme_instance_ticker
else
store[:auto_play_gif] = Setting.auto_play_gif
store[:display_media] = Setting.display_media

View file

@ -30,6 +30,9 @@
= stylesheet_link_tag '/inert.css', skip_pipeline: true, media: 'all', id: 'inert-style'
- if instance_ticker_css.present?
= stylesheet_link_tag instance_ticker_css, skip_pipeline: true, media: 'all'
- if Setting.custom_css.present?
= stylesheet_link_tag custom_css_path, host: request.host, media: 'all'

View file

@ -5,16 +5,22 @@
= button_tag t('generic.save_changes'), class: 'button', form: 'edit_user'
= simple_form_for current_user, url: settings_preferences_appearance_path, html: { method: :put, id: 'edit_user' } do |f|
.fields-row
.fields-group.fields-row__column.fields-row__column-6
= f.input :locale, collection: I18n.available_locales, wrapper: :with_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, selected: I18n.locale, hint: false
.fields-group.fields-row__column.fields-row__column-6
= f.input :setting_theme, collection: Themes.instance.names, label_method: lambda { |theme| I18n.t("themes.#{theme}", default: theme) }, wrapper: :with_label, include_blank: false, hint: false
.fields-group.fields-row__column-6
= f.input :locale, collection: I18n.available_locales, wrapper: :with_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, selected: I18n.locale, hint: false
- unless I18n.locale == :en
.flash-message.translation-prompt
#{t 'appearance.localization.body'} #{content_tag(:a, t('appearance.localization.guide_link_text'), href: t('appearance.localization.guide_link'), target: "_blank", rel: "noopener")}
%h4= t 'appearance.themes'
.fields-row
.fields-row__column.fields-row__column-6
= f.input :setting_theme, collection: Themes.instance.names, label_method: lambda { |theme| I18n.t("themes.#{theme}", default: theme) }, wrapper: :with_label, include_blank: false, hint: true
.fields-row__column.fields-row__column-6
= f.input :setting_theme_instance_ticker, collection: ['none', 'type-0', 'type-1', 'type-2', 'type-3'], label_method: lambda { |item| t("simple_form.hints.defaults.setting_theme_instance_ticker_#{item}") }, wrapper: :with_label, include_blank: false, hint: t('simple_form.hints.defaults.setting_theme_instance_ticker_html'), fedibird_features: true
%h4= t 'appearance.advanced_web_interface'
%p.hint= t 'appearance.advanced_web_interface_hint'

View file

@ -16,7 +16,7 @@ media_host ||= host_to_url(ENV['S3_CLOUDFRONT_HOST'])
media_host ||= host_to_url(ENV['S3_HOSTNAME']) if ENV['S3_ENABLED'] == 'true'
media_host ||= assets_host
instance_ticker_host = 'https://inst.ance.tk'
instance_ticker_host = 'https://34.si'
github_host = "https://raw.githubusercontent.com" # GitHub
google_fonts_host = "https://fonts.gstatic.com" # Google Fonts

View file

@ -768,6 +768,7 @@ en:
guide_link: https://crowdin.com/project/mastodon
guide_link_text: Everyone can contribute.
sensitive_content: Sensitive content
themes: Themes
toot_layout: Post layout
application_mailer:
notification_preferences: Change e-mail preferences

View file

@ -746,6 +746,7 @@ ja:
guide_link: https://ja.crowdin.com/project/mastodon
guide_link_text: 誰でも参加することができます。
sensitive_content: 閲覧注意コンテンツ
themes: テーマ
toot_layout: 投稿のレイアウト
application_mailer:
notification_preferences: メール設定の変更

View file

@ -78,6 +78,13 @@ en:
setting_show_tab_bar_label: When adding a list etc. to the tab bar, it is recommended to display the label because it is not possible to distinguish by the icon alone
setting_show_followed_by: "The color of the follow button changes according to the follow status (gray: no follow relationship, yellow: followed, blue: following, green: mutual follow)"
setting_show_target: Enable the function to switch between posting target and follow / subscribe target
setting_theme: Change the site's coloring, buttons, and other design elements
setting_theme_instance_ticker_html: Display the poster's server information in the post (<a href="https://34.si/" target="_blank" rel="noopener noreferrer">#InstanceTicker</a>)
setting_theme_instance_ticker_none: None
setting_theme_instance_ticker_type-0: Type-0 (SNS LOGO)
setting_theme_instance_ticker_type-1: Type-1 (Favicon)
setting_theme_instance_ticker_type-2: Type-2 (Favicon + BG White)
setting_theme_instance_ticker_type-3: Type-3 (Favicon + BG Black)
setting_use_blurhash: Gradients are based on the colors of the hidden visuals but obfuscate any details
setting_use_pending_items: Hide timeline updates behind a click instead of automatically scrolling the feed
username: Your username will be unique on %{domain}
@ -230,6 +237,7 @@ en:
setting_show_target: Enable targeting features
setting_system_font_ui: Use system's default font
setting_theme: Site theme
setting_theme_instance_ticker: '#InstanceTicker'
setting_trends: Show today's trends
setting_unfollow_modal: Show confirmation dialog before unfollowing someone
setting_unsubscribe_modal: Show confirmation dialog before unsubscribing someone

View file

@ -78,6 +78,13 @@ ja:
setting_show_tab_bar_label: リスト等をタブバーに追加する場合、アイコンだけでは区別がつかないので、ラベルを表示することをおすすめします
setting_show_followed_by: フォロー状態に応じてフォローボタンの色が変わります(灰色:フォロー関係なし、黄色:フォローされている、青色:フォローしている、緑色:相互フォロー)
setting_show_target: 投稿対象と、フォロー・購読の対象を切り替える機能を有効にします
setting_theme: サイトのカラーリングやボタンなどのデザインを変更します
setting_theme_instance_ticker_html: 投稿に投稿者のサーバ情報を表示します(<a href="https://34.si/" target="_blank" rel="noopener noreferrer">#InstanceTicker</a>
setting_theme_instance_ticker_none: なし
setting_theme_instance_ticker_type-0: Type-0 (SNSロゴ)
setting_theme_instance_ticker_type-1: Type-1 (Favicon)
setting_theme_instance_ticker_type-2: Type-2 (Favicon + 白背景)
setting_theme_instance_ticker_type-3: Type-3 (Favicon + 黒背景)
setting_use_blurhash: ぼかしはメディアの色を元に生成されますが、細部は見えにくくなっています
setting_use_pending_items: 新着があってもタイムラインを自動的にスクロールしないようにします
username: あなたのユーザー名は %{domain} の中で重複していない必要があります
@ -230,6 +237,7 @@ ja:
setting_show_target: ターゲット機能を有効にする
setting_system_font_ui: システムのデフォルトフォントを使う
setting_theme: サイトテーマ
setting_theme_instance_ticker: インスタンス・ティッカー
setting_trends: 本日のトレンドタグを表示する
setting_unfollow_modal: フォローを解除する前に確認ダイアログを表示する
setting_unsubscribe_modal: 購読を解除する前に確認ダイアログを表示する

View file

@ -32,6 +32,7 @@ defaults: &defaults
system_font_ui: false
noindex: false
theme: 'default'
theme_instance_ticker: 'none'
aggregate_reblogs: true
advanced_layout: false
use_blurhash: true

View file

@ -0,0 +1,18 @@
class MigrateInstanceTickerTheme < ActiveRecord::Migration[6.1]
THEME_CONVERSION = {
nil => 'default',
'contrast' => 'contrast',
'light' => 'mastodon-light',
}.freeze
def up
result = ActiveRecord::Base.connection.select_all("select u.id, (regexp_matches(s.value, '--- instance-ticker-(type-[0123])'))[1] as type, (regexp_matches(s.value, '--- instance-ticker-type-[0123]-?(contrast|light)'))[1] as theme from users u join settings s on s.thing_id = u.id where s.thing_type = 'User' and var = 'theme' and value ~ '--- instance-ticker-type-[0123]-?(contrast|light)?'").each do |row|
User.find(row['id']).settings['theme_instance_ticker'] = row['type']
User.find(row['id']).settings['theme'] = THEME_CONVERSION[row['theme']]
end
end
def down
# nothing to do
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_02_02_115057) do
ActiveRecord::Schema.define(version: 2022_02_21_014129) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"