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

View File

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