From 934670b2a7bf4a2ec0ba6e52306a4b57f2bf7e34 Mon Sep 17 00:00:00 2001 From: Renan LE CARO Date: Fri, 14 Mar 2025 20:12:02 +0100 Subject: [PATCH] Added sw --- deploy.sh | 5 ++++ package-lock.json | 15 ++++++++++ package.json | 1 + public/icon-128.png | Bin 0 -> 749 bytes public/{icon.png => icon-512.png} | Bin public/icon-64.png | Bin 0 -> 479 bytes public/manifest.json | 14 ++++++++-- public/sw-b71.js | 44 ++++++++++++++++++++++++++++++ src/game.ts | 2 ++ src/options.ts | 2 +- src/sw_loader.ts | 4 +++ 11 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 public/icon-128.png rename public/{icon.png => icon-512.png} (100%) create mode 100644 public/icon-64.png create mode 100644 public/sw-b71.js create mode 100644 src/sw_loader.ts diff --git a/deploy.sh b/deploy.sh index 5c0b2f6..c569c71 100755 --- a/deploy.sh +++ b/deploy.sh @@ -33,6 +33,11 @@ sed -i -e "s/^[[:space:]]*versionCode = .*/ versionCode = $versionCode/" echo "\"$versionCode\"" > src/version.json +# Update service worker +sed -i -e "s/VERSION = .*/ VERSION = '$versionCode'/" ./public/sw-b71.js + + + # remove all exif metadata from pictures, because i think fdroid doesn't like that. odd find -name '*.jp*g' -o -name '*.png' | xargs exiftool -all= diff --git a/package-lock.json b/package-lock.json index aa9087c..5cc5c16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "GNU AGPLv3", "dependencies": { + "@parcel/service-worker": "^2.13.3", "@parcel/transformer-less": "^2.13.3", "@types/react": "^19.0.10", "@types/react-dom": "^19.0.4", @@ -1922,6 +1923,20 @@ "url": "https://opencollective.com/parcel" } }, + "node_modules/@parcel/service-worker": { + "version": "2.13.3", + "resolved": "https://registry.npmjs.org/@parcel/service-worker/-/service-worker-2.13.3.tgz", + "integrity": "sha512-b/wbbQPusfPsXvHx4mgI/hSQYIk6B5pkEL2ubNrtedjdzLPvjveZ161MxuF3XLvpDWINl7y8qPbmFZrf+pa8lg==", + "license": "MIT", + "engines": { + "node": ">= 16.0.0", + "parcel": "^2.13.3" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, "node_modules/@parcel/source-map": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/@parcel/source-map/-/source-map-2.1.1.tgz", diff --git a/package.json b/package.json index 0d99430..a677289 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "author": "Renan LE CARO", "license": "GNU AGPLv3", "dependencies": { + "@parcel/service-worker": "^2.13.3", "@parcel/transformer-less": "^2.13.3", "@types/react": "^19.0.10", "@types/react-dom": "^19.0.4", diff --git a/public/icon-128.png b/public/icon-128.png new file mode 100644 index 0000000000000000000000000000000000000000..34d70aab56e4d16c1407162cd45d53f511e33f8d GIT binary patch literal 749 zcmV|ABj`tN~-1m|NjjZF&-sOD@1&4L6B?qD(mvSsL8;vtZ+h6D;-@*na? zs&{viWx0-Y?+k@--yofAz0bOP?@qFaD8LJpeNUXg37o(QoWKd3;K>OlKA41ca|cCX z6+z6eumT#wcE}g8g0uBN3YL%pCPZI$;TKZi3DE@4O@I_oA)?}lnvKChyBLp3<17U9 zy`|u-Ob1TD{v_4Z5-&^z^Q#@z*oQJg2x3`&$89p;%SlO!HB*6%OG+_{q2aXy)D#r^AkYiBD(Flg3TaNK5G^QR@m1Kxd<7|}aURY>VATZ}dfE*v25}q%0sZN3UF!B1 zxB{=$HxhjGeSa&GO;yd?P*K$d3qG(Z+o~9k#QHx3Q+X!^emD|r>zb~}gA&{m846wS z#5aR@rsDk#IM7SNj>!cqXu&3#zcGo+c%}uflJ)tj{Pafzl=J6f-yBAj1fwn#1Rf-_ z0yG=M7#8>ub3%kuV#dkR$WF&TuPn$HQo{FZ-Kg3H;^j&?xmj}_=;q<4Y69{#olKNu zD~k~@oqxc7xQr8|$XGgDDL-=xb@}7F=nKe?ACkeHUA)6FGZ=m*C;xq^ fffG2v{}ucNA8^bFN-eLH00000NkvXXu0mjfp~F21 literal 0 HcmV?d00001 diff --git a/public/icon.png b/public/icon-512.png similarity index 100% rename from public/icon.png rename to public/icon-512.png diff --git a/public/icon-64.png b/public/icon-64.png new file mode 100644 index 0000000000000000000000000000000000000000..deb7aab5e4b4f496f93e626b5f282b6f3e476a9b GIT binary patch literal 479 zcmV<50U-W~P)|ABj`tN~-1m|NjXQDIXtfMyMx!IRlSww59~#Ae^t4r(*obfRZk<&?1ysPl0qkz< zZDE~%ob5CD9b z0HB}*5XKQP^?~%5r-=%49qm%h9pF$D-!!lS++!TC2vU4AGB8X64dU+AJX4qf zZTy~?mleQ+kfRI+4$lith-;a&OARFLXco$408$k@maNB#S~ADWrRYMKf@qlLi7HYW zXIUKoWWVZ`ynp}9nSk?qosdf17=x-m72IrvU;j@Z0d&o)+WjNv7A^qJRRP}v`~pjM V5xneWf-V36002ovPDHLkV1moO#3uj% literal 0 HcmV?d00001 diff --git a/public/manifest.json b/public/manifest.json index cd5aa71..64a7e4d 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -3,12 +3,22 @@ "name": "Breakout 71", "icons": [ { - "src": "/icon.png", + "src": "/icon-512.png", "sizes": "512x512", "type": "image/png" + }, + { + "src": "/icon-128.png", + "sizes": "128x128", + "type": "image/png" + }, + { + "src": "/icon-64.png", + "sizes": "64x64", + "type": "image/png" } ], - "start_url": ".", + "start_url": "/index.html?isPWA=true", "display": "fullscreen", "theme_color": "#5DA3EA", "background_color": "#ffffff" diff --git a/public/sw-b71.js b/public/sw-b71.js new file mode 100644 index 0000000..14d23d4 --- /dev/null +++ b/public/sw-b71.js @@ -0,0 +1,44 @@ +// The version of the cache. +const VERSION = '29032991' + +// The name of the cache +const CACHE_NAME = `breakout-71-${VERSION}`; + +// The static resources that the app needs to function. +const APP_STATIC_RESOURCES = [ + "/" +]; + +// On install, cache the static resources +self.addEventListener("install", (event) => { + event.waitUntil( + (async () => { + const cache = await caches.open(CACHE_NAME); + cache.addAll(APP_STATIC_RESOURCES); + })(), + ); +}); + +// delete old caches on activate +self.addEventListener("activate", (event) => { + event.waitUntil( + (async () => { + const names = await caches.keys(); + await Promise.all( + names.map((name) => { + if (name !== CACHE_NAME) { + return caches.delete(name); + } + }), + ); + await clients.claim(); + })(), + ); +}); + +self.addEventListener("fetch", (event) => { + if (event.request.mode === "navigate" && event.request.url.endsWith('/index.html?isPWA=true')) { + event.respondWith(caches.match("/")); + return; + } +}); diff --git a/src/game.ts b/src/game.ts index 1c5179d..c26c856 100644 --- a/src/game.ts +++ b/src/game.ts @@ -17,6 +17,7 @@ import {putBallsAtPuck, resetBalls} from "./resetBalls"; import {makeEmptyPerksMap, sumOfKeys} from "./game_utils"; import {baseCombo, decreaseCombo, resetCombo} from "./combo"; +import './sw_loader' const gameCanvas = document.getElementById("game") as HTMLCanvasElement; const ctx = gameCanvas.getContext("2d", { @@ -2382,6 +2383,7 @@ async function openSettingsPanel() { }); } } + actions.push({ text: "Sandbox mode", help: diff --git a/src/options.ts b/src/options.ts index 201ec2f..fea4866 100644 --- a/src/options.ts +++ b/src/options.ts @@ -46,7 +46,7 @@ export const options = { disabled() { return window.location.search.includes("isInWebView=true"); }, - }, + } } as const satisfies { [k: string]: OptionDef }; export type OptionDef = { diff --git a/src/sw_loader.ts b/src/sw_loader.ts new file mode 100644 index 0000000..d038dcc --- /dev/null +++ b/src/sw_loader.ts @@ -0,0 +1,4 @@ +if ("serviceWorker" in navigator && + window.location.search.includes("isPWA=true")) { + navigator.serviceWorker.register("sw-b71.js"); +} \ No newline at end of file