From d352aa01899f64681b11c96ca0d0d4ad185bb029 Mon Sep 17 00:00:00 2001 From: Ian Morland <16573496+imorland@users.noreply.github.com> Date: Sun, 12 Jun 2022 16:27:55 +0100 Subject: [PATCH] feat: Support new FoF/Default-User-Preferences (#61) * Support new FoF/Default-User-Preferences * Apply fixes from StyleCI Co-authored-by: StyleCI Bot --- composer.json | 5 ++++- extend.php | 6 ++++++ resources/locale/en.yml | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f567ca1..f1d4420 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,10 @@ }, "flagrow": { "discuss": "https://discuss.flarum.org/d/21492" - } + }, + "optional-dependencies": [ + "fof/default-user-preferences" + ] }, "autoload": { "psr-4": { diff --git a/extend.php b/extend.php index 064017f..2162927 100644 --- a/extend.php +++ b/extend.php @@ -12,7 +12,9 @@ namespace FoF\NightMode; use Flarum\Extend; +use Flarum\Extension\ExtensionManager; use Flarum\Settings\SettingsRepositoryInterface; +use FoF\DefaultUserPreferences\Extend\RegisterUserPreferenceDefault; return [ (new Extend\Frontend('forum')) @@ -54,4 +56,8 @@ }, false) ->serializeToForum('fofNightMode.showThemeToggleOnHeaderAlways', 'fofNightMode.show_theme_toggle_on_header_always', 'boolval', false) ->serializeToForum('fof-nightmode.default_theme', 'fof-nightmode.default_theme', 'intval', 0), + + class_exists(RegisterUserPreferenceDefault::class) && resolve(ExtensionManager::class)->isEnabled('fof-default-user-preferences') ? (new RegisterUserPreferenceDefault()) + ->default('fofNightMode', 0, 'number') + ->default('fofNightMode_perDevice', false, 'bool') : [], ]; diff --git a/resources/locale/en.yml b/resources/locale/en.yml index 95ca4df..c34de73 100755 --- a/resources/locale/en.yml +++ b/resources/locale/en.yml @@ -36,3 +36,11 @@ fof-nightmode: auto: Your theme will be automatically selected based on your browser or device settings. For example, if you have dark mode enabled in iOS, the forums will be dark too. day: The classic experience which you're used to. Loved and tested. night: You're a bit of a night owl. You watch over the forum at night, while the birds are sleeping and the foxes are hunting. Or you just prefer the darker colours! + +fof-default-user-preferences: + admin: + settings: + fofNightMode: "FoF Nightmode: Color theme to use by default" + fofNightMode-help: "0 - automatic, 1 - light mode, 2 - dark mode" + fofNightMode_perDevice: "FoF Nightmode: Use per device settings" + fofNightMode_perDevice-help: Use per device preferences for nightmode settings