mirror of
https://github.com/nzp-team/fteqw.git
synced 2024-11-26 05:41:52 +00:00
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:
parent
711bd8a990
commit
87ee3298a3
2 changed files with 49 additions and 3 deletions
|
@ -69,6 +69,7 @@ mergeInto(LibraryManager.library,
|
||||||
ctxwarned:0,
|
ctxwarned:0,
|
||||||
pointerislocked:0,
|
pointerislocked:0,
|
||||||
pointerwantlock:0,
|
pointerwantlock:0,
|
||||||
|
clipboard:"",
|
||||||
linebuffer:'',
|
linebuffer:'',
|
||||||
localstorefailure:false,
|
localstorefailure:false,
|
||||||
w: -1,
|
w: -1,
|
||||||
|
@ -1120,6 +1121,52 @@ mergeInto(LibraryManager.library,
|
||||||
};
|
};
|
||||||
img.crossorigin = true;
|
img.crossorigin = true;
|
||||||
img.src = "data:image/png;base64," + encode64(HEAPU8.subarray(dataptr, dataptr+datasize));
|
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 {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -314,8 +314,7 @@ qboolean Sys_RunInstaller(void)
|
||||||
}
|
}
|
||||||
#endif
|
#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)
|
void Sys_Clipboard_PasteText(clipboardtype_t cbt, void (*callback)(void *cb, const char *utf8), void *ctx)
|
||||||
{
|
{
|
||||||
callback(ctx, clipboard_buffer);
|
callback(ctx, clipboard_buffer);
|
||||||
|
@ -324,7 +323,7 @@ void Sys_SaveClipboard(clipboardtype_t cbt, const char *text)
|
||||||
{
|
{
|
||||||
free(clipboard_buffer);
|
free(clipboard_buffer);
|
||||||
clipboard_buffer = strdup(text);
|
clipboard_buffer = strdup(text);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
#ifdef MULTITHREAD
|
#ifdef MULTITHREAD
|
||||||
/* Thread creation calls */
|
/* Thread creation calls */
|
||||||
|
|
Loading…
Reference in a new issue