Skip to content

Commit 4680a29

Browse files
committed
WIP: try to generate user themed icons
Signed-off-by: Simon L <szaimen@e.mail.de>
1 parent 102617f commit 4680a29

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

apps/theming/lib/Controller/IconController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ public function __construct(
8686
* @throws \Exception
8787
*/
8888
public function getThemedIcon(string $app, string $image): Response {
89+
$color = $this->themingDefaults->getColorPrimary();
8990
try {
90-
$iconFile = $this->imageManager->getCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image));
91+
$iconFile = $this->imageManager->getCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image) . $color);
9192
} catch (NotFoundException $exception) {
9293
$icon = $this->iconBuilder->colorSvg($app, $image);
9394
if ($icon === false || $icon === '') {
9495
return new NotFoundResponse();
9596
}
96-
$iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image), $icon);
97+
$iconFile = $this->imageManager->setCachedImage('icon-' . $app . '-' . str_replace('/', '_',$image) . $color, $icon);
9798
}
9899
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
99100
$response->cacheFor(86400, false, true);

apps/theming/lib/Service/JSDataService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,26 @@
3030
use OCA\Theming\ThemingDefaults;
3131
use OCA\Theming\Util;
3232
use OCP\IConfig;
33+
use OCP\IUserSession;
3334

3435
class JSDataService implements \JsonSerializable {
3536
private ThemingDefaults $themingDefaults;
3637
private Util $util;
3738
private IConfig $appConfig;
39+
private IUserSession $userSession;
3840
private ThemesService $themesService;
3941

4042
public function __construct(
4143
ThemingDefaults $themingDefaults,
4244
Util $util,
4345
IConfig $appConfig,
46+
IUserSession $userSession,
4447
ThemesService $themesService
4548
) {
4649
$this->themingDefaults = $themingDefaults;
4750
$this->util = $util;
4851
$this->appConfig = $appConfig;
52+
$this->userSession = $userSession;
4953
$this->themesService = $themesService;
5054
}
5155

@@ -60,6 +64,7 @@ public function jsonSerialize(): array {
6064
'privacyUrl' => $this->themingDefaults->getPrivacyUrl(),
6165
'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()),
6266
'cacheBuster' => $this->appConfig->getAppValue(Application::APP_ID, 'cachebuster', '0'),
67+
'userCacheBuster' => $this->util->getUserCacheBuster(Application::APP_ID, $this->appConfig, $this->userSession),
6368
'enabledThemes' => $this->themesService->getEnabledThemes(),
6469
];
6570
}

apps/theming/lib/ThemingDefaults.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ public function replaceImagePath($app, $image) {
420420
}
421421

422422
if ($route) {
423+
$userCacheBusterValue = $this->util->getUserCacheBuster(Application::APP_ID, $this->config, $this->userSession);
424+
$cacheBusterValue = '';
425+
if ($userCacheBusterValue) {
426+
$cacheBusterValue = $userCacheBusterValue;
427+
}
423428
return $route . '?v=' . $cacheBusterValue;
424429
}
425430

apps/theming/lib/Util.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OCP\Files\NotFoundException;
3535
use OCP\Files\SimpleFS\ISimpleFile;
3636
use OCP\IConfig;
37+
use OCP\IUserSession;
3738
use Mexitek\PHPColors\Color;
3839

3940
class Util {
@@ -266,4 +267,14 @@ public function isBackgroundThemed() {
266267
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
267268
return $backgroundLogo !== '' && $backgroundLogo !== 'backgroundColor';
268269
}
270+
271+
public function getUserCacheBuster(string $appId, IConfig $config, ?IUserSession $user): string {
272+
$userId = $user->getUser() ? $user->getUser()->getUID() : '';
273+
$cacheBusterValue = '';
274+
if ($userId) {
275+
$userCacheBusterValue = (int)$config->getUserValue($userId, $appId, 'userCacheBuster', '0');
276+
$cacheBusterValue = substr(sha1($userId . '_' . $userCacheBusterValue), 0, 8);
277+
}
278+
return $cacheBusterValue;
279+
}
269280
}

core/js/mimetype.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ OC.MimeType = {
108108
path += '.svg';
109109

110110
if(OCA.Theming) {
111-
path += "?v=" + OCA.Theming.cacheBuster;
111+
if (OCA.Theming.userCacheBuster) {
112+
path += "?v=" + OCA.Theming.userCacheBuster;
113+
} else {
114+
path += "?v=" + OCA.Theming.cacheBuster;
115+
}
112116
}
113117

114118
// Cache the result

0 commit comments

Comments
 (0)