Skip to content

Commit

Permalink
chore: update web initialization logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jsgalarraga committed May 21, 2024
1 parent 682b40d commit 8839e58
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 104 deletions.
11 changes: 6 additions & 5 deletions lib/main_development.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ignore_for_file: avoid_web_libraries_in_flutter

import 'dart:async';
import 'dart:js' as js;
import 'dart:js_interop' as js;
import 'dart:js_interop_unsafe';

import 'package:api_client/api_client.dart';
import 'package:authentication_repository/authentication_repository.dart';
Expand All @@ -18,8 +17,10 @@ import 'package:leaderboard_repository/leaderboard_repository.dart';

void main() async {
if (kDebugMode) {
js.context['FIREBASE_APPCHECK_DEBUG_TOKEN'] =
const String.fromEnvironment('APPCHECK_DEBUG_TOKEN');
js.globalContext.setProperty(
'FIREBASE_APPCHECK_DEBUG_TOKEN'.toJS,
const String.fromEnvironment('APPCHECK_DEBUG_TOKEN').toJS,
);
}

WidgetsFlutterBinding.ensureInitialized();
Expand Down
3 changes: 3 additions & 0 deletions packages/api_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ dependencies:
game_domain:
path: ../../api/packages/game_domain
http: ^1.2.1

dependency_overrides:
pointycastle: ^3.9.1
68 changes: 34 additions & 34 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ packages:
dependency: transitive
description:
name: _flutterfire_internals
sha256: "3dee3db3468c5f4640a4e8aa9c1e22561c298976d8c39ed2fdd456a9a3db26e1"
sha256: "2350805d7afefb0efe7acd325cb19d3ae8ba4039b906eade3807ffb69938a01f"
url: "https://pub.dev"
source: hosted
version: "1.3.32"
version: "1.3.33"
analyzer:
dependency: transitive
description:
Expand Down Expand Up @@ -385,26 +385,26 @@ packages:
dependency: "direct main"
description:
name: firebase_app_check
sha256: "8f8c54d00bd26e94b507c78f575f86c5f441d72b5f39b67ac743d9271e89bfaa"
sha256: f66b67027de548b6f8b61c7aa752a24804104e7f463723d202ae9c6d9520fa6b
url: "https://pub.dev"
source: hosted
version: "0.2.2"
version: "0.2.2+5"
firebase_app_check_platform_interface:
dependency: transitive
description:
name: firebase_app_check_platform_interface
sha256: "4eb67ee2ecc597c6b1421fcfd1e721aff35928e70cc471aa7fca9c79c15292bf"
sha256: c06fcb2381ff2566f4ebe1a1df2e1798de3d0fad531f673e8539368f33cf6b34
url: "https://pub.dev"
source: hosted
version: "0.1.0+22"
version: "0.1.0+27"
firebase_app_check_web:
dependency: transitive
description:
name: firebase_app_check_web
sha256: "57cb0d2c41fe31d45a37d62b9d91d93ed192f0d85b36ed28107493332f9d9ebe"
sha256: "88c8d792d429a43767461312f29baa5d3b76cd0453cf48dd008f8f94393221c1"
url: "https://pub.dev"
source: hosted
version: "0.1.2"
version: "0.1.2+5"
firebase_auth:
dependency: "direct main"
description:
Expand Down Expand Up @@ -433,10 +433,10 @@ packages:
dependency: "direct main"
description:
name: firebase_core
sha256: "4aef2a23d0f3265545807d68fbc2f76a6b994ca3c778d88453b99325abd63284"
sha256: "372d94ced114b9c40cb85e18c50ac94a7e998c8eec630c50d7aec047847d27bf"
url: "https://pub.dev"
source: hosted
version: "2.30.1"
version: "2.31.0"
firebase_core_platform_interface:
dependency: transitive
description:
Expand All @@ -449,10 +449,10 @@ packages:
dependency: transitive
description:
name: firebase_core_web
sha256: "67f2fcc600fc78c2f731c370a3a5e6c87ee862e3a2fba6f951eca6d5dafe5c29"
sha256: "43d9e951ac52b87ae9cc38ecdcca1e8fa7b52a1dd26a96085ba41ce5108db8e9"
url: "https://pub.dev"
source: hosted
version: "2.16.0"
version: "2.17.0"
fixnum:
dependency: transitive
description:
Expand Down Expand Up @@ -588,10 +588,10 @@ packages:
dependency: "direct main"
description:
name: intl
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
url: "https://pub.dev"
source: hosted
version: "0.18.1"
version: "0.19.0"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -634,26 +634,26 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
version: "10.0.4"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "3.0.3"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "3.0.1"
logging:
dependency: transitive
description:
Expand Down Expand Up @@ -682,10 +682,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.12.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -834,10 +834,10 @@ packages:
dependency: transitive
description:
name: pointycastle
sha256: "43ac87de6e10afabc85c445745a7b799e04de84cebaa4fd7bf55a5e1e9604d29"
sha256: "4be0097fcf3fd3e8449e53730c631200ebc7b88016acecab2b0da2f0149222fe"
url: "https://pub.dev"
source: hosted
version: "3.7.4"
version: "3.9.1"
pool:
dependency: transitive
description:
Expand Down Expand Up @@ -999,26 +999,26 @@ packages:
dependency: transitive
description:
name: test
sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f
sha256: "7ee446762c2c50b3bd4ea96fe13ffac69919352bd3b4b17bac3f3465edc58073"
url: "https://pub.dev"
source: hosted
version: "1.24.9"
version: "1.25.2"
test_api:
dependency: transitive
description:
name: test_api
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
url: "https://pub.dev"
source: hosted
version: "0.6.1"
version: "0.7.0"
test_core:
dependency: transitive
description:
name: test_core
sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a
sha256: "2bc4b4ecddd75309300d8096f781c0e3280ca1ef85beda558d33fcbedc2eead4"
url: "https://pub.dev"
source: hosted
version: "0.5.9"
version: "0.6.0"
time:
dependency: transitive
description:
Expand Down Expand Up @@ -1159,10 +1159,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
source: hosted
version: "13.0.0"
version: "14.2.1"
watcher:
dependency: transitive
description:
Expand Down Expand Up @@ -1228,5 +1228,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.19.0"
dart: ">=3.4.0 <4.0.0"
flutter: ">=3.22.0"
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version: 0.0.1+1
publish_to: none

environment:
sdk: ">=3.2.0 <4.0.0"
flutter: ">=3.19.0"
sdk: ">=3.4.0 <4.0.0"
flutter: ">=3.22.0"

dependencies:
api_client:
Expand All @@ -21,7 +21,7 @@ dependencies:
crossword_repository:
path: packages/crossword_repository
equatable: ^2.0.5
firebase_app_check: ^0.2.2
firebase_app_check: ^0.2.2+5
firebase_auth: ^4.19.4
firebase_core: ^2.30.1
flame: ^1.17.0
Expand All @@ -35,7 +35,7 @@ dependencies:
game_domain:
path: api/packages/game_domain
http: ^1.2.1
intl: ^0.18.1
intl: ^0.19.0
io_crossword_ui:
path: packages/io_crossword_ui
leaderboard_repository:
Expand Down
43 changes: 43 additions & 0 deletions web/flutter_bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/// Keep in mind that this file is not a real javascript file, it is a template
/// that will be processed by the build system to generate the final javascript
/// file. Therefore, we use the mustache syntax, like {{variable}}, to inject
/// values and you might see some linter errors in this file.

{{flutter_js}}
{{flutter_build_config}}

const cookieBar = document.querySelector("#cookie-bar");
const cookieBarButton = document.querySelector("#confirm-cookies");
const splashCopy = document.querySelector("#splash_copy");

const additionalScripts = [];

let cookiesAcceptanceCompleter;
let hasUserAcceptedCookies = new Promise((resolve) => {
cookiesAcceptanceCompleter = resolve;
});

cookieBarButton.addEventListener("click", () => {
console.log("cookieBarButton clicked");
cookieBar.remove();
cookiesAcceptanceCompleter();
});

window.addEventListener("load", (event) => {
_flutter.loader.load({
serviceWorkerSettings: {
serviceWorkerVersion: {{flutter_service_worker_version}},
},
onEntrypointLoaded: async function (engineInitializer) {
const appRunner = await engineInitializer.initializeEngine();
await hasUserAcceptedCookies;

window.addEventListener("flutter-first-frame", function () {
splashCopy.remove();
document.body.classList.remove("loading-mode");
});

await appRunner.runApp();
},
});
});
62 changes: 1 addition & 61 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@
}

</style>

<script>
// The value below is injected by flutter build, do not touch.
var serviceWorkerVersion = null;
</script>
</head>
<body class="loading-mode">
<img id="background" src="hero.png" />
Expand All @@ -213,62 +208,7 @@
<button id="confirm-cookies">Ok, got it</button>
</div>
<script>
(function () {
const cookieBar = document.querySelector("#cookie-bar");
const cookieBarButton = document.querySelector("#confirm-cookies");
const splashCopy = document.querySelector("#splash_copy");

const additionalScripts = [];

let cookiesAcceptanceCompleter;
let hasUserAcceptedCookies = new Promise((resolve) => {
cookiesAcceptanceCompleter = resolve;
});

cookieBarButton.addEventListener("click", function () {
cookieBar.remove();
cookiesAcceptanceCompleter();
});

function injectScript(url) {
return new Promise(function (resolve) {
let scriptTag = document.createElement("script");
scriptTag.src = url;
scriptTag.type = "application/javascript";
scriptTag.onload = function () {
resolve();
};

document.body.append(scriptTag);
});
}

window.addEventListener("load", async function (ev) {
await injectScript("flutter.js");

_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function (engineInitializer) {
engineInitializer
.initializeEngine()
.then(async function (appRunner) {
await hasUserAcceptedCookies;
window.addEventListener(
"flutter-first-frame",
function () {
splashCopy.remove();
document.body.classList.remove("loading-mode");
}
);

appRunner.runApp();
});
},
});
});
})();
{{flutter_bootstrap_js}}
</script>
</body>
</html>

0 comments on commit 8839e58

Please sign in to comment.