diff --git a/app/Settings/AppSettingsStore.php b/app/Settings/AppSettingsStore.php index d830df639..e6fc466ba 100644 --- a/app/Settings/AppSettingsStore.php +++ b/app/Settings/AppSettingsStore.php @@ -51,6 +51,8 @@ class AppSettingsStore $this->destroyExistingSettingImage('app-icon-' . $size); setting()->remove('app-icon-' . $size); } + + $this->faviconHandler->restoreOriginal(); } } diff --git a/app/Uploads/FaviconHandler.php b/app/Uploads/FaviconHandler.php index 78c9a899b..f61e7ae64 100644 --- a/app/Uploads/FaviconHandler.php +++ b/app/Uploads/FaviconHandler.php @@ -17,19 +17,32 @@ class FaviconHandler */ public function saveForUploadedImage(UploadedFile $file): void { + $targetPath = public_path('favicon.ico'); + if (!is_writeable($targetPath)) { + return; + } + $imageData = file_get_contents($file->getRealPath()); $image = $this->imageTool->make($imageData); $image->resize(32, 32); $bmpData = $image->encode('bmp'); $icoData = $this->bmpToIco($bmpData, 32, 32); - // TODO - Below are test paths - file_put_contents(public_path('uploads/test.ico'), $icoData); - file_put_contents(public_path('uploads/test.bmp'), $bmpData); + file_put_contents($targetPath, $icoData); + } - // TODO - Permission check for icon overwrite - // TODO - Write to correct location - // TODO - Handle deletion and restore of original icon on user icon clear + /** + * Restore the original favicon image. + */ + public function restoreOriginal(): void + { + $targetPath = public_path('favicon.ico'); + $original = public_path('icon.ico'); + if (!is_writeable($targetPath)) { + return; + } + + copy($original, $targetPath); } /** diff --git a/public/favicon.ico b/public/favicon.ico index 41655ccba..e047657cc 100644 Binary files a/public/favicon.ico and b/public/favicon.ico differ diff --git a/public/icon.ico b/public/icon.ico new file mode 100644 index 000000000..41655ccba Binary files /dev/null and b/public/icon.ico differ diff --git a/tests/Settings/SettingsTest.php b/tests/Settings/SettingsTest.php index 30bb50f7c..fb952585a 100644 --- a/tests/Settings/SettingsTest.php +++ b/tests/Settings/SettingsTest.php @@ -52,6 +52,10 @@ class SettingsTest extends TestCase $this->assertFalse(setting()->get('app-icon-128')); $this->assertFalse(setting()->get('app-icon-64')); $this->assertFalse(setting()->get('app-icon-32')); + $this->assertEquals( + file_get_contents(public_path('icon.ico')), + file_get_contents(public_path('favicon.ico')), + ); $prevFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png')); @@ -71,6 +75,11 @@ class SettingsTest extends TestCase $resp = $this->get('/'); $this->withHtml($resp)->assertElementCount('link[sizes][href*="my-app-icon"]', 6); + $this->assertNotEquals( + file_get_contents(public_path('icon.ico')), + file_get_contents(public_path('favicon.ico')), + ); + $reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']); $reset->assertRedirect('/settings/customization'); @@ -81,5 +90,10 @@ class SettingsTest extends TestCase $this->assertFalse(setting()->get('app-icon-128')); $this->assertFalse(setting()->get('app-icon-64')); $this->assertFalse(setting()->get('app-icon-32')); + + $this->assertEquals( + file_get_contents(public_path('icon.ico')), + file_get_contents(public_path('favicon.ico')), + ); } }