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

Error handling to afterSaveLilypondPDF Method #4288

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@
<input type="checkbox" id="guitarCheck" tabindex="-1" />
<p></p>
<p><button id="submitLilypond"></button></p>
<!-- <button id="submitPDF"></button></p> -->
<!-- <p><button id="submitPDF"></button></p> -->
</div>
</div>

Expand Down
30 changes: 20 additions & 10 deletions js/SaveInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ class SaveInterface {
docById("guitarText").textContent = _("Include guitar tablature output?");
//.TRANS: Lilypond is a scripting language for generating sheet music
docById("submitLilypond").textContent = _("Save as Lilypond");
//.TRANS: LilypondPDF option
// docById("submitPDF").textContent = _("Save as Lilypond PDF");
docById("fileName").value = filename;
if (activity.PlanetInterface !== undefined) {
docById("title").value = activity.PlanetInterface.getCurrentProjectName();
Expand All @@ -429,12 +431,9 @@ class SaveInterface {
docById("submitLilypond").onclick = () => {
activity.save.saveLYFile(false);
};
// if (this.planet){
// docById('submitPDF').onclick = function(){this.saveLYFile(true);}.bind(this);
// docById('submitPDF').disabled = false;
// } else {
// docById('submitPDF').disabled = true;
// }
// docById("submitPDF").onclick = () => {
// activity.save.saveLYFile(true); // Set isPDF to true for PDF generation
// };
docByClass("close")[0].onclick = () => {
activity.logo.runningLilypond = false;
docById("lilypondModal").style.display = "none";
Expand Down Expand Up @@ -466,8 +465,14 @@ class SaveInterface {
const guitarCheck = docById("guitarCheck").checked;

if (filename != null) {
if (fileExt(filename) !== "ly") {
filename += ".ly";
if(!isPDF){
if (fileExt(filename) !== "ly") {
filename += ".ly";
}
} else {
if (fileExt(filename) !== "pdf") {
filename += ".pdf";
}
}
}

Expand Down Expand Up @@ -579,7 +584,6 @@ class SaveInterface {
this.download("ly", "data:text;utf8," + encodeURIComponent(lydata), filename);
}


/**
* Perform actions after saving a Lilypond file in PDF format.
*
Expand All @@ -593,14 +597,20 @@ class SaveInterface {
* @instance
*/
afterSaveLilypondPDF(lydata, filename) {
filename = docById("fileName").value;
document.body.style.cursor = "wait";
window.Converter.ly2pdf(lydata, (success, dataurl) => {
document.body.style.cursor = "default";
if (!success) {
// eslint-disable-next-line no-console
console.debug("Error: " + dataurl);
//TODO: Error message box
// Error message handling if needed
const tmp = jQuery("<textarea />").appendTo(document.body);
this.activity.textMsg(
_("Oops. Looks like we couldn’t save your music as a PDF. ")
);
} else {
// Download the generated PDF
this.activity.save.download("pdf", dataurl, filename);
}
});
Expand Down
1 change: 1 addition & 0 deletions js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ class Activity {
activity.save.saveLilypond.bind(activity.save),
activity.save.saveLilypond.bind(afterSaveLilypond),
activity.save.afterSaveLilypondLY.bind(activity.save),
activity.save.afterSaveLilypondPDF.bind(activity.save),
activity.save.saveAbc.bind(activity.save),
activity.save.saveMxml.bind(activity.save),
activity.save.saveBlockArtwork.bind(activity.save)
Expand Down
2 changes: 1 addition & 1 deletion planet/js/ServerInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ class ServerInterface {

init() { };

}
}
Loading