fixed dragdropfile +

This commit is contained in:
Leon van Kammen 2025-01-17 13:39:21 +01:00
parent ed9fc6ca8b
commit dcef641217
2 changed files with 8 additions and 5 deletions

View File

@ -3,7 +3,7 @@ ISOTerminal.prototype.redirectConsole = function(handler){
const dir = console.dir;
const err = console.error;
const warn = console.warn;
const addLineFeeds = (str) => str.replace(/\n/g,"\n\r")
const addLineFeeds = (str) => typeof str == 'string' ? str.replace(/\n/g,"\n\r") : str
console.log = (...args)=>{
const textArg = args[0];
@ -34,9 +34,10 @@ ISOTerminal.prototype.enableConsole = function(opts){
opts = opts || {stdout:false}
this.redirectConsole( (str,prefix) => {
let _str = typeof str == 'string' ? str : JSON.stringify(str)
let finalStr = "";
prefix = prefix ? prefix+' ' : ''
str.trim().split("\n").map( (line) => {
_str.trim().split("\n").map( (line) => {
finalStr += `${opts.stdout ? '' : "\x1b[38;5;165m/dev/browser: \x1b[0m"}`+prefix+line+'\n'
})
if( opts.stdout ){

View File

@ -17,7 +17,8 @@ if( typeof emulator != 'undefined' ){
ISOTerminal.prototype.pasteFile = async function(data){
const {type,item,pastedText} = data
if( pastedText){
this.pasteWriteFile( this.convert.toUint8Array(pastedText) ,type, null, true)
// the terminal handles this (pastes text)
// this.pasteWriteFile( this.convert.toUint8Array(pastedText) ,type, null, true)
}else{
const file = item.getAsFile();
const reader = new FileReader();
@ -35,8 +36,9 @@ if( typeof emulator != 'undefined' ){
const el = aEntity.el.dom.querySelector('#pastedrop') // upload input
el.addEventListener('change', (e) => {
const file = el.files[0];
const item = {...file, getAsFile: () => file }
this.el.emit('pasteFile', { item, type: file.type });
const item = {...file, getAsFile: () => file } // pasteFile-event works with File objets
const data = { item, type: file.type }
this.emit( 'pasteFile', data, "worker" ) // impersonate as worker (as worker cannot handle File objet)
})
}