Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions appinfo/app.php

This file was deleted.

75 changes: 16 additions & 59 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,75 +24,32 @@
namespace OCA\FirstRunWizard\AppInfo;

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\FirstRunWizard\Notification\AppHint;
use OCA\FirstRunWizard\Listener\AppEnabledListener;
use OCA\FirstRunWizard\Listener\BeforeFilesAppTemplateRenderedListener;
use OCA\FirstRunWizard\Listener\BeforeTemplateRenderedListener;
use OCA\FirstRunWizard\Notification\Notifier;
use OCP\App\ManagerEvent;
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\BeforeTemplateRenderedEvent;

class Application extends App {

/** @var bool */
protected $isCLI;
class Application extends App implements IBootstrap {

public function __construct() {
parent::__construct('firstrunwizard');
$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');
});

public function register(IRegistrationContext $context): void {
$context->registerEventListener(ManagerEvent::EVENT_APP_ENABLE, AppEnabledListener::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
// 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();
});
$context->registerEventListener(LoadAdditionalScriptsEvent::class, BeforeFilesAppTemplateRenderedListener::class);
}

protected function registerNotificationNotifier() {
$this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class);

/** @var AppHint $appHint */
$appHint = $this->getContainer()->query(AppHint::class);
$appHint->registerAppListener();
public function boot(IBootContext $context): void {
$serverContainer = $context->getServerContainer();
$serverContainer->getNotificationManager()->registerNotifierService(Notifier::class);
}
}
49 changes: 49 additions & 0 deletions lib/Listener/AppEnabledListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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\FirstRunWizard\Notification\AppHint;
use OCP\App\ManagerEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

class AppEnabledListener implements IEventListener {
/** @var AppHint */
private $appHint;

public function __construct(AppHint $appHint) {
$this->appHint = $appHint;
}

public function handle(Event $event): void {
if (!$event instanceof ManagerEvent) {
return;
}

$this->appHint->dismissNotification($event->getAppID());
}
}
73 changes: 73 additions & 0 deletions lib/Listener/BeforeFilesAppTemplateRenderedListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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\FirstRunWizard\Notification\AppHint;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\BackgroundJob\IJobList;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserSession;

class BeforeFilesAppTemplateRenderedListener 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 {
$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();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2016, Joas Schilling <coding@schilljs.com>
* @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Morris Jobke <hey@morrisjobke.de>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -17,22 +20,25 @@
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\FirstRunWizard\Tests\AppInfo;
namespace OCA\FirstRunWizard\Listener;

use Test\TestCase;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* Class AppPhpTest
*
* @package OCA\FirstRunWizard\Tests\AppInfo
*/
class AppPhpTest extends TestCase {
public function testRoutes() {
$void = include(__DIR__ . '/../../appinfo/app.php');
$this->assertSame(1, $void); // See http://de2.php.net/manual/de/function.include.php#example-137
class BeforeTemplateRenderedListener implements IEventListener {
public function __construct() {
}

public function handle(Event $event): void {
if (!$event instanceof BeforeTemplateRenderedEvent || !$event->isLoggedIn()) {
return;
}

\OC_Util::addScript('firstrunwizard', 'about');
}
}
16 changes: 2 additions & 14 deletions lib/Notification/AppHint.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
namespace OCA\FirstRunWizard\Notification;

use OCP\App\IAppManager;
use OCP\App\ManagerEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\Notification\IManager as INotificationManager;
Expand All @@ -44,20 +42,16 @@ class AppHint {
/** @var IConfig */
protected $config;

/** @var IEventDispatcher */
private $dispatcher;

/** @var string */
private $userId;

const APP_HINT_VERSION = '18';

public function __construct(INotificationManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IConfig $config, IEventDispatcher $eventDispatcher, $userId) {
public function __construct(INotificationManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IConfig $config, $userId) {
$this->notificationManager = $notificationManager;
$this->groupManager = $groupManager;
$this->appManager =$appManager;
$this->config = $config;
$this->dispatcher = $eventDispatcher;
$this->userId = $userId;
}

Expand All @@ -72,12 +66,6 @@ public function sendAppHintNotifications(): void {
}
}

public function registerAppListener(): void {
$this->dispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function(ManagerEvent $event) {
$this->dismissNotification($event->getAppID());
});
}

protected function sendNotification(string $app, string $user): void {
$notification = $this->generateNotification($app, $user);
if (
Expand All @@ -93,7 +81,7 @@ protected function sendNotification(string $app, string $user): void {
}
}

protected function dismissNotification(string $app) {
public function dismissNotification(string $app) {
$notification = $this->notificationManager->createNotification();
$notification->setApp('firstrunwizard')
->setSubject('apphint-'. $app)
Expand Down
Loading