1
0
Fork 0
mirror of https://github.com/mwalbeck/nextcloud-breeze-dark.git synced 2025-07-07 19:51:58 +00:00

Compare commits

...

3 commits

Author SHA1 Message Date
9cebb71eb2
Update Changelog and bump version number 2024-08-04 15:31:09 +02:00
3d4e92bc8a
Also migrate enforced theme settings
(cherry picked from commit 4c85966ff0)
2024-08-04 15:28:48 +02:00
9810a95c49
Switch to using BeforeTemplateRenderedListener for injecting theme metadata into body tag ()
Switch to using BeforeTemplateRenderedListener for injecting theme metadata into body tag, instead of trying to use the theming app for it. Use the dark theme for enforcement instead, as the theming app now requires the enforced app to be a valid theme.

(cherry picked from commit 157f777dc8)
2024-08-04 15:28:43 +02:00
12 changed files with 561 additions and 325 deletions

View file

@ -12,7 +12,7 @@ jobs:
- name: Run prettier
if: ${{ always() }}
run: npm run prettier
- name: Run stylelint
continue-on-error: true
if: ${{ always() }}
run: npm run stylelint
# - name: Run stylelint
# continue-on-error: true
# if: ${{ always() }}
# run: npm run stylelint

2
.vscode/launch.json vendored
View file

@ -10,7 +10,7 @@
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html/lib/public": "${workspaceFolder}/vendor/christophwurst/nextcloud/OCP",
"/var/www/html/lib/public": "${workspaceFolder}/vendor/nextcloud/ocp/OCP",
"/var/www/html/custom_apps/breezedark": "${workspaceFolder}/../breezedark"
}
}

View file

@ -2,6 +2,12 @@
## [Unreleased]
## 28.0.1 - 2024-08-04
### Fixed
- [#344](https://github.com/mwalbeck/nextcloud-breeze-dark/issues/344) Error "Enforced theme not found" while it works correctly
## 28.0.0 - 2024-04-12
### Added

View file

@ -38,7 +38,7 @@ Settings > Personal > Appearance and accessibility > Breeze Dark
Under the Theming section in the admin settings you can add your own custom styling to the theme. Only standard CSS can be used. This custom styling will be applied whenever the theme is enabled and only affects the Breeze Dark theme.
]]></description>
<version>28.0.0</version>
<version>28.0.1</version>
<licence>agpl</licence>
<author mail="mw@mwalbeck.org" homepage="https://github.com/mwalbeck/nextcloud-breeze-dark">Magnus Walbeck</author>
<namespace>BreezeDark</namespace>

View file

@ -8,6 +8,6 @@
"require": {},
"require-dev": {
"nextcloud/coding-standard": "^0.5.0",
"christophwurst/nextcloud": "^22"
"nextcloud/ocp": "^28"
}
}

696
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -36,6 +36,8 @@ use OCP\IConfig;
use OCP\IUserSession;
use OCP\Util;
use OCP\IURLGenerator;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCA\BreezeDark\Listener\BeforeTemplateRenderedListener;
class Application extends App implements IBootstrap
{
@ -54,6 +56,7 @@ class Application extends App implements IBootstrap
public function register(IRegistrationContext $context): void
{
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
}
public function boot(IBootContext $context): void

View file

@ -74,10 +74,8 @@ class SettingsController extends Controller
if (!$themeEnforced) {
if ($this->request->getParam("theme_enabled")) {
$this->config->setUserValue($this->userId, $this->appName, "theme_enabled", "1");
$this->toggleTheme("on");
} else {
$this->config->setUserValue($this->userId, $this->appName, "theme_enabled", "0");
$this->toggleTheme("off");
}
}
@ -130,25 +128,10 @@ class SettingsController extends Controller
}
}
public function toggleTheme($state): void
{
$enabledThemes = json_decode($this->config->getUserValue($this->userId, "theming", "enabled-themes", "[]"));
if ($state === "on") {
$enabledThemes = array_merge(["breezedark"], $enabledThemes);
$this->config->setUserValue($this->userId, "theming", "enabled-themes", json_encode(array_values(array_unique($enabledThemes))));
}
if ($state === "off") {
$enabledThemes = array_diff($enabledThemes, ["breezedark"]);
$this->config->setUserValue($this->userId, "theming", "enabled-themes", json_encode(array_values(array_unique($enabledThemes))));
}
}
public function enforceTheme($state): void
{
if ($state === "on") {
$this->config->setSystemValue("enforce_theme", "breezedark");
$this->config->setSystemValue("enforce_theme", "dark");
}
if ($state === "off") {

View file

@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
/**
* Breeze Dark theme for Nextcloud
*
* @copyright Copyright (C) 2023 Magnus Walbeck <mw@mwalbeck.org>
*
* @author Magnus Walbeck <mw@mwalbeck.org>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\BreezeDark\Listener;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use OCP\IUserSession;
class BeforeTemplateRenderedListener implements IEventListener {
protected $appName;
private IUserSession $userSession;
private IConfig $config;
public function __construct(
IUserSession $userSession,
IConfig $config
) {
$this->appName = "breezedark";
$this->userSession = $userSession;
$this->config = $config;
}
public function handle(Event $event): void {
$response = $event->getResponse();
$themeEnforced = $this->config->getAppValue($this->appName, 'theme_enforced', "0");
$params = $response->getParams();
if ($themeEnforced) {
$params = array_merge(["enabledThemes" => ["breezedark", "dark"]], $params);
$response->setParams($params);
return;
}
if ($response->getRenderAs() === TemplateResponse::RENDER_AS_USER) {
$userId = $this->userSession->getUser()->getUID();
$themeEnabled = $this->config->getUserValue($userId, $this->appName, "theme_enabled", "0");
if ($themeEnabled) {
$enabledThemes = json_decode($this->config->getUserValue($userId, "theming", "enabled-themes", "[]"));
$enabledThemes = array_merge(["breezedark"], $enabledThemes);
$params = array_merge(["enabledThemes" => $enabledThemes], $params);
$response->setParams($params);
}
}
}
}

View file

@ -30,7 +30,6 @@ namespace OCA\BreezeDark\Migration;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
@ -55,31 +54,15 @@ class InstallRestoreSettings implements IRepairStep
public function run(IOutput $output): void
{
$userQb = $this->db->getQueryBuilder();
$userQb->select('userid')->from('preferences')->where(
$userQb->expr()->eq('appid', $userQb->createNamedParameter('breezedark'), IQueryBuilder::PARAM_STR),
$userQb->expr()->eq('configkey', $userQb->createNamedParameter('theme_enabled')),
$userQb->expr()->eq('configvalue', $userQb->createNamedParameter('1'))
);
$result = $userQb->executeQuery();
$users = $result->fetchAll();
foreach($users as $user) {
$enabledThemes = json_decode($this->config->getUserValue($user["userid"], "theming", "enabled-themes", "[]"));
$enabledThemes = array_merge(["breezedark"], $enabledThemes);
$this->config->setUserValue($user["userid"], "theming", "enabled-themes", json_encode(array_values(array_unique($enabledThemes))));
}
$themeEnforced = $this->config->getAppValue("breezedark", "theme_enforced", "0");
$currentEnforcedTheme = $this->config->getSystemValue("enforce_theme", "");
if ($themeEnforced && $currentEnforcedTheme === "") {
// Re-enable enforcement of the theme if no enforced theme is currently set
$this->config->setSystemValue("enforce_theme", "breezedark");
} elseif ($themeEnforced && $currentEnforcedTheme !== "breezedark") {
$this->config->setSystemValue("enforce_theme", "dark");
} elseif ($themeEnforced && $currentEnforcedTheme !== "dark") {
// Disable theme enforcement of breezedark if a theme other than
// breezedark is currently being enforced
// the one breezedark set is currently being enforced
$this->config->setAppValue("breezedark", "theme_enforced", "0");
}
}

View file

@ -57,7 +57,7 @@ class MigrateUserThemeSettings implements IRepairStep
{
$settingsVersion = $this->config->getAppValue("breezedark", "theme_settings_version", "0");
if ($settingsVersion >= "2") {
if ($settingsVersion >= "3") {
return;
}
@ -73,10 +73,22 @@ class MigrateUserThemeSettings implements IRepairStep
foreach($users as $user) {
$enabledThemes = json_decode($this->config->getUserValue($user["userid"], "theming", "enabled-themes", "[]"));
$enabledThemes = array_merge(["breezedark"], $enabledThemes);
$key = array_search("breezedark", $enabledThemes);
if ($key !== false) {
unset($enabledThemes[$key]);
}
$this->config->setUserValue($user["userid"], "theming", "enabled-themes", json_encode(array_values(array_unique($enabledThemes))));
}
$this->config->setAppValue("breezedark", "theme_settings_version", "2");
$currentEnforcedTheme = $this->config->getSystemValue("enforce_theme", "");
if ($currentEnforcedTheme === "breezedark") {
$this->config->setSystemValue("enforce_theme", "dark");
}
$this->config->setAppValue("breezedark", "theme_settings_version", "3");
}
}

View file

@ -30,7 +30,6 @@ namespace OCA\BreezeDark\Migration;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
@ -55,37 +54,16 @@ class UninstallCleanup implements IRepairStep
public function run(IOutput $output): void
{
$userQb = $this->db->getQueryBuilder();
$userQb->select('userid')->from('preferences')->where(
$userQb->expr()->eq('appid', $userQb->createNamedParameter('breezedark'), IQueryBuilder::PARAM_STR),
$userQb->expr()->eq('configkey', $userQb->createNamedParameter('theme_enabled')),
$userQb->expr()->eq('configvalue', $userQb->createNamedParameter('1'))
);
$result = $userQb->executeQuery();
$users = $result->fetchAll();
foreach($users as $user) {
$enabledThemes = json_decode($this->config->getUserValue($user["userid"], "theming", "enabled-themes", "[]"));
$key = array_search("breezedark", $enabledThemes);
if ($key !== false) {
unset($enabledThemes[$key]);
}
$this->config->setUserValue($user["userid"], "theming", "enabled-themes", json_encode(array_values(array_unique($enabledThemes))));
}
$themeEnforced = $this->config->getAppValue("breezedark", "theme_enforced", "0");
$currentEnforcedTheme = $this->config->getSystemValue("enforce_theme", "");
// Disable enforcement of the theme if the current enforced theme is breezedark
if ($themeEnforced && $currentEnforcedTheme === "breezedark") {
// Disable enforcement of the theme if the current enforced theme
// is the one set by breezedark
if ($themeEnforced && $currentEnforcedTheme === "dark") {
$this->config->setSystemValue("enforce_theme", "");
} elseif ($themeEnforced && $currentEnforcedTheme !== "breezedark") {
} elseif ($themeEnforced && $currentEnforcedTheme !== "dark") {
// Disable theme enforcement of breezedark if a theme other than
// breezedark is currently being enforced
// the one breezedark set is currently being enforced
$this->config->setAppValue("breezedark", "theme_enforced", "0");
}
}