add config proxy

This commit is contained in:
Simon Vieille 2020-09-22 14:24:53 +02:00
parent 7b5e92f83e
commit 40e883841e
Signed by: deblan
GPG key ID: 03383D15A1D31745
4 changed files with 52 additions and 51 deletions

View file

@ -6,6 +6,7 @@ use OC;
use OC\Security\CSP\ContentSecurityPolicyNonceManager;
use OC\User\User;
use OCA\SideMenu\Service\AppRepository;
use OCA\SideMenu\Service\ConfigProxy;
use OCP\AppFramework\App;
use OCP\IUserSession;
use OCP\Util;
@ -73,6 +74,10 @@ class Application extends App
$container->registerService('AppRepository', function (ContainerInterface $c) {
return new AppRepository(new OC_App());
});
$container->registerService('ConfigProxy', function (ContainerInterface $c) {
return new ConfigProxy($this->config);
});
}
/**

View file

@ -27,11 +27,12 @@ use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
use OCA\SideMenu\AppInfo\Application;
use OCA\SideMenu\Service\ConfigProxy;
class CssController extends Controller
{
/**
* @var \OCP\IConfig
* @var ConfigProxy
*/
protected $config;
@ -45,7 +46,7 @@ class CssController extends Controller
* @param IRequest $request
* @param IConfig $config
*/
public function __construct($appName, IRequest $request, IConfig $config)
public function __construct($appName, IRequest $request, ConfigProxy $config)
{
parent::__construct($appName, $request);
@ -70,13 +71,13 @@ class CssController extends Controller
protected function getConfig(): array
{
$backgroundColor = $this->config->getAppValue(Application::APP_ID, 'background-color', '#333333');
$backgroundColorTo = $this->config->getAppValue(Application::APP_ID, 'background-color-to', $backgroundColor);
$backgroundColor = $this->config->getAppValue('background-color', '#333333');
$backgroundColorTo = $this->config->getAppValue('background-color-to', $backgroundColor);
$topMenuApps = (array) json_decode($this->config->getAppValue(Application::APP_ID, 'top-menu-apps', '[]'), true);
$topMenuApps = $this->config->getAppValueArray('top-menu-apps', '[]');
if ($this->user) {
$userTopMenuApps = (array) json_decode($this->config->getUserValue($this->user->getUid(), Application::APP_ID, 'top-menu-apps', '[]'), true);
$userTopMenuApps = $this->config->getUserValueArray($this->user, 'top-menu-apps', '[]');
if (!empty($userTopMenuApps)) {
$topMenuApps = $userTopMenuApps;
@ -87,20 +88,20 @@ class CssController extends Controller
'vars' => [
'background-color' => $backgroundColor,
'background-color-to' => $backgroundColorTo,
'current-app-background-color' => $this->config->getAppValue(Application::APP_ID, 'current-app-background-color', '#444444'),
'loader-color' => $this->config->getAppValue(Application::APP_ID, 'loader-color', '#0e75ac'),
'text-color' => $this->config->getAppValue(Application::APP_ID, 'text-color', '#FFFFFF'),
'opener' => $this->config->getAppValue(Application::APP_ID, 'opener', 'side-menu-opener'),
'icon-invert-filter' => abs((int) $this->config->getAppValue(Application::APP_ID, 'icon-invert-filter', '0')).'%',
'icon-opacity' => abs((int) $this->config->getAppValue(Application::APP_ID, 'icon-opacity', '100') / 100),
'current-app-background-color' => $this->config->getAppValue('current-app-background-color', '#444444'),
'loader-color' => $this->config->getAppValue('loader-color', '#0e75ac'),
'text-color' => $this->config->getAppValue('text-color', '#FFFFFF'),
'opener' => $this->config->getAppValue('opener', 'side-menu-opener'),
'icon-invert-filter' => abs($this->config->getAppValueInt('icon-invert-filter', '0')).'%',
'icon-opacity' => abs($this->config->getAppValueInt('icon-opacity', '100') / 100),
],
'display-logo' => (bool) $this->config->getAppValue(Application::APP_ID, 'display-logo', 1),
'opener-only' => (bool) $this->config->getAppValue(Application::APP_ID, 'opener-only', 0),
'external-sites-in-top-menu' => (bool) $this->config->getAppValue(Application::APP_ID, 'external-sites-in-top-menu', 0),
'size-icon' => $this->config->getAppValue(Application::APP_ID, 'size-icon', 'normal'),
'size-text' => $this->config->getAppValue(Application::APP_ID, 'size-text', 'normal'),
'always-displayed' => (bool) $this->config->getAppValue(Application::APP_ID, 'always-displayed', '0'),
'big-menu' => (bool) $this->config->getAppValue(Application::APP_ID, 'big-menu', '0'),
'display-logo' => $this->config->getAppValueBool('display-logo', 1),
'opener-only' => $this->config->getAppValueBool('opener-only', 0),
'external-sites-in-top-menu' => $this->config->getAppValueBool('external-sites-in-top-menu', 0),
'size-icon' => $this->config->getAppValue('size-icon', 'normal'),
'size-text' => $this->config->getAppValue('size-text', 'normal'),
'always-displayed' => $this->config->getAppValueBool('always-displayed', '0'),
'big-menu' => $this->config->getAppValueBool('big-menu', '0'),
'top-menu-apps' => $topMenuApps,
];
}

View file

@ -28,11 +28,12 @@ use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
use OCA\SideMenu\AppInfo\Application;
use OCA\SideMenu\Service\ConfigProxy;
class JsController extends Controller
{
/**
* @var \OCP\IConfig
* @var ConfigProxy
*/
protected $config;
@ -49,10 +50,10 @@ class JsController extends Controller
/**
* @param string $appName
* @param IRequest $request
* @param IConfig $config
* @param ConfigProxy $config
* @param ThemingDefaults $themingDefaults
*/
public function __construct($appName, IRequest $request, IConfig $config, ThemingDefaults $themingDefaults)
public function __construct($appName, IRequest $request, ConfigProxy $config, ThemingDefaults $themingDefaults)
{
parent::__construct($appName, $request);
@ -87,20 +88,20 @@ class JsController extends Controller
protected function getConfig(): array
{
$topMenuApps = (array) json_decode($this->config->getAppValue(Application::APP_ID, 'top-menu-apps', '[]'), true);
$targetBlankApps = (array) json_decode($this->config->getAppValue(Application::APP_ID, 'target-blank-apps', '[]'), true);
$useAvatar = (bool) $this->config->getAppValue(Application::APP_ID, 'use-avatar', '0');
$topMenuApps = $this->config->getAppValueArray('top-menu-apps', '[]');
$targetBlankApps = $this->config->getAppValueArray('target-blank-apps', '[]');
$useAvatar = $this->config->getAppValueBool('use-avatar', '0');
$avatar = null;
if ($this->user) {
$userTopMenuApps = (array) json_decode($this->config->getUserValue($this->user->getUid(), Application::APP_ID, 'top-menu-apps', '[]'), true);
$userTopMenuApps = $this->config->getUserValueArray($this->user, 'top-menu-apps', '[]');
if (!empty($userTopMenuApps)) {
$topMenuApps = $userTopMenuApps;
}
$userTargetBlankMode = (int) $this->config->getUserValue($this->user->getUid(), Application::APP_ID, 'target-blank-mode', '1');
$userTargetBlankApps = (array) json_decode($this->config->getUserValue($this->user->getUid(), Application::APP_ID, 'target-blank-apps', '[]'), true);
$userTargetBlankMode = $this->config->getUserValueInt($this->user, 'target-blank-mode', '1');
$userTargetBlankApps = $this->config->getUserValueArray($this->user, 'target-blank-apps', '[]');
if (2 === $userTargetBlankMode) {
$targetBlankApps = $userTargetBlankApps;
@ -113,21 +114,21 @@ class JsController extends Controller
'core.avatar.getAvatar', [
'userId' => $this->user->getUid(),
'size' => 128,
'v' => $this->config->getUserValue($this->user, 'avatar', 'version', 0),
'v' => $this->config->getUserValueInt($this->user, 'avatar', 'version', 0),
]
);
}
}
return [
'opener-position' => $this->config->getAppValue(Application::APP_ID, 'opener-position', 'before'),
'opener-hover' => (bool) $this->config->getAppValue(Application::APP_ID, 'opener-hover', '0'),
'external-sites-in-top-menu' => (bool) $this->config->getAppValue(Application::APP_ID, 'external-sites-in-top-menu', 0),
'force-light-icon' => (bool) $this->config->getAppValue(Application::APP_ID, 'force-light-icon', '0'),
'hide-when-no-apps' => (bool) $this->config->getAppValue(Application::APP_ID, 'hide-when-no-apps', '0'),
'loader-enabled' => (bool) $this->config->getAppValue(Application::APP_ID, 'loader-enabled', '1'),
'always-displayed' => (bool) $this->config->getAppValue(Application::APP_ID, 'always-displayed', '0'),
'big-menu' => (bool) $this->config->getAppValue(Application::APP_ID, 'big-menu', '0'),
'opener-position' => $this->config->getAppValue('opener-position', 'before'),
'opener-hover' => $this->config->getAppValueBool('opener-hover', '0'),
'external-sites-in-top-menu' => $this->config->getAppValueBool('external-sites-in-top-menu', 0),
'force-light-icon' => $this->config->getAppValueBool('force-light-icon', '0'),
'hide-when-no-apps' => $this->config->getAppValueBool('hide-when-no-apps', '0'),
'loader-enabled' => $this->config->getAppValueBool('loader-enabled', '1'),
'always-displayed' => $this->config->getAppValueBool('always-displayed', '0'),
'big-menu' => $this->config->getAppValueBool('big-menu', '0'),
'avatar' => $avatar,
'top-menu-apps' => $topMenuApps,
'target-blank-apps' => $targetBlankApps,

View file

@ -21,20 +21,20 @@ namespace OCA\SideMenu\Controller;
use OC;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\URLGenerator;
use OCA\SideMenu\AppInfo\Application;
use OCA\SideMenu\Service\AppRepository;
use OCA\SideMenu\Service\ConfigProxy;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCA\SideMenu\AppInfo\Application;
class NavController extends Controller
{
/**
* @var IConfig
* @var ConfigProxy
*/
protected $config;
@ -59,19 +59,13 @@ class NavController extends Controller
protected $router;
/**
* @param string $appName
* @param IRequest $request
* @param string $appName
* @param IConfig $config
* @param AppRepository $appRepository
* @param CategoryFetcher $categoryFetcher
* @param URLGenerator $router
* @param IL10N $trans
* @param IFactory $l10nFactory
*/
public function __construct(
$appName,
IRequest $request,
IConfig $config,
ConfigProxy $config,
AppRepository $appRepository,
CategoryFetcher $categoryFetcher,
URLGenerator $router,
@ -99,7 +93,7 @@ class NavController extends Controller
$apps = $this->appRepository->getVisibleApps();
$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
$categoriesLabels = $this->categoryFetcher->get();
$externalSitesInTopMenu = (bool) $this->config->getAppValue(Application::APP_ID, 'external-sites-in-top-menu', 0);
$externalSitesInTopMenu = $this->config->getAppValueBool('external-sites-in-top-menu', 0);
$user = OC::$server[IUserSession::class]->getUser();
$appsCategories = [];
$categoriesAppsCount = [];
@ -111,8 +105,8 @@ class NavController extends Controller
]);
}
$topMenuApps = (array) json_decode($this->config->getAppValue(Application::APP_ID, 'top-menu-apps', '[]'), true);
$userTopMenuApps = (array) json_decode($this->config->getUserValue($user->getUid(), Application::APP_ID, 'top-menu-apps', '[]'), true);
$topMenuApps = $this->config->getAppValueArray('top-menu-apps', '[]');
$userTopMenuApps = $this->config->getUserValueArray($user, 'top-menu-apps', '[]');
if (!empty($userTopMenuApps)) {
$topMenuApps = $userTopMenuApps;