Skip to content

Commit

Permalink
Add LoadViewer event
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Oct 26, 2019
1 parent f6794fe commit 7650c35
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 7 deletions.
9 changes: 2 additions & 7 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,5 @@

namespace OCA\Viewer\AppInfo;

$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener(
'OCA\Files::loadAdditionalScripts',
function() {
\OCP\Util::addScript('viewer', 'viewer');
}
);
// Query the app instance in the hope it's instantiated exactly once
OC::$server->query(\OCA\Viewer\AppInfo\Application::class);
46 changes: 46 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @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\Viewer\AppInfo;

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Viewer\Event\LoadViewer;
use OCA\Viewer\Listener\LoadViewerScript;
use OCP\AppFramework\App;
use OCP\EventDispatcher\IEventDispatcher;

class Application extends App {

const appID = 'viewer';

public function __construct() {
parent::__construct(self::appID);

// listen to sidebar loading event
$server = $this->getContainer()->getServer();
$eventDispatcher = $server->query(IEventDispatcher::class);
$eventDispatcher->addServiceListener(LoadViewer::class, LoadViewerScript::class);
$eventDispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadViewerScript::class);
}
}
28 changes: 28 additions & 0 deletions lib/Event/LoadViewer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, Roeland Jago Douma <[email protected]>
*
* @author Roeland Jago Douma <[email protected]>
*
* @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\Viewer\Event;

use OCP\EventDispatcher\Event;

class LoadViewer extends Event {}
41 changes: 41 additions & 0 deletions lib/Listener/LoadViewerScript.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @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\Viewer\Listener;

use OCA\Viewer\AppInfo\Application;
use OCA\Viewer\Event\LoadViewer;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

class LoadViewerScript implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof LoadViewer)) {
return;
}

Util::addScript(Application::appID, Application::appID);
}
}

0 comments on commit 7650c35

Please sign in to comment.