Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix file download in download menu #10408

Merged
merged 1 commit into from
Mar 7, 2025
Merged

fix file download in download menu #10408

merged 1 commit into from
Mar 7, 2025

Conversation

srietkerk
Copy link
Contributor

@srietkerk srietkerk commented Mar 6, 2025

@srietkerk srietkerk requested review from a team and Copilot March 6, 2025 01:16
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR fixes the file download functionality in the download menu by replacing the hardware download process with an asynchronous file-saving operation.

  • Renames the download click handler from onHwDownloadClick to onFileDownloadClick.
  • Replaces the compile call with an asynchronous call to saveProjectToFileAsync.
  • Updates the dropdown menu event to reference the new onFileDownloadClick method.

Reviewed Changes

File Description
webapp/src/editortoolbar.tsx Updated download handler to use async file save for downloads

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

// Matching the tick in the call to compile() above for historical reasons
pxt.tickEvent("editortools.download", { collapsed: this.getCollapsedState() }, { interactiveConsent: true });
pxt.tickEvent("editortools.downloadasfile", { collapsed: this.getCollapsedState() }, { interactiveConsent: true });
(this.props.parent as ProjectView).compile(true);
await (this.props.parent as ProjectView).saveProjectToFileAsync();
Copy link
Preview

Copilot AI Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The asynchronous function call is not wrapped in error handling. Consider adding a try/catch block to handle potential failures when saving the project to a file.

Suggested change
await (this.props.parent as ProjectView).saveProjectToFileAsync();
try {
await (this.props.parent as ProjectView).saveProjectToFileAsync();
} catch (error) {
console.error("Failed to save project to file:", error);
// Optionally, display an error message to the user
}

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume this is already happening in saveProjectToFileAsync but I guess worth double checking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saveProjectToFileAsync kinda has a lot going on in it, but from what I can tell, all of the different scenarios that it calls all error there, so I think we're safe to not add this try catch.

Copy link
Contributor

@thsparks thsparks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always wondered why this optioned popped up the hardware dialog. This seems much more natural.

@srietkerk srietkerk merged commit bf2278e into master Mar 7, 2025
7 checks passed
@srietkerk srietkerk deleted the srietkerk/file-save branch March 7, 2025 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Download to file" asks you to choose hardware "Save" should be beneath downloads button
2 participants