Skip to content

Commit

Permalink
Update MistFetch.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mistium authored Oct 9, 2024
1 parent e57fb3b commit 498e18d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion files/MistFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MistFetch {
arguments: {
URL: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'https://example.com'
defaultValue: 'https://extensions.turbowarp.org/hello.txt'
},
ID: {
type: Scratch.ArgumentType.STRING,
Expand Down Expand Up @@ -66,6 +66,23 @@ class MistFetch {
defaultValue: 'request1'
}
}
},
{
opcode: 'whenIdRequestCompleted',
blockType: Scratch.BlockType.EVENT,
text: 'when request [ID] completed',
isEdgeActivated: false,
arguments: {
ID: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'request1'
}
}
},
{
opcode: 'inProgress',
blockType: Scratch.BlockType.REPORTER,
text: 'all requests in progress',
}
]
};
Expand Down Expand Up @@ -93,6 +110,7 @@ class MistFetch {
const { done: doneReading, value } = await reader.read();
if (doneReading) {
done = true;
Scratch.vm.runtime.startHats('mistfetch_whenIdRequestCompleted', { ID: ID });
this.requests[ID].completed = true;
} else {
this.requests[ID].totalBytes += value.length;
Expand Down Expand Up @@ -143,6 +161,17 @@ class MistFetch {
}
return `No request found for ID: ${ID}`;
}

whenIdRequestCompleted({ ID }) {
if (this.requests[ID] && this.requests[ID].completed) {
return true;
}
return false;
}

inProgress() {
return JSON.stringify(Object.keys(this.requests));
}
}

// Register the extension
Expand Down

0 comments on commit 498e18d

Please sign in to comment.