Skip to content

Commit

Permalink
Add title screen option to install app
Browse files Browse the repository at this point in the history
  • Loading branch information
fragglet committed Nov 22, 2024
1 parent 22f5eea commit efa75d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/emscripten/sopwith.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
function openManual() {
window.open("doc/sopwith-emscripten.html");
}
function promptForInstall() {
if (installPrompt != null) {
installPrompt.prompt();
}
}
function programError() {
canvas.style.visibility = "hidden";
loadingElement.style.visibility = "visible";
Expand Down Expand Up @@ -111,6 +116,11 @@
if (text) Module.printErr('[post-exception status] ' + text);
};
});
var installPrompt = null;
window.addEventListener("beforeinstallprompt", (event) => {
event.preventDefault();
installPrompt = event;
});
</script>

<script async type="text/javascript" src="sopwith.js"></script>
Expand Down
4 changes: 4 additions & 0 deletions src/swtitle.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ void getgamemode(void)
#endif
#ifdef __EMSCRIPTEN__
swputs(" M - open manual\n");
swputs(" I - install as app\n");
#endif
Vid_Update();

Expand Down Expand Up @@ -255,6 +256,9 @@ void getgamemode(void)
break;
#endif
#ifdef __EMSCRIPTEN__
case 'I':
emscripten_run_script("promptForInstall()");
break;
case 'M':
emscripten_run_script("openManual()");
break;
Expand Down

0 comments on commit efa75d7

Please sign in to comment.