forked from baron/baron-sso
feat: update worksmobile sync and restore planning
This commit is contained in:
@@ -27,11 +27,71 @@ warm_get() {
|
||||
"http://127.0.0.1:${USERFRONT_INTERNAL_PORT}${path}" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
wait_for_userfront_build() {
|
||||
flutter_pid="$1"
|
||||
attempt=1
|
||||
|
||||
while [ "$attempt" -le "$USERFRONT_BOOT_WARMUP_ATTEMPTS" ]; do
|
||||
if [ -f "build/web/index.html" ]; then
|
||||
return 0
|
||||
fi
|
||||
if ! kill -0 "$flutter_pid" 2>/dev/null; then
|
||||
echo "[userfront-boot] warmup skipped because flutter exited before build/web/index.html was ready" >&2
|
||||
return 1
|
||||
fi
|
||||
attempt=$((attempt + 1))
|
||||
sleep "$USERFRONT_BOOT_WARMUP_INTERVAL_SECONDS"
|
||||
done
|
||||
|
||||
echo "[userfront-boot] warmup skipped after ${USERFRONT_BOOT_WARMUP_ATTEMPTS} build readiness attempts" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
reset_userfront_service_worker() {
|
||||
cat > build/web/flutter_service_worker.js <<'EOF'
|
||||
self.addEventListener("install", (event) => {
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
(async () => {
|
||||
if (self.caches) {
|
||||
const keys = await self.caches.keys();
|
||||
await Promise.all(
|
||||
keys
|
||||
.filter(
|
||||
(key) =>
|
||||
key.indexOf("baron-userfront-") === 0 ||
|
||||
key.indexOf("flutter-app-cache") === 0,
|
||||
)
|
||||
.map((key) => self.caches.delete(key)),
|
||||
);
|
||||
}
|
||||
|
||||
await self.registration.unregister();
|
||||
|
||||
const clients = await self.clients.matchAll({
|
||||
type: "window",
|
||||
includeUncontrolled: true,
|
||||
});
|
||||
await Promise.all(clients.map((client) => client.navigate(client.url)));
|
||||
})(),
|
||||
);
|
||||
});
|
||||
EOF
|
||||
}
|
||||
|
||||
warm_userfront_once() {
|
||||
flutter_pid="$1"
|
||||
attempt=1
|
||||
started_at="$(date +%s)"
|
||||
|
||||
if ! wait_for_userfront_build "$flutter_pid"; then
|
||||
return 0
|
||||
fi
|
||||
reset_userfront_service_worker
|
||||
|
||||
while [ "$attempt" -le "$USERFRONT_BOOT_WARMUP_ATTEMPTS" ]; do
|
||||
if wget -qO- "http://127.0.0.1:${USERFRONT_INTERNAL_PORT}/flutter_bootstrap.js" >/dev/null 2>&1; then
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user