Skip to content

Commit c8d7a5a

Browse files
committed
fix(AppManager): Allow to query dark **or** bright icon
The navigation needs the bright icon, while the notifications and activity need a dark icon. Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent b6691b3 commit c8d7a5a

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

apps/updatenotification/lib/Notification/AppUpdateNotifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public function prepare(INotification $notification, string $languageCode): INot
8484
// Prepare translation factory for requested language
8585
$l = $this->l10nFactory->get(Application::APP_NAME, $languageCode);
8686

87-
$icon = $this->appManager->getAppIcon($appId);
87+
$icon = $this->appManager->getAppIcon($appId, true);
8888
if ($icon === null) {
89-
$icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
89+
$icon = $this->urlGenerator->imagePath('core', 'actions/change.svg');
9090
}
9191

9292
$action = $notification->createAction();

lib/private/App/AppManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public function __construct(
109109
) {
110110
}
111111

112-
public function getAppIcon(string $appId): ?string {
113-
$possibleIcons = [$appId . '.svg', 'app.svg', $appId . '-dark.svg', 'app-dark.svg'];
112+
public function getAppIcon(string $appId, bool $dark = false): ?string {
113+
$possibleIcons = $dark ? [$appId . '-dark.svg', 'app-dark.svg'] : [$appId . '.svg', 'app.svg'];
114114
$icon = null;
115115
foreach ($possibleIcons as $iconName) {
116116
try {

lib/public/App/IAppManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ public function getAppVersion(string $appId, bool $useCache = true): string;
6565
* Returns the app icon or null if none is found
6666
*
6767
* @param string $appId
68+
* @param bool $dark Enable to request a dark icon variant, default is a white icon
6869
* @return string|null
6970
* @since 29.0.0
7071
*/
71-
public function getAppIcon(string $appId): string|null;
72+
public function getAppIcon(string $appId, bool $dark = false): string|null;
7273

7374
/**
7475
* Check if an app is enabled for user

tests/lib/App/AppManagerTest.php

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,16 @@ protected function setUp(): void {
135135
/**
136136
* @dataProvider dataGetAppIcon
137137
*/
138-
public function testGetAppIcon($callback, string|null $expected) {
138+
public function testGetAppIcon($callback, ?bool $dark, string|null $expected) {
139139
$this->urlGenerator->expects($this->atLeastOnce())
140140
->method('imagePath')
141141
->willReturnCallback($callback);
142142

143-
$this->assertEquals($expected, $this->manager->getAppIcon('test'));
143+
if ($dark !== null) {
144+
$this->assertEquals($expected, $this->manager->getAppIcon('test', $dark));
145+
} else {
146+
$this->assertEquals($expected, $this->manager->getAppIcon('test'));
147+
}
144148
}
145149

146150
public function dataGetAppIcon(): array {
@@ -162,36 +166,59 @@ public function dataGetAppIcon(): array {
162166
return [
163167
'does not find anything' => [
164168
$nothing,
169+
false,
170+
null,
171+
],
172+
'nothing if request dark but only bright available' => [
173+
$createCallback(['app.svg']),
174+
true,
165175
null,
166176
],
167-
'only app.svg' => [
177+
'nothing if request bright but only dark available' => [
178+
$createCallback(['app-dark.svg']),
179+
false,
180+
null,
181+
],
182+
'bright and only app.svg' => [
168183
$createCallback(['app.svg']),
184+
false,
169185
'/path/app.svg',
170186
],
171-
'only app-dark.svg' => [
187+
'dark and only app-dark.svg' => [
172188
$createCallback(['app-dark.svg']),
189+
true,
173190
'/path/app-dark.svg',
174191
],
175-
'only appname -dark.svg' => [
192+
'dark only appname -dark.svg' => [
176193
$createCallback(['test-dark.svg']),
194+
true,
177195
'/path/test-dark.svg',
178196
],
179-
'only appname.svg' => [
197+
'bright and only appname.svg' => [
180198
$createCallback(['test.svg']),
199+
false,
181200
'/path/test.svg',
182201
],
183202
'priotize custom over default' => [
184203
$createCallback(['app.svg', 'test.svg']),
204+
false,
185205
'/path/test.svg',
186206
],
187-
'priotize default over dark' => [
188-
$createCallback(['test-dark.svg', 'app-dark.svg', 'app.svg']),
189-
'/path/app.svg',
207+
'defaults to bright' => [
208+
$createCallback(['test-dark.svg', 'test.svg']),
209+
null,
210+
'/path/test.svg',
190211
],
191-
'priotize custom over default' => [
192-
$createCallback(['test.svg', 'test-dark.svg', 'app-dark.svg']),
212+
'no dark icon on default' => [
213+
$createCallback(['test-dark.svg', 'test.svg', 'app-dark.svg', 'app.svg']),
214+
false,
193215
'/path/test.svg',
194216
],
217+
'no bright icon on dark' => [
218+
$createCallback(['test-dark.svg', 'test.svg', 'app-dark.svg', 'app.svg']),
219+
true,
220+
'/path/test-dark.svg',
221+
],
195222
];
196223
}
197224

0 commit comments

Comments
 (0)