Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/firstrunwizard.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-07-14 04:43:58 +0300
committerMorris Jobke <hey@morrisjobke.de>2020-07-14 04:43:58 +0300
commit9980fd09cbc8e5968f660be755ea6bfdc7906509 (patch)
treefdd8e284d723197892c067093e3eb2c9a1f50a9d /lib
parentfe9d5c42746a4d57945416dd8970f51758adda7c (diff)
Use IBootstrap for the app
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php74
-rw-r--r--lib/Listener/LoadAdditionalScriptsListener.php77
-rw-r--r--lib/Listener/LoadAdditionalScriptsLoggedInListener.php41
3 files changed, 138 insertions, 54 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 4379d00e..0ea0a526 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -24,20 +24,17 @@
namespace OCA\FirstRunWizard\AppInfo;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCA\FirstRunWizard\Listener\LoadAdditionalScriptsListener;
+use OCA\FirstRunWizard\Listener\LoadAdditionalScriptsLoggedInListener;
use OCA\FirstRunWizard\Notification\AppHint;
use OCA\FirstRunWizard\Notification\Notifier;
use OCP\AppFramework\App;
-use OCP\AppFramework\Http\TemplateResponse;
-use OCP\EventDispatcher\IEventDispatcher;
-use OCP\IConfig;
-use OCP\IInitialStateService;
-use OCP\IL10N;
-use OCP\IServerContainer;
-use OCP\IUser;
-use OCP\IUserSession;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use OCP\AppFramework\Bootstrap\IBootContext;
+use OCP\AppFramework\Bootstrap\IBootstrap;
+use OCP\AppFramework\Bootstrap\IRegistrationContext;
+use OCP\AppFramework\Http\Events\LoadAdditionalScriptsLoggedInEvent;
-class Application extends App {
+class Application extends App implements IBootstrap {
/** @var bool */
protected $isCLI;
@@ -47,52 +44,21 @@ class Application extends App {
$this->isCLI = \OC::$CLI;
}
- public function register() {
- if (!$this->isCLI) {
- $this->registerScripts();
- $this->registerNotificationNotifier();
- }
- }
-
- protected function registerScripts() {
- /** @var IServerContainer $server */
- $server = $this->getContainer()->getServer();
- /** @var IEventDispatcher $dispatcher */
- $dispatcher = $server->query(IEventDispatcher::class);
-
- $dispatcher->addListener(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, function() {
- \OC_Util::addScript('firstrunwizard', 'about');
- });
-
- // Display the first run wizard only on the files app,
- $dispatcher->addListener(LoadAdditionalScriptsEvent::class, function() use ($server) {
- /** @var IUserSession $userSession */
- $userSession = $this->getContainer()->query(IUserSession::class);
- $user = $userSession->getUser();
-
- if (!$user instanceof IUser) {
- return;
- }
-
- /** @var IConfig $config */
- $config = $this->getContainer()->query(IConfig::class);
- $appHint = $this->getContainer()->query(AppHint::class);
-
- if ($config->getUserValue($user->getUID(), 'firstrunwizard', 'show', '1') !== '0') {
- \OC_Util::addScript('firstrunwizard', 'activate');
-
- $jobList = $this->getContainer()->getServer()->getJobList();
- $jobList->add('OCA\FirstRunWizard\Notification\BackgroundJob', ['uid' => $userSession->getUser()->getUID()]);
- }
- $appHint->sendAppHintNotifications();
- });
+ public function register(IRegistrationContext $context): void {
+ // Display the first run wizard only on the files app
+ $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScriptsListener::class);
+ $context->registerEventListener(LoadAdditionalScriptsLoggedInEvent::class, LoadAdditionalScriptsLoggedInListener::class);
}
- protected function registerNotificationNotifier() {
- $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class);
+ public function boot(IBootContext $context): void {
+ if (!$this->isCLI) {
+ $serverContainer = $context->getServerContainer();
+ $serverContainer->getNotificationManager()->registerNotifierService(Notifier::class);
- /** @var AppHint $appHint */
- $appHint = $this->getContainer()->query(AppHint::class);
- $appHint->registerAppListener();
+ $appContainer = $context->getAppContainer();
+ /** @var AppHint $appHint */
+ $appHint = $appContainer->query(AppHint::class);
+ $appHint->registerAppListener();
+ }
}
}
diff --git a/lib/Listener/LoadAdditionalScriptsListener.php b/lib/Listener/LoadAdditionalScriptsListener.php
new file mode 100644
index 00000000..b9bccab3
--- /dev/null
+++ b/lib/Listener/LoadAdditionalScriptsListener.php
@@ -0,0 +1,77 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de>
+ *
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @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\FirstRunWizard\Listener;
+
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCA\FirstRunWizard\Notification\AppHint;
+use OCP\BackgroundJob\IJobList;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\IConfig;
+use OCP\IUser;
+use OCP\IUserSession;
+
+class LoadAdditionalScriptsListener implements IEventListener {
+ /** @var IUserSession */
+ private $userSession;
+ /** @var IConfig */
+ private $config;
+ /** @var AppHint */
+ private $appHint;
+ /** @var IJobList */
+ private $jobList;
+
+ public function __construct(
+ IConfig $config,
+ IUserSession $userSession,
+ IJobList $jobList,
+ AppHint $appHint
+ ) {
+ $this->userSession = $userSession;
+ $this->config = $config;
+ $this->appHint = $appHint;
+ $this->jobList = $jobList;
+ }
+
+ public function handle(Event $event): void {
+ if (!($event instanceof LoadAdditionalScriptsEvent)) {
+ return;
+ }
+
+ $user = $this->userSession->getUser();
+ if (!$user instanceof IUser) {
+ return;
+ }
+
+ if ($this->config->getUserValue($user->getUID(), 'firstrunwizard', 'show', '1') !== '0') {
+ \OC_Util::addScript('firstrunwizard', 'activate');
+
+ $this->jobList->add('OCA\FirstRunWizard\Notification\BackgroundJob', ['uid' => $this->userSession->getUser()->getUID()]);
+ }
+ $this->appHint->sendAppHintNotifications();
+ }
+}
diff --git a/lib/Listener/LoadAdditionalScriptsLoggedInListener.php b/lib/Listener/LoadAdditionalScriptsLoggedInListener.php
new file mode 100644
index 00000000..ae39c66e
--- /dev/null
+++ b/lib/Listener/LoadAdditionalScriptsLoggedInListener.php
@@ -0,0 +1,41 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de>
+ *
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @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\FirstRunWizard\Listener;
+
+use OCP\AppFramework\Http\Events\LoadAdditionalScriptsLoggedInEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+class LoadAdditionalScriptsLoggedInListener implements IEventListener {
+ public function handle(Event $event): void {
+ if (!($event instanceof LoadAdditionalScriptsLoggedInEvent)) {
+ return;
+ }
+
+ \OC_Util::addScript('firstrunwizard', 'about');
+ }
+}