Skip to content

Commit 3b026fd

Browse files
committed
Improved generation
1 parent c22c75b commit 3b026fd

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*! coi-serviceworker v0.1.7 - Guido Zuidhof and contributors, licensed under MIT */
2+
/*! mini-coi - Andrea Giammarchi and contributors, licensed under MIT */
3+
(({ document: d, navigator: { serviceWorker: s } }) => {
4+
if (d) {
5+
const { currentScript: c } = d;
6+
s.register(c.src, { scope: c.getAttribute('scope') || '.' }).then(r => {
7+
r.addEventListener('updatefound', () => location.reload());
8+
if (r.active && !s.controller) location.reload();
9+
});
10+
}
11+
else {
12+
addEventListener('install', () => skipWaiting());
13+
addEventListener('activate', e => e.waitUntil(clients.claim()));
14+
addEventListener('fetch', e => {
15+
const { request: r } = e;
16+
if (r.cache === 'only-if-cached' && r.mode !== 'same-origin') return;
17+
e.respondWith(fetch(r).then(r => {
18+
const { body, status, statusText } = r;
19+
if (!status || status > 399) return r;
20+
const h = new Headers(r.headers);
21+
h.set('Cross-Origin-Opener-Policy', 'same-origin');
22+
h.set('Cross-Origin-Embedder-Policy', 'require-corp');
23+
h.set('Cross-Origin-Resource-Policy', 'cross-origin');
24+
return new Response(body, { status, statusText, headers: h });
25+
}));
26+
});
27+
}
28+
})(self);

cmake/platforms/emscripten/shell.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
<html lang="en-us">
33
<head>
44
<meta charset="utf-8">
5+
<script src="mini-coi.js"></script>
56
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6-
<meta http-equiv="Cross-Origin-Embedder-Policy" content="require-corp">
7-
<meta http-equiv="Cross-Origin-Opener-Policy" content="same-origin">
87
<title>YUP! On Emscripten</title>
98
<style>
109
*, *::before, *::after {

cmake/yup.cmake

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ include (FetchContent)
2828
#==============================================================================
2929

3030
macro (_yup_setup_platform)
31-
if (IOS OR CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_TOOLCHAIN_FILE MATCHES ".*ios\.cmake$")
31+
if (IOS OR CMAKE_SYSTEM_NAME MATCHES "iOS" OR CMAKE_TOOLCHAIN_FILE MATCHES ".*ios\.cmake$")
3232
set (yup_platform "ios")
3333

34-
elseif (ANDROID)
34+
elseif (ANDROID OR YUP_TARGET_ANDROID)
3535
set (yup_platform "android")
3636

3737
elseif (EMSCRIPTEN OR CMAKE_TOOLCHAIN_FILE MATCHES ".*Emscripten\.cmake$")
@@ -44,7 +44,7 @@ macro (_yup_setup_platform)
4444
set (yup_platform "linux")
4545

4646
elseif (WIN32)
47-
if (CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
47+
if (CMAKE_SYSTEM_NAME MATCHES "WindowsStore")
4848
set (yup_platform "uwp")
4949
else()
5050
set (yup_platform "win32")
@@ -745,6 +745,13 @@ function (yup_standalone_app)
745745
-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$dynCall'
746746
--shell-file "${CMAKE_SOURCE_DIR}/cmake/platforms/${yup_platform}/shell.html")
747747

748+
set (target_copy_dest "$<TARGET_FILE_DIR:${target_name}>")
749+
add_custom_command(
750+
TARGET ${target_name} POST_BUILD
751+
COMMAND ${CMAKE_COMMAND} -E copy
752+
"${CMAKE_SOURCE_DIR}/cmake/platforms/${yup_platform}/mini-coi.js"
753+
"${target_copy_dest}/mini-coi.js")
754+
748755
endif()
749756

750757
if (YUP_ARG_TARGET_IDE_GROUP)

justfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ emscripten:
3232
emcc -v
3333
emcmake cmake -G "Ninja Multi-Config" -B build
3434
cmake --build build
35-
python3 serve.py -p 8000 -d .
35+
python3 -m http.server -d .
36+
#python3 serve.py -p 8000 -d .
3637

3738
#run:
3839
# @just make

0 commit comments

Comments
 (0)