settings: Add automatic theme detection feature.

With this implementation of the feature of the automatic theme
detection, we make the following changes in the backend, frontend and
documentation.

This replaces the previous night_mode boolean with an enum, with the
default value being to use the prefers-color-scheme feature of the
operating system to determine which theme to use.

Fixes: #14451.

Co-authored-by: @kPerikou <44238834+kPerikou@users.noreply.github.com>
This commit is contained in:
MariaGkoulta
2020-05-16 14:13:59 +03:00
committed by Tim Abbott
parent 9bd8ead32d
commit b10f156250
25 changed files with 185 additions and 61 deletions

View File

@@ -0,0 +1,35 @@
# Generated by Django 2.2.13 on 2020-06-20 15:22
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
COLOR_SCHEME_AUTOMATIC = 1
COLOR_SCHEME_NIGHT = 2
# Set color_scheme to night mode, if night_mode is True.
def set_color_scheme_to_night_mode(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")
UserProfile.objects.filter(night_mode=True).update(color_scheme=COLOR_SCHEME_NIGHT)
class Migration(migrations.Migration):
dependencies = [
('zerver', '0289_tighten_attachment_size'),
]
operations = [
migrations.AddField(
model_name='userprofile',
name='color_scheme',
field=models.PositiveSmallIntegerField(default=COLOR_SCHEME_AUTOMATIC),
),
migrations.RunPython(
set_color_scheme_to_night_mode,
reverse_code=migrations.RunPython.noop,
elidable=True),
migrations.RemoveField(
model_name='userprofile',
name='night_mode',
),
]