1
0
Fork 0
forked from fte/fteqw

Let the browser port access the system clipboard (where permitted/allowed by browsers).

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6179 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2022-02-07 14:33:44 +00:00
parent 711bd8a990
commit 87ee3298a3
2 changed files with 49 additions and 3 deletions

View file

@ -69,6 +69,7 @@ mergeInto(LibraryManager.library,
ctxwarned:0,
pointerislocked:0,
pointerwantlock:0,
clipboard:"",
linebuffer:'',
localstorefailure:false,
w: -1,
@ -1120,6 +1121,52 @@ mergeInto(LibraryManager.library,
};
img.crossorigin = true;
img.src = "data:image/png;base64," + encode64(HEAPU8.subarray(dataptr, dataptr+datasize));
},
Sys_Clipboard_PasteText: function(cbt, callback, ctx)
{
if (cbt != 0)
return; //don't do selections.
let docallback = function(text)
{
FTEC.clipboard = text;
try{
let stringlen = (text.length*3)+1;
let dataptr = _malloc(stringlen);
stringToUTF8(text, dataptr, stringlen);
{{{makeDynCall('vii')}}}(callback, ctx, dataptr);
_free(dataptr);
}catch(e){
}
};
//try pasting. if it fails then use our internal string.
try
{
navigator.clipboard.readText()
.then(docallback)
.catch((e)=>{docallback(FTEC.clipboard)});
}
catch(e)
{ //clipboard API not supported at all.
console.log(e); //happens in firefox. lets print it so we know WHY its failing.
docallback(FTEC.clipboard);
}
},
Sys_SaveClipboard: function(cbt, text)
{
if (cbt != 0)
return; //don't do selections.
FTEC.clipboard = UTF8ToString(text);
try
{
//try and copy it to the system clipboard too.
navigator.clipboard.writeText(FTEC.clipboard);
}
catch {}
}
});

View file

@ -314,8 +314,7 @@ qboolean Sys_RunInstaller(void)
}
#endif
#define SYS_CLIPBOARD_SIZE 256
static char *clipboard_buffer;
/*static char *clipboard_buffer;
void Sys_Clipboard_PasteText(clipboardtype_t cbt, void (*callback)(void *cb, const char *utf8), void *ctx)
{
callback(ctx, clipboard_buffer);
@ -324,7 +323,7 @@ void Sys_SaveClipboard(clipboardtype_t cbt, const char *text)
{
free(clipboard_buffer);
clipboard_buffer = strdup(text);
}
}*/
#ifdef MULTITHREAD
/* Thread creation calls */