Skip to content

Commit

Permalink
Added touch icon route (#370)
Browse files Browse the repository at this point in the history
* Added touch icon route

* fixed php style
  • Loading branch information
memurats authored Sep 30, 2024
1 parent 6c1aa95 commit 9eb32d9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@
'url' => '/mime/img/{iconname}.svg',
'verb' => 'GET',
],
[
'name' => 'TouchIcon#getTouchIcon',
'url' => '/touchicon/{app}',
'verb' => 'GET',
'defaults' => ['app' => 'nmctheme'],
],
]
];
52 changes: 52 additions & 0 deletions lib/Controller/TouchIconController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace OCA\NMCTheme\Controller;

use OC\IntegrityCheck\Helpers\FileAccessHelper;
use OCA\NMCTheme\AppInfo\Application;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\Response;
use OCP\IRequest;

class TouchIconController extends Controller {
/** @var FileAccessHelper */
private $fileAccessHelper;

/** @var IAppManager */
private $appManager;

public function __construct(
IRequest $request,
FileAccessHelper $fileAccessHelper,
IAppManager $appManager,
) {
parent::__construct(Application::APP_ID, $request);
$this->fileAccessHelper = $fileAccessHelper;
$this->appManager = $appManager;
}

/**
* Return a 512x512 icon for touch devices
*
* @PublicPage
* @NoCSRFRequired
*
* @param string $app ID of the app
* @return DataDisplayResponse<Http::STATUS_OK, array{Content-Type: 'image/png'}>|FileDisplayResponse<Http::STATUS_OK, array{Content-Type: 'image/x-icon'|'image/png'}>|NotFoundResponse<Http::STATUS_NOT_FOUND, array{}>
*
* 200: Touch icon returned
* 404: Touch icon not found
*/
public function getTouchIcon(string $app = 'core'): Response {

$touchIconPath = $this->appManager->getAppPath(Application::APP_ID) . "/img/";
$iconFile = $this->fileAccessHelper->file_get_contents($touchIconPath . 'favicon-touch.png');
$response = new DataDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']);
$response->cacheFor(86400);

return $response;
}
}
4 changes: 4 additions & 0 deletions lib/URLGeneratorDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function __construct(IURLGenerator $decorated) {
* No decoration, only delegate.
*/
public function linkToRoute(string $routeName, array $arguments = []): string {
if ($routeName === 'theming.Icon.getTouchIcon') {
return $this->decorated->linkToRoute('nmctheme.TouchIcon.getTouchIcon', $arguments);
}

return $this->decorated->linkToRoute($routeName, $arguments);
}

Expand Down

0 comments on commit 9eb32d9

Please sign in to comment.