Add pwa fix files, disable publishing

This commit is contained in:
2024-01-26 20:08:29 +05:30
parent 1f49fea6e6
commit c5c95499af
3 changed files with 86 additions and 17 deletions

View File

@@ -22,6 +22,9 @@ on:
- ".github/workflows/**"
- "scripts/**"
env:
HREFREPLACE: "IIITB_Menu"
jobs:
build:
name: Build
@@ -68,11 +71,18 @@ jobs:
# run: flutter test
- name: Build Web Release
run: flutter build web --base-href "/IIITB_Menu/" --web-renderer canvaskit
run: flutter build web --base-href "/$HREFREPLACE/" --web-renderer canvaskit --no-web-resources-cdn
- name: Build Android Release
run: flutter build apk --split-per-abi --release --no-track-widget-creation --analyze-size --target-platform "android-arm64"
- name: Fix PWA Offline Support
run: |
cp scripts/fixOfflinePWA.sh .
chmod +x fixOfflinePWA.sh
./fixOfflinePWA.sh
cat ./build/web/flutter_service_worker.js
- name: Create Release
uses: marvinpinto/action-automatic-releases@v1.2.1
with:
@@ -89,21 +99,21 @@ jobs:
name: production-files
path: ./build/web
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
# deploy:
# name: Deploy
# needs: build
# runs-on: ubuntu-latest
# if: github.ref == 'refs/heads/master'
steps:
- name: Download artifact
uses: actions/download-artifact@v2.1.1
with:
name: production-files
path: ./build
# steps:
# - name: Download artifact
# uses: actions/download-artifact@v2.1.1
# with:
# name: production-files
# path: ./build
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3.9.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
# - name: Deploy to gh-pages
# uses: peaceiris/actions-gh-pages@v3.9.3
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: ./build

6
scripts/fixOfflinePWA.sh Normal file
View File

@@ -0,0 +1,6 @@
#! /bin/sh
cp scripts/pwaOffline.patch .
sed -e "s/HREFREPLACE/$(echo $HREFREPLACE)\//g" pwaOffline.patch > fix.patch
mv build/web/flutter_service_worker.js .
patch flutter_service_worker.js < fix.patch
mv flutter_service_worker.js build/web/

53
scripts/pwaOffline.patch Normal file
View File

@@ -0,0 +1,53 @@
--- menu/build/web/flutter_service_worker.js 2024-01-26 14:59:42.195084752 +0530
+++ in/flutter_service_worker.pat.js 2024-01-26 15:07:37.253097455 +0530
@@ -2,6 +2,7 @@
const MANIFEST = 'flutter-app-manifest';
const TEMP = 'flutter-temp-cache';
const CACHE_NAME = 'flutter-app-cache';
+const BaseHREF = 'HREFREPLACE';
const RESOURCES = {
"version.json": "d7fbd41faace5a7a02bb5da13e6049ec",
@@ -37,10 +38,7 @@
};
// The application shell files that are downloaded before a service worker can
// start.
-const CORE = ["main.dart.js",
-"index.html",
-"assets/AssetManifest.json",
-"assets/FontManifest.json"];
+const CORE = Object.keys(RESOURCES);
// During install, the TEMP cache is populated with the application shell files.
self.addEventListener("install", (event) =>
@@ -139,13 +137,30 @@
{
key = key.split('?v=')[0];
}
- if (event.request.url == origin || event.request.url.startsWith(origin + '/#') || key == '') {
+ if (key.endsWith("chromium/canvaskit.js"))
+ {
+ key = "canvaskit/chromium/canvaskit.js"
+ }
+ if (key.endsWith("chromium/canvaskit.wasm"))
+ {
+ key = "canvaskit/chromium/canvaskit.wasm"
+ }
+ if (key.endsWith("canvaskit.js"))
+ {
+ key = "canvaskit/canvaskit.js"
+ }
+ if (key.endsWith("canvaskit.wasm"))
+ {
+ key = "canvaskit/canvaskit.wasm"
+ }
+ if (event.request.url == origin || event.request.url.startsWith(origin + '/#') || key == '' || key == BaseHREF) {
key = '/';
}
// If the URL is not the RESOURCE list then return to signal that the
// browser should take over.
- if (!RESOURCES[key]) {
+ var resKey = key.replace(BaseHREF, "");
+ if (!RESOURCES[resKey]) {
return;
}