Skip to content

Commit

Permalink
"Fix" clipboard access
Browse files Browse the repository at this point in the history
  • Loading branch information
bones-was-here committed Aug 8, 2024
1 parent bab2b07 commit 8e5df4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ LDFLAGS_LINUXSV=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -rdynamic
LDFLAGS_LINUXSDL=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -rdynamic $(LDFLAGS_UNIXSDL)


##### WASM specific variable #####
##### WASM specific variables #####

LDFLAGS_WASMJS=$(LDFLAGS_UNIXCOMMON) -s USE_SDL=2 \
-s USE_LIBPNG=1 \
Expand Down
20 changes: 18 additions & 2 deletions sys_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,31 @@ void Sys_SDL_Dialog(const char *title, const char *string)
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, string, NULL);
}

// In a browser the clipboard can only be read asynchronously
// doing this efficiently and cleanly requires JSPI
// enable in makefile.inc with emcc option: -s JSPI
/* TODO: enable this code when JSPI is enabled by default in browsers
EM_ASYNC_JS(char *, js_getclipboard, (void),
{
try
{
const text = await navigator.clipboard.readText();
return stringToNewUTF8(text);
}
catch (err)
{
return stringToNewUTF8("clipboard error: ", err);
}
}); */
EM_JS(char *, js_getclipboard, (void), {
//Thank you again, stack overflow
return stringToNewUTF8(navigator.clipboard.readText());
return stringToNewUTF8("clipboard access requires JSPI which is not currently enabled.");
});
char *Sys_SDL_GetClipboardData (void)
{
char *data = NULL;
char *cliptext;

// SDL_GetClipboardText() does nothing in a browser, see above
cliptext = js_getclipboard();
if (cliptext != NULL) {
size_t allocsize;
Expand Down

0 comments on commit 8e5df4e

Please sign in to comment.