diff --git a/README.md b/README.md index b1686e0..03a77a1 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,14 @@ Users can disable the menu using the page of personal settings. Use the shortcut `Ctrl`+`o` to open and to hide the side menu. Use `tab` to navigate. +### Use first top menu app as default app + +You can easily let Nextcloud redirect to the first top menu app by changing the following parameter in your `config/config.php`: + +``` +'defaultapp' => 'side_menu', +``` + How to contribute? ------------------ diff --git a/appinfo/routes.php b/appinfo/routes.php index 1efd4b6..bdc3fba 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -19,6 +19,7 @@ return [ 'routes' => [ + ['name' => 'App#index', 'url' => '/', 'verb' => 'GET'], ['name' => 'Css#stylesheet', 'url' => '/css/stylesheet', 'verb' => 'GET'], ['name' => 'Js#script', 'url' => '/js/script', 'verb' => 'GET'], ['name' => 'Js#config', 'url' => '/js/config', 'verb' => 'GET'], diff --git a/lib/Controller/AppController.php b/lib/Controller/AppController.php new file mode 100644 index 0000000..1d3de92 --- /dev/null +++ b/lib/Controller/AppController.php @@ -0,0 +1,102 @@ +. + */ + +namespace OCA\SideMenu\Controller; + +use OC; +use OCA\SideMenu\Service\AppRepository; +use OCA\SideMenu\Service\ConfigProxy; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\RedirectResponse; +use OCP\IRequest; +use OCP\IURLGenerator; +use OCP\IUserSession; + +class AppController extends Controller +{ + /** + * @var ConfigProxy + */ + protected $config; + + /** + * @var AppRepository + */ + protected $appRepository; + + public function __construct( + string $appName, + IRequest $request, + AppRepository $appRepository, + IURLGenerator $urlGenerator, + ConfigProxy $config + ) { + parent::__construct($appName, $request); + + $this->appRepository = $appRepository; + $this->urlGenerator = $urlGenerator; + $this->config = $config; + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function index(): RedirectResponse + { + $user = OC::$server[IUserSession::class]->getUser(); + $topMenuApps = $this->config->getAppValueArray('top-menu-apps', '[]'); + $hiddenApps = $this->config->getAppValueArray('big-menu-hidden-apps', '[]'); + $isForced = $this->config->getAppValueBool('force', '0'); + $userTopMenuApps = $this->config->getUserValueArray($user, 'top-menu-apps', '[]'); + $apps = $this->appRepository->getOrderedApps($user); + + if (!$isForced && !empty($userTopMenuApps)) { + $topMenuApps = $userTopMenuApps; + } + + foreach ($apps as $app) { + $inTopMenuApps = in_array($app['id'], $topMenuApps); + $inHiddenApps = in_array($app['id'], $hiddenApps); + + if (!$inTopMenuApps || $inHiddenApps) { + continue; + } + + return $this->redirectToApp($app['id']); + } + + return $this->redirectToApp('files'); + } + + protected function redirectToApp($appId): RedirectResponse + { + $isIgnoreFrontController = true === OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false); + $isFrontControllerActive = 'true' === getenv('front_controller_active'); + + if ($isIgnoreFrontController || $isFrontControllerActive) { + $path = '/apps/%s/'; + } else { + $path = '/index.php/apps/%s/'; + } + + $url = $this->urlGenerator->getAbsoluteURL(sprintf($path, $appId)); + + return new RedirectResponse($url); + } +}