Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a setting allowing the use of system's default font in Web UI #4033

Merged
merged 14 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/settings/preferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def user_settings_params
:setting_boost_modal,
:setting_delete_modal,
:setting_auto_play_gif,
:setting_system_font_ui,
notification_emails: %i(follow follow_request reblog favourite mention digest),
interactions: %i(must_be_follower must_be_following)
)
Expand Down
14 changes: 12 additions & 2 deletions app/javascript/mastodon/features/ui/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import classNames from 'classnames';
import Switch from 'react-router-dom/Switch';
import Route from 'react-router-dom/Route';
import Redirect from 'react-router-dom/Redirect';
Expand Down Expand Up @@ -72,12 +73,17 @@ class WrappedRoute extends React.Component {

}

@connect()
const mapStateToProps = state => ({
systemFontUi: state.getIn(['meta', 'system_font_ui']),
});

@connect(mapStateToProps)
export default class UI extends React.PureComponent {

static propTypes = {
dispatch: PropTypes.func.isRequired,
children: PropTypes.node,
systemFontUi: PropTypes.bool,
};

state = {
Expand Down Expand Up @@ -176,8 +182,12 @@ export default class UI extends React.PureComponent {
const { width, draggingOver } = this.state;
const { children } = this.props;

const className = classNames('ui', {
'system-font': this.props.systemFontUi,
});

return (
<div className='ui' ref={this.setRef}>
<div className={className} ref={this.setRef}>
<TabsBar />
<ColumnsAreaContainer singleColumn={isMobile(width)}>
<WrappedSwitch>
Expand Down
15 changes: 15 additions & 0 deletions app/javascript/styles/basics.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,18 @@ button {
align-items: center;
justify-content: center;
}

.system-font {
// system-ui => standard property (Chrome/Android WebView 56+, Opera 43+, Safari 11+)
// -apple-system => Safari <11 specific
// BlinkMacSystemFont => Chrome <56 on macOS specific
// Segoe UI => Windows 7/8/10
// Oxygen => KDE
// Ubuntu => Unity/Ubuntu
// Cantarell => GNOME
// Fira Sans => Firefox OS
// Droid Sans => Older Androids (<4.0)
// Helvetica Neue => Older macOS <10.11
// Roboto => web-font fallback and newer Androids (>=4.0)
font-family: system-ui, -apple-system,BlinkMacSystemFont, "Segoe UI","Oxygen", "Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue","Roboto", sans-serif;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, the webfont for Roboto is actually called "mastodon-font-sans-serif" in our CSS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gargron I just fixed this. Sorry for the overlooking 😅

}
5 changes: 5 additions & 0 deletions app/lib/user_settings_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def process_update
user.settings['boost_modal'] = boost_modal_preference
user.settings['delete_modal'] = delete_modal_preference
user.settings['auto_play_gif'] = auto_play_gif_preference
user.settings['system_font_ui'] = system_font_ui_preference
end

def merged_notification_emails
Expand All @@ -43,6 +44,10 @@ def delete_modal_preference
boolean_cast_setting 'setting_delete_modal'
end

def system_font_ui_preference
boolean_cast_setting 'setting_system_font_ui'
end

def auto_play_gif_preference
boolean_cast_setting 'setting_auto_play_gif'
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def setting_auto_play_gif
settings.auto_play_gif
end

def setting_system_font_ui
settings.system_font_ui
end

def activate_session(request)
session_activations.activate(session_id: SecureRandom.hex,
user_agent: request.user_agent,
Expand Down
1 change: 1 addition & 0 deletions app/views/home/initial_state.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node(:meta) do
boost_modal: current_account.user.setting_boost_modal,
delete_modal: current_account.user.setting_delete_modal,
auto_play_gif: current_account.user.setting_auto_play_gif,
system_font_ui: current_account.user.setting_system_font_ui,
}
end

Expand Down
1 change: 1 addition & 0 deletions app/views/settings/preferences/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

.fields-group
= f.input :setting_auto_play_gif, as: :boolean, wrapper: :with_label
= f.input :setting_system_font_ui, as: :boolean, wrapper: :with_label

.actions
= f.button :button, t('generic.save_changes'), type: :submit
1 change: 1 addition & 0 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ en:
setting_boost_modal: Show confirmation dialog before boosting
setting_default_privacy: Post privacy
setting_delete_modal: Show confirmation dialog before deleting a toot
setting_system_font_ui: Use system's default font
severity: Severity
type: Import type
username: Username
Expand Down
1 change: 1 addition & 0 deletions config/locales/simple_form.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fr:
password: Mot de passe
setting_boost_modal: Afficher un dialogue de confirmation avant de partager
setting_default_privacy: Confidentialité des statuts
setting_system_font_ui: Utiliser la police par défaut du système
severity: Séverité
type: Type d'import
username: Identifiant
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defaults: &defaults
boost_modal: false
auto_play_gif: true
delete_modal: true
system_font_ui: false
notification_emails:
follow: false
reblog: false
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/user_settings_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,12 @@
settings.update(values)
expect(user.settings['auto_play_gif']).to eq false
end

it 'updates the user settings value for system font in UI' do
values = { 'setting_system_font_ui' => '0' }

settings.update(values)
expect(user.settings['system_font_ui']).to eq false
end
end
end
8 changes: 8 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@
expect(user.setting_auto_play_gif).to eq false
end
end

describe '#setting_system_font_ui' do
it 'returns system font ui setting' do
user = Fabricate(:user)
user.settings[:system_font_ui] = false
expect(user.setting_system_font_ui).to eq false
end
end

describe '#setting_boost_modal' do
it 'returns boost modal setting' do
Expand Down