settings: Extract code for checking night-mode setting.

We extract the code for checking night mode setting on
the basis of color_scheme value and using matchMedia when
color_scheme is set to automatic. This is currently used
in rendering the correct logo only.

This is a prep commit for fixing loading indicator not
visible on message-edit button in night-mode.
This commit is contained in:
sahil839
2021-07-08 16:44:17 +05:30
committed by Tim Abbott
parent 8ffe22fc15
commit a3f7639af3
3 changed files with 39 additions and 9 deletions

View File

@@ -158,3 +158,18 @@ export function user_can_edit_topic_of_any_message() {
}
return user_has_permission(page_params.realm_edit_topic_policy);
}
export function using_dark_theme() {
if (page_params.color_scheme === settings_config.color_scheme_values.night.code) {
return true;
}
if (
page_params.color_scheme === settings_config.color_scheme_values.automatic.code &&
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
) {
return true;
}
return false;
}