Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Enable emoji on web #766

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed fonts/NotoEmoji/NotoColorEmoji.ttf
Binary file not shown.
Binary file removed fonts/NotoEmoji/NotoEmoji-Regular.ttf
Binary file not shown.
3 changes: 0 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,6 @@ flutter:
- family: RobotoMono
fonts:
- asset: fonts/Roboto/RobotoMono-Regular.ttf
- family: NotoEmoji
fonts:
- asset: fonts/NotoEmoji/NotoColorEmoji.ttf
- family: Inter
fonts:
- asset: fonts/Inter/Inter-Thin.ttf
Expand Down
92 changes: 27 additions & 65 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
name="viewport"
/>
<script src="splash/splash.js"></script>
<script>
// The value below is injected by flutter build, do not touch.
var serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
</head>

<body>
Expand Down Expand Up @@ -68,75 +74,31 @@
alt=""
/>
</picture>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs() {
if (scriptLoaded) {
return;
}
scriptLoaded = true;
var scriptTag = document.createElement("script");
scriptTag.src = "main.dart.js";
scriptTag.type = "application/javascript";
document.body.append(scriptTag);
}

if ("serviceWorker" in navigator) {
// Service workers are supported. Use them.
window.addEventListener("load", function () {
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl =
"flutter_service_worker.js?v=" + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl).then((reg) => {
function waitForActivation(serviceWorker) {
serviceWorker.addEventListener("statechange", () => {
if (serviceWorker.state == "activated") {
console.log("Installed new service worker.");
loadMainDartJs();
}
window.addEventListener("load", function (ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function (engineInitializer) {
engineInitializer
.initializeEngine({
useColorEmoji: true,
})
.then(function (appRunner) {
appRunner.runApp();
});
}
if (!reg.active && (reg.installing || reg.waiting)) {
// No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing ?? reg.waiting);
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log("New service worker available.");
reg.update();
waitForActivation(reg.installing);
} else {
// Existing service worker is still good.
console.log("Loading app from service worker.");
loadMainDartJs();
}
});

// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
"Failed to load app from service worker. Falling back to plain <script> tag."
);
loadMainDartJs();
}
}, 4000);
},
});
} else {
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
}
});
</script>
<script src="assets/assets/js/package/olm.js"></script>
<script src="https://unpkg.com/pica/dist/pica.min.js" ></script>
<script type="application/javascript" src="/assets/packages/flutter_inappwebview/assets/web/web_support.js" defer></script>
<script src="https://unpkg.com/pica/dist/pica.min.js"></script>
<script
type="application/javascript"
src="/assets/packages/flutter_inappwebview/assets/web/web_support.js"
defer
></script>
</body>
</html>