a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[frontend] Initial PWA enablement

authored by

Lilian and committed by
Laura Hausmann
8b9019b7 55f7b48d

+100 -4
+6 -2
Iceshrimp.Backend/Pages/Shared/FrontendSPA.cshtml
··· 14 14 <link rel="stylesheet" href="~/css/app.css"/> 15 15 <link rel="stylesheet" href="~/_content/Iceshrimp.Assets.PhosphorIcons/css/ph-regular.css"/> 16 16 <link rel="stylesheet" href="~/_content/Iceshrimp.Assets.PhosphorIcons/css/ph-fill.css"/> 17 - <link rel="icon" type="image/png" href="~/favicon.png"/> 17 + <link rel="icon" type="image/png" href="~/_content/Iceshrimp.Assets.Branding/favicon.png"/> 18 18 <link rel="stylesheet" href="~/Iceshrimp.Frontend.styles.css"/> 19 + <link href="manifest.webmanifest" rel="manifest"/> 20 + <link rel="apple-touch-icon" sizes="512x512" href="~/_content/Iceshrimp.Assets.Branding/512.png"/> 21 + <link rel="apple-touch-icon" sizes="192x192" href="~/_content/Iceshrimp.Assets.Branding/192.png"/> 19 22 </head> 20 23 21 24 <body> ··· 38 41 </div> 39 42 40 43 <script src="~/_framework/blazor.webassembly.js"></script> 44 + <script>navigator.serviceWorker.register('service-worker.js');</script> 41 45 </body> 42 46 43 47 </html> 44 - @* ReSharper restore Html.PathError *@ 48 + @* ReSharper restore Html.PathError *@
+13 -2
Iceshrimp.Frontend/Iceshrimp.Frontend.csproj
··· 6 6 <BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData> 7 7 </PropertyGroup> 8 8 9 - <Import Project="..\Iceshrimp.Build\Iceshrimp.Build.props"/> 10 - <Import Project="..\Iceshrimp.Build\Iceshrimp.Build.targets"/> 9 + <Import Project="..\Iceshrimp.Build\Iceshrimp.Build.props" /> 10 + <Import Project="..\Iceshrimp.Build\Iceshrimp.Build.targets" /> 11 11 12 12 <!-- Disables erroneous ILLink warnings. See https://github.com/dotnet/fsharp/issues/15261#issuecomment-1562959640 for more details.--> 13 13 <PropertyGroup> ··· 16 16 17 17 <ItemGroup> 18 18 <None Update="Components/MfmText.razor.css" CssScope="mfm" /> 19 + <None Include="wwwroot\icon-512.png" /> 19 20 </ItemGroup> 20 21 21 22 <ItemGroup> ··· 27 28 <PackageReference Include="AngleSharp" Version="1.1.2" /> 28 29 <PackageReference Include="Blazored.LocalStorage" Version="4.5.0" /> 29 30 <PackageReference Include="BlazorIntersectionObserver" Version="3.1.0" /> 31 + <PackageReference Include="Iceshrimp.Assets.Branding" Version="1.0.1" /> 30 32 <PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="9.0.0" /> 31 33 <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0" /> 32 34 <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.0" /> ··· 43 45 <!-- Transitive dependency version overrides to patch security vulnerabilities --> 44 46 <ItemGroup> 45 47 <PackageReference Include="MessagePack" Version="2.5.192" /> 48 + </ItemGroup> 49 + 50 + <!-- Required for PWA Features --> 51 + <PropertyGroup> 52 + <ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest> 53 + </PropertyGroup> 54 + 55 + <ItemGroup> 56 + <ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" /> 46 57 </ItemGroup> 47 58 48 59 <ItemGroup>
Iceshrimp.Frontend/wwwroot/favicon.png

This is a binary file and will not be displayed.

Iceshrimp.Frontend/wwwroot/icon-192.png

This is a binary file and will not be displayed.

+22
Iceshrimp.Frontend/wwwroot/manifest.webmanifest
··· 1 + { 2 + "name": "Iceshrimp.Frontend", 3 + "short_name": "Iceshrimp.Frontend", 4 + "id": "./", 5 + "start_url": "./", 6 + "display": "standalone", 7 + "background_color": "#ffffff", 8 + "theme_color": "#03173d", 9 + "prefer_related_applications": false, 10 + "icons": [ 11 + { 12 + "src": "icon-512.png", 13 + "type": "image/png", 14 + "sizes": "512x512" 15 + }, 16 + { 17 + "src": "icon-192.png", 18 + "type": "image/png", 19 + "sizes": "192x192" 20 + } 21 + ] 22 + }
+4
Iceshrimp.Frontend/wwwroot/service-worker.js
··· 1 + // In development, always fetch from the network and do not enable offline support. 2 + // This is because caching would make development more difficult (changes would not 3 + // be reflected on the first load after each change). 4 + self.addEventListener('fetch', () => { });
+55
Iceshrimp.Frontend/wwwroot/service-worker.published.js
··· 1 + // Caution! Be sure you understand the caveats before publishing an application with 2 + // offline support. See https://aka.ms/blazor-offline-considerations 3 + 4 + self.importScripts('./service-worker-assets.js'); 5 + self.addEventListener('install', event => event.waitUntil(onInstall(event))); 6 + self.addEventListener('activate', event => event.waitUntil(onActivate(event))); 7 + self.addEventListener('fetch', event => event.respondWith(onFetch(event))); 8 + 9 + const cacheNamePrefix = 'offline-cache-'; 10 + const cacheName = `${cacheNamePrefix}${self.assetsManifest.version}`; 11 + const offlineAssetsInclude = [ /\.dll$/, /\.pdb$/, /\.wasm/, /\.html/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/, /\.blat$/, /\.dat$/ ]; 12 + const offlineAssetsExclude = [ /^service-worker\.js$/ ]; 13 + 14 + // Replace with your base path if you are hosting on a subfolder. Ensure there is a trailing '/'. 15 + const base = "/"; 16 + const baseUrl = new URL(base, self.origin); 17 + const manifestUrlList = self.assetsManifest.assets.map(asset => new URL(asset.url, baseUrl).href); 18 + 19 + async function onInstall(event) { 20 + console.info('Service worker: Install'); 21 + 22 + // Fetch and cache all matching items from the assets manifest 23 + const assetsRequests = self.assetsManifest.assets 24 + .filter(asset => offlineAssetsInclude.some(pattern => pattern.test(asset.url))) 25 + .filter(asset => !offlineAssetsExclude.some(pattern => pattern.test(asset.url))) 26 + .map(asset => new Request(asset.url, { integrity: asset.hash, cache: 'no-cache' })); 27 + await caches.open(cacheName).then(cache => cache.addAll(assetsRequests)); 28 + } 29 + 30 + async function onActivate(event) { 31 + console.info('Service worker: Activate'); 32 + 33 + // Delete unused caches 34 + const cacheKeys = await caches.keys(); 35 + await Promise.all(cacheKeys 36 + .filter(key => key.startsWith(cacheNamePrefix) && key !== cacheName) 37 + .map(key => caches.delete(key))); 38 + } 39 + 40 + async function onFetch(event) { 41 + let cachedResponse = null; 42 + if (event.request.method === 'GET') { 43 + // For all navigation requests, try to serve index.html from cache, 44 + // unless that request is for an offline resource. 45 + // If you need some URLs to be server-rendered, edit the following check to exclude those URLs 46 + const shouldServeIndexHtml = event.request.mode === 'navigate' 47 + && !manifestUrlList.some(url => url === event.request.url); 48 + 49 + const request = shouldServeIndexHtml ? 'index.html' : event.request; 50 + const cache = await caches.open(cacheName); 51 + cachedResponse = await cache.match(request); 52 + } 53 + 54 + return cachedResponse || fetch(event.request); 55 + }