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
2 changes: 1 addition & 1 deletion cypress/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ services:
environment:
CYPRESS_baseUrl:
APP_SOURCE:
BRANCH: stable19
BRANCH: master
volumes:
- ${APP_SOURCE}:/var/www/html/apps/text
86 changes: 17 additions & 69 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,85 +24,33 @@

namespace OCA\Text\AppInfo;

use OCA\Text\DirectEditing\TextDirectEditor;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Text\Listeners\FilesLoadAdditionalScriptsListener;
use OCA\Text\Listeners\FilesSharingLoadAdditionalScriptsListener;
use OCA\Text\Listeners\LoadViewerListener;
use OCA\Text\Listeners\RegisterDirectEditorEventListener;
use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\DirectEditing\RegisterDirectEditorEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IInitialStateService;

class Application extends App {


class Application extends App implements IBootstrap {
const APP_NAME = 'text';

/** @var IInitialStateService */
private $initialStateService;
/**
* @var \OCP\IUserSession
*/
private $userSession;
/**
* @var \OCP\IConfig
*/
private $config;


/**
* Application constructor.
*
* @param array $params
* @throws \OCP\AppFramework\QueryException
*/
public function __construct(array $params = []) {
parent::__construct(self::APP_NAME, $params);
}

$container = $this->getContainer();
$server = $container->getServer();
/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = $server->query(IEventDispatcher::class);
$this->initialStateService = $server->query(IInitialStateService::class);
$this->userSession = $server->getUserSession();
$this->config = $this->getContainer()->getServer()->getConfig();

$eventDispatcher->addListener(RegisterDirectEditorEvent::class, function (RegisterDirectEditorEvent $event) use ($container) {
$editor = $container->query(TextDirectEditor::class);
$event->register($editor);
});

$eventDispatcher->addListener(LoadViewer::class, function () {
\OCP\Util::addScript('text', 'viewer');
\OCP\Util::addStyle('text', 'icons');
});

if ($this->userSession->isLoggedIn()) {
$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function () {
\OCP\Util::addScript('text', 'files');
\OCP\Util::addStyle('text', 'icons');

$this->initialStateService->provideInitialState(
self::APP_NAME,
'workspace_available',
$this->config->getAppValue(self::APP_NAME, 'workspace_available', '1') === '1'
);
$this->initialStateService->provideInitialState(
self::APP_NAME,
'workspace_enabled',
$this->config->getUserValue($this->userSession->getUser()->getUID(), self::APP_NAME, 'workspace_enabled', '1') === '1'
);
});
}

$eventDispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function () {
\OCP\Util::addScript('text', 'public');
\OCP\Util::addStyle('text', 'icons');
$this->initialStateService->provideInitialState(
self::APP_NAME,
'workspace_available',
$this->config->getAppValue(self::APP_NAME, 'workspace_available', '1') === '1'
);
});
public function register(IRegistrationContext $context): void {
$context->registerEventListener(RegisterDirectEditorEvent::class, RegisterDirectEditorEventListener::class);
$context->registerEventListener(LoadViewer::class, LoadViewerListener::class);
$context->registerEventListener('OCA\Files_Sharing::loadAdditionalScripts', FilesSharingLoadAdditionalScriptsListener::class);
$context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesLoadAdditionalScriptsListener::class);
}

public function boot(IBootContext $context): void {
}
}

69 changes: 69 additions & 0 deletions lib/Listeners/FilesLoadAdditionalScriptsListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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\Text\Listeners;

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Text\AppInfo\Application;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\IUserSession;

class FilesLoadAdditionalScriptsListener implements IEventListener {
/** @var IConfig */
protected $config;
/** @var IInitialStateService */
protected $initialStateService;
/** @var IUserSession */
protected $userSession;

public function __construct(IConfig $config, IInitialStateService $initialStateService, IUserSession $userSession) {
$this->config = $config;
$this->initialStateService = $initialStateService;
$this->userSession = $userSession;
}

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

\OCP\Util::addScript('text', 'files');
\OCP\Util::addStyle('text', 'icons');

$this->initialStateService->provideInitialState(
Application::APP_NAME,
'workspace_available',
$this->config->getAppValue(Application::APP_NAME, 'workspace_available', '1') === '1'
);
$this->initialStateService->provideInitialState(
Application::APP_NAME,
'workspace_enabled',
$this->config->getUserValue($this->userSession->getUser()->getUID(), Application::APP_NAME, 'workspace_enabled', '1') === '1'
);
}
}
62 changes: 62 additions & 0 deletions lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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\Text\Listeners;

use OCA\Text\AppInfo\Application;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\IUserSession;

class FilesSharingLoadAdditionalScriptsListener implements IEventListener {
/** @var IConfig */
protected $config;
/** @var IInitialStateService */
protected $initialStateService;
/** @var IUserSession */
protected $userSession;

public function __construct(IConfig $config, IInitialStateService $initialStateService, IUserSession $userSession) {
$this->config = $config;
$this->initialStateService = $initialStateService;
$this->userSession = $userSession;
}

public function handle(Event $event): void {
if (!$this->userSession->isLoggedIn()) {
return;
}
\OCP\Util::addScript('text', 'public');
\OCP\Util::addStyle('text', 'icons');

$this->initialStateService->provideInitialState(
Application::APP_NAME,
'workspace_available',
$this->config->getAppValue(Application::APP_NAME, 'workspace_available', '1') === '1'
);
}
}
21 changes: 17 additions & 4 deletions appinfo/app.php → lib/Listeners/LoadViewerListener.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
* @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de>
*
* @author Julius Härtl <jus@bitgrid.net>
* @author Morris Jobke <hey@morrisjobke.de>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -22,6 +23,18 @@
*
*/

namespace OCA\Text\AppInfo;
namespace OCA\Text\Listeners;

use OCA\Viewer\Event\LoadViewer;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

$app = \OC::$server->query(Application::class);
class LoadViewerListener implements IEventListener {
public function handle(Event $event): void {
if (!$event instanceof LoadViewer) {
return;
}
\OCP\Util::addScript('text', 'viewer');
\OCP\Util::addStyle('text', 'icons');
}
}
47 changes: 47 additions & 0 deletions lib/Listeners/RegisterDirectEditorEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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\Text\Listeners;

use OCA\Text\DirectEditing\TextDirectEditor;
use OCP\DirectEditing\RegisterDirectEditorEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

class RegisterDirectEditorEventListener implements IEventListener {
/** @var TextDirectEditor */
protected $editor;

public function __construct(TextDirectEditor $editor) {
$this->editor = $editor;
}

public function handle(Event $event): void {
if (!$event instanceof RegisterDirectEditorEvent) {
return;
}
$event->register($this->editor);
}
}