diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index f01714e..f4bf03d 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -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 diff --git a/scripts/fixOfflinePWA.sh b/scripts/fixOfflinePWA.sh new file mode 100644 index 0000000..8ad9a84 --- /dev/null +++ b/scripts/fixOfflinePWA.sh @@ -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/ diff --git a/scripts/pwaOffline.patch b/scripts/pwaOffline.patch new file mode 100644 index 0000000..0483e48 --- /dev/null +++ b/scripts/pwaOffline.patch @@ -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; + }