Skip to content

Commit

Permalink
Adding some console logging into GWT game input code, to help track d…
Browse files Browse the repository at this point in the history
…own Safari issue.
  • Loading branch information
lanceewing committed Apr 7, 2024
1 parent 6577ab6 commit df2239a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions html/src/main/java/com/agifans/agile/gwt/GwtDialogHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public void openFileDialog(AppConfigItem appConfigItem, String fileType, String
showHtmlOpenFileDialog(fileType, new GwtOpenFileResultsHandler() {
@Override
public void onFileResultsReady(GwtOpenFileResult[] openFileResultArray) {
if (openFileResultArray.length > 0) {
logToJSConsole("Game files are now being imported into AGILE...");
}

boolean hasVolFile = false;
boolean hasDirFile = false;
String directoryName = null;
Expand Down Expand Up @@ -257,6 +261,8 @@ private boolean isGameFile(String filename) {
}

private final native void showHtmlOpenFileDialog(String type, GwtOpenFileResultsHandler resultsHandler)/*-{
console.log('About to create input element of type file...');
var fileInputElem = document.createElement('input');
fileInputElem.type = "file";
Expand All @@ -272,22 +278,33 @@ private final native void showHtmlOpenFileDialog(String type, GwtOpenFileResults
fileInputElem.multiple = true;
}
console.log('Finished creating input element of type file');
// The onchange event occurs after a file is chosen.
fileInputElem.onchange = function(event) {
console.log('File input element onchange event triggered.');
console.log('The event object is: ' + event);
if (this.files.length === 0) {
console.log('No files selected for import');
// No file was selected, so nothing more to do.
[email protected]::onFileResultsReady([Lcom/agifans/agile/gwt/GwtOpenFileResult;)([]);
}
else {
console.log('File(s) were selected for import. Reading them now...');
// There can be multiple files, so we need to fetch all of them, and
// only when all have finished loading do we invoke the callback with
// content of the files.
Promise.all([].map.call(this.files, function (file) {
console.log('Starting to read in file ' + file.name);
return new Promise(function (resolve, reject) {
var reader = new FileReader();
// NOTE 1: loadend called regards of whether it was successful or not.
// NOTE 2: file has .name, .size and .lastModified fields.
reader.onloadend = function (event) {
console.log('Finished reading in file ' + file.name);
resolve({
fileName: file.name,
filePath: file.webkitRelativePath? file.webkitRelativePath : '',
Expand All @@ -297,6 +314,8 @@ private final native void showHtmlOpenFileDialog(String type, GwtOpenFileResults
reader.readAsArrayBuffer(file);
});
})).then(function (results) {
console.log('Finished reading in all selected files.');
// The results param is an array of result objects
[email protected]::onFileResultsReady([Lcom/agifans/agile/gwt/GwtOpenFileResult;)(results);
});
Expand All @@ -305,6 +324,8 @@ private final native void showHtmlOpenFileDialog(String type, GwtOpenFileResults
// Trigger the display of the open file dialog.
fileInputElem.click();
console.log('File input element has been clicked.');
}-*/;

@Override
Expand Down Expand Up @@ -352,4 +373,8 @@ private final native void showHtmlMessageBox(String message)/*-{
public boolean isDialogOpen() {
return dialogOpen;
}

private final native void logToJSConsole(String message)/*-{
console.log(message);
}-*/;
}

0 comments on commit df2239a

Please sign in to comment.