add config proxy

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

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,