Skip to content

Commit

Permalink
Added generator directory selector for fixing MacOS compatibility (ne…
Browse files Browse the repository at this point in the history
…eds the directory to have at least one file inside when selecting it). The File Path can also be copied.
  • Loading branch information
Olmectron committed Jan 15, 2022
1 parent 12c0b80 commit 0c0a44c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
17 changes: 12 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const url = require('url')
var PROTOCOL = 'file';
const WEB_FOLDER = 'public_web';

var testing=false;
var hideToolbarFull=true;
function setupInterceptFiles(){
electron.protocol.interceptFileProtocol(PROTOCOL, (request, callback) => {
Expand Down Expand Up @@ -74,11 +75,17 @@ function createWindow () {
// and load the index.html of the app.
// mainWindow.loadFile('index.html')

mainWindow.loadURL(url.format({
pathname: 'index.html',
protocol: PROTOCOL + ':',
slashes: true
}));
if(testing){
mainWindow.loadURL("http://localhost:8081")
}
else{
mainWindow.loadURL(url.format({
pathname: 'index.html',
protocol: PROTOCOL + ':',
slashes: true
}));
}


//mainWindow.loadURL("http://localhost:8081")
// Open the DevTools.
Expand Down
5 changes: 3 additions & 2 deletions public_web/src/game-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ context.set("name",internalData.name);context.set("publisher",internalData.publi
</template>
</div>
`}removeGame(e){var ndsFile=e.detail.ndsFile;this.splice("ndsFiles",this.ndsFiles.indexOf(ndsFile),1);MiscUtils.Toast.show("File removed successfully")}pushFiles(files){if(!this.ndsFiles){this.set("ndsFiles",[])}for(var i=0;i<files.length;i++){// var ndsFile=new NDSFile(files[i],function());
this.push("ndsFiles",{file:files[i]})}}_getCurrentPath(){const{remote}=require("electron");var camino=remote.process.env.PORTABLE_EXECUTABLE_DIR;if(!camino){camino="."}return camino}callPythonGenerator(template){var context=this,ndsFile=template.lastNdsFile;console.log("NDS FILE",ndsFile);const spawn=require("child_process").spawn;var camino=ndsFile.file.path,outputName="YANBF-"+ndsFile.file.name.substring(0,ndsFile.file.name.length-4).replace(/ /g,"_")+".cia",outputLog="YANBF-"+ndsFile.file.name.substring(0,ndsFile.file.name.length-4).replace(/ /g,"_")+".log";console.log("Output name",outputName);var selectedPython=this.selectedPython;if(null==selectedPython||""==selectedPython){MiscUtils.Toast.show("You didn't set a Python3 location or command");return}for(var arrayArgs=[],splittedPython=selectedPython.split(" "),i=0,item;i<splittedPython.length;i++){item=splittedPython[i];if(null!=item&&""!=item&&0<i){arrayArgs.push(item)}}arrayArgs.push(context._getCurrentPath()+"/generator.py");arrayArgs.push(camino);arrayArgs.push("-o");arrayArgs.push(context._getCurrentPath()+"/output/"+outputName);if(null!=ndsFile.boxArtFile){arrayArgs.push("-b");arrayArgs.push(ndsFile.boxArtFile.path);console.log("Path File",ndsFile.boxArtFile.path)}console.log("Array args",arrayArgs);const pythonProcess=spawn(splittedPython[0],arrayArgs,{cwd:this._getCurrentPath()});template.set("lastNdsFile.running",!0);template.set("lastNdsFile.finished",!1);template.set("lastNdsFile.hadSuccess",!1);return new Promise(function(resolve,reject){/* pythonProcess.on("error",function(err){
this.push("ndsFiles",{file:files[i]})}}_getCurrentPath(){const{remote}=require("electron");if(null!=this.directoryPath&&""!=this.directoryPath.trim()){return this.directoryPath.trim()}var camino=remote.process.env.PORTABLE_EXECUTABLE_DIR;if(!camino){camino="."}return camino}callPythonGenerator(template){var context=this,ndsFile=template.lastNdsFile;console.log("NDS FILE",ndsFile);const spawn=require("child_process").spawn;var camino=ndsFile.file.path,outputName="YANBF-"+ndsFile.file.name.substring(0,ndsFile.file.name.length-4).replace(/ /g,"_")+".cia",outputLog="YANBF-"+ndsFile.file.name.substring(0,ndsFile.file.name.length-4).replace(/ /g,"_")+".log";console.log("Output name",outputName);var selectedPython=this.selectedPython;if(null==selectedPython||""==selectedPython){MiscUtils.Toast.show("You didn't set a Python3 location or command");return}for(var arrayArgs=[],splittedPython=selectedPython.split(" "),i=0,item;i<splittedPython.length;i++){item=splittedPython[i];if(null!=item&&""!=item&&0<i){arrayArgs.push(item)}}arrayArgs.push(context._getCurrentPath()+"/generator.py");arrayArgs.push(camino);arrayArgs.push("-o");arrayArgs.push(context._getCurrentPath()+"/output/"+outputName);if(null!=ndsFile.boxArtFile){arrayArgs.push("-b");arrayArgs.push(ndsFile.boxArtFile.path);console.log("Path File",ndsFile.boxArtFile.path)}console.log("Array args",arrayArgs);const pythonProcess=spawn(splittedPython[0],arrayArgs,{cwd:this._getCurrentPath()});template.set("lastNdsFile.running",!0);template.set("lastNdsFile.finished",!1);template.set("lastNdsFile.hadSuccess",!1);return new Promise(function(resolve,reject){/* pythonProcess.on("error",function(err){
console.log("Python error",err);
});
pythonProcess.on("close",function(err){
Expand All @@ -962,4 +962,5 @@ for(var files=e.dataTransfer.files,i=0,file;file=files[i];i++){console.log("FILE
}
reader.readAsDataURL(file); // start reading the file data.
*/}}})}constructor(){super();var context=this;LocalStoreQuery.addFieldCallback("selectedPython",function(target){if(!target){context.set("selectedPython","python3");return}if(target.startsWith("other")){if(-1<target.indexOf("---")){context.set("selectedPython",target.split("---")[1]||"")}else{context.set("selectedPython","")}}else{context.set("selectedPython",target)}})}static get properties(){return{selectedPython:{type:String,notify:!0},saving:{type:Boolean,notify:!0,value:!1},cardList:{type:Array,notify:!0},ndsFiles:{type:Array,notify:!0,value:null}}}}window.customElements.define("game-list",GameList)});
*/}}})}constructor(){super();var context=this;LocalStoreQuery.addFieldCallback("directoryPath",function(path){if(null==path||""==path||"null"==path){LocalStoreQuery.set("directoryPath",".")}else{context.set("directoryPath",path);// LocalStoreQuery.set("directoryPath",context._getCurrentPath());
}});LocalStoreQuery.addFieldCallback("selectedPython",function(target){if(!target){context.set("selectedPython","python3");return}if(target.startsWith("other")){if(-1<target.indexOf("---")){context.set("selectedPython",target.split("---")[1]||"")}else{context.set("selectedPython","")}}else{context.set("selectedPython",target)}})}static get properties(){return{selectedPython:{type:String,notify:!0},saving:{type:Boolean,notify:!0,value:!1},cardList:{type:Array,notify:!0},ndsFiles:{type:Array,notify:!0,value:null}}}}window.customElements.define("game-list",GameList)});
30 changes: 25 additions & 5 deletions public_web/src/my-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13575,17 +13575,17 @@ if(e&&e.target===this&&"opacity"===e.propertyName){if(this.opened){this._finishR
`}_selectedLocalFilesChanged(files){this.dispatchEvent(new CustomEvent("file-selected",{detail:{files:files}}))}clearFile(){this.shadowRoot.querySelector("input").value=""}_selectedLocalFileChanged(file){this.dispatchEvent(new CustomEvent("image-selected",{detail:{file:file}}));if(!0==this.photo&&null!=file){var context=this;// console.log("eefile",e.detail.file);
this.set("dataFile",file);this.set("imageFile",file);if(FileReader&&file){var fr=new FileReader,context=this;fr.onload=function(){context.set("imageUrl",fr.result)};fr.readAsDataURL(file)}}else{this.set("imageFile",null);this.set("imageUrl",null)}this.dispatchEvent(new CustomEvent("file-selected",{detail:{file:file}}))}clearFile(){}_accChanged(string){if(null!=string)this.$._fileButton.accept=string}static get properties(){return{multiple:{type:Boolean,notify:!0,value:!1},accept:{type:String,notify:!0,observer:"_accChanged"},options:{type:Object,notify:!0,observer:"_optionsChanged"},imageUrl:{type:String,notify:!0,reflectToAttribute:!0,value:null},imageFile:{type:Object,notify:!0,reflectToAttribute:!0,value:null},_selectedUploadButtonFile:{type:String,notify:!0,value:null,observer:"_selectedLocalFileChanged"},_selectedUploadButtonFiles:{type:Object,notify:!0,value:null,observer:"_selectedLocalFilesChanged"},manualUpload:{type:Boolean,notify:!0,value:!1},photo:{type:Boolean,notify:!0,value:!1},crop:{type:Boolean,notify:!0,value:!1},enabled:{type:Boolean,notify:!0,value:!0}}}clickSlot(){if(!this.enabled){return}this.$.slot.click()}_optionsChanged(options){if(options){if(options.fileTypes){// console.log("Type",type);
this.$._fileButton.accept=options.fileTypes.join(",");// inputFile.accept=type.join(",");
}}}executeUpload(){if(this._selectedUploadButtonFile)this._actualUploadAction(this._selectedUploadButtonFile);else PolymerUtils.Toast.show("No has seleccionado ning\xFAn archivo")}_filesSelectedHandler(e){var options=this.options,context=this;if(null==options&&!0!=this.manualUpload){PolymerUtils.Toast.show("Error. Verifica la informaci\xF3n de la subida de archivos");console.error("You haven't set an options object");return}/* var type=options.fileTypes;
}}}executeUpload(){if(this._selectedUploadButtonFile)this._actualUploadAction(this._selectedUploadButtonFile);else MiscUtils.Toast.show("You didn't select a file")}_filesSelectedHandler(e){var options=this.options,context=this;if(null==options&&!0!=this.manualUpload){MiscUtils.Toast.show("Error. Verify your files");console.error("You haven't set an options object");return}/* var type=options.fileTypes;
var path=options.path;
var name=options.name;
var uploadDone=options.success;
var errorFunction=options.error;
var onPaused=options.onPaused;
var onResumed=options.onResumed;
var progressCallback=options.onProgress;*/if(e.target.files&&e.target.files[0]){if(this.photo&&this.crop){PolymerUtils.Dialog.createAndShow({element:"photo-cropper-dialog",params:[e.target.files[0],function(blob){//DataHelper.Storage._actualFirebasePhotoUpload(options,blob,options.width,options.height);
var archivo=new File([blob],options.name,{type:blob.type,lastModified:new Date().getTime()});if(null!=e.target.files&&1<e.target.files.length){this.set("_selectedUploadButtonFiles",e.target.files)}else{context.set("_selectedUploadButtonFile",archivo)}context.shadowRoot.querySelector("input").value="";if(!context.manualUpload){context._actualUploadAction(context._selectedUploadButtonFile)}}]})}else{if(null!=e.target.files&&1<e.target.files.length){this.set("_selectedUploadButtonFiles",e.target.files)}else{this.set("_selectedUploadButtonFile",e.target.files[0])}context.shadowRoot.querySelector("input").value="";if(!context.manualUpload){context._actualUploadAction(context._selectedUploadButtonFile)}}}else{PolymerUtils.Toast.show("No seleccionaste ning\xFAn archivo")}}_actualUploadAction(file){var options=this.options;if(this.photo){/*if(this.crop){
var progressCallback=options.onProgress;*/if(e.target.files&&e.target.files[0]){if(this.photo&&this.crop){MiscUtils.Dialog.createAndShow({element:"photo-cropper-dialog",params:[e.target.files[0],function(blob){//DataHelper.Storage._actualFirebasePhotoUpload(options,blob,options.width,options.height);
var archivo=new File([blob],options.name,{type:blob.type,lastModified:new Date().getTime()});if(null!=e.target.files&&1<e.target.files.length){this.set("_selectedUploadButtonFiles",e.target.files)}else{context.set("_selectedUploadButtonFile",archivo)}context.shadowRoot.querySelector("input").value="";if(!context.manualUpload){context._actualUploadAction(context._selectedUploadButtonFile)}}]})}else{if(null!=e.target.files&&1<e.target.files.length){this.set("_selectedUploadButtonFiles",e.target.files)}else{this.set("_selectedUploadButtonFile",e.target.files[0])}context.shadowRoot.querySelector("input").value="";if(!context.manualUpload){context._actualUploadAction(context._selectedUploadButtonFile)}}}else{MiscUtils.Toast.show("You didn't select any file")}}_actualUploadAction(file){var options=this.options;if(this.photo){/*if(this.crop){
var t=this;
PolymerUtils.Dialog.createAndShow({element:"photo-cropper-dialog",params:[file,function(blob){
MiscUtils.Dialog.createAndShow({element:"photo-cropper-dialog",params:[file,function(blob){
DataHelper.Storage._actualFirebasePhotoUpload(options,blob,options.width,options.height);


Expand Down Expand Up @@ -13657,6 +13657,9 @@ setRootPath(MyAppGlobals.rootPath);class MyApp extends ElectronMixin(PolymerElem
paper-radio-button{
display: block;
}
.dir-name-input{
--paper-input-container-input:{font-size: 13px};
}
</style>

<app-location route="{{route}}" url-space-regex="^[[rootPath]]">
Expand All @@ -13678,6 +13681,21 @@ setRootPath(MyAppGlobals.rootPath);class MyApp extends ElectronMixin(PolymerElem
<!--<iron-selector selected="[[page]]" attr-for-selected="name" class="drawer-list" role="navigation">-->



<div style="display: flex; align-items: center; padding: 0px 8px;">

<paper-input class="dir-name-input" on-input="setDirectoryPathInput" style="flex-grow: 1;" label="Generator Directory" always-float-label value="{{directoryPath}}"></paper-input>

<div style="width: 40px; max-width: 40px; height: 40px; max-height: 40px; overflow: hidden; position: relative;">
<paper-icon-button style="position: absolute; top: 0; left: 0; right: 0; bottom: 0;" icon="icons:create-new-folder"></paper-icon-button>
<input class="dir-input" type="file" on-change="checkDirectoryNew" webkitdirectory directory multiple style="opacity: 0; cursor: pointer; min-height: 40px; min-width: 40px;background-color: red; width: 40px; max-width: 40px; height: 40px; max-height: 40px; position: absolute; top: 0; left: 0; right: 0; bottom: 0;"/>


</div>

</div>


<div style="padding: 8px; font-size: 12px; font-weight: 600;">Python command/location</div>
<div style="padding: 8px; font-size: 13px; color: var(--paper-grey-600);">If your process gets stale (progress circle keeps going on more than 30 seconds and nothing happens), <span on-click="reload" style="text-decoration: underline; color: var(--paper-blue-500); cursor:pointer;">restart the app</span> and select a different command or location.</div>
<paper-radio-group attr-for-selected="name" selected="{{selectedPython}}">
Expand Down Expand Up @@ -13734,7 +13752,9 @@ setRootPath(MyAppGlobals.rootPath);class MyApp extends ElectronMixin(PolymerElem
</app-drawer-layout>
`}pushFiles(files){this.shadowRoot.querySelector(".game-list").pushFiles(files)}requestFiles(e){var files=e.detail.files,file=e.detail.file;if(files){this.pushFiles(files)}else if(file){this.pushFiles([file])}//var { ipcRenderer }=require("electron");
//ipcRenderer.send("requestFiles");
}constructor(){super();var context=this;LocalStoreQuery.addFieldCallback("selectedPython",function(target){if(!target){context.set("selectedPython","python3");return}if(target.startsWith("other")){context.set("selectedPython","other");if(-1<target.indexOf("---")){context.set("otherPython",target.split("---")[1]||"")}}else{context.set("selectedPython",target)}})}setPythonInput(e){var context=this;console.log("Calling python input");if(this.lastInputDebounce){clearTimeout(this.lastInputDebounce);this.set("lastInputDebounce",null)}this.set("lastInputDebounce",setTimeout(function(){var command="other---"+(context.otherPython||"").trim();LocalStoreQuery.set("selectedPython",command);MiscUtils.Toast.show("Selected python command/location updated")},500))}setPython(){console.log("Calling python common");var context=this;setTimeout(function(){var selectedPython=context.selectedPython;LocalStoreQuery.set("selectedPython",selectedPython);MiscUtils.Toast.show("Selected python command/location updated")},250)}setSelectedTarget(){var context=this;setTimeout(function(){var selectedTarget=context.selectedTarget;LocalStoreQuery.set("selectedTarget",selectedTarget)},250)}_sortName(a,b){var aName=a.name?a.name.toLowerCase().trim():"zzzzzz",bName=b.name?b.name.toLowerCase().trim():"zzzzzz";return aName.localeCompare(bName)}saveCheckboxOption(e){var checkbox=e.target.closest("paper-checkbox"),name=checkbox.getAttribute("name");console.log("Saving:"+name);var context=this;setTimeout(function(){LocalStoreQuery.set(name,!0==context[name]?"true":"false")},250)}updateFolderForGames(){LocalStoreQuery.set("folderForGames",this.folderForGames);MiscUtils.Toast.show("Folder updated")}isString(string1,string2){return string1==string2}reload(){const app=require("electron").remote.app;app.relaunch();app.exit();// window.location.reload();
}_getCurrentPath(){const{remote}=require("electron");var camino=remote.process.env.PORTABLE_EXECUTABLE_DIR;if(!camino){camino="."}return camino}checkDirectoryNew(e){if(e.target.files&&e.target.files[0]){var context=this,fileSplit=e.target.files[0].path.split("\\");fileSplit.splice(fileSplit.length-1,1);var pathFinal=fileSplit.join("\\");console.log("File DIR",pathFinal);LocalStoreQuery.set("directoryPath",pathFinal);MiscUtils.Toast.show("Generator directory path updated");// this.set("_selectedUploadButtonFile",e.target.files[0]);
context.shadowRoot.querySelector(".dir-input").value=""}else{MiscUtils.Toast.show("You didn't select a directory")}}constructor(){super();var context=this;LocalStoreQuery.addFieldCallback("directoryPath",function(path){if(null==path||""==path||"null"==path){LocalStoreQuery.set("directoryPath",context._getCurrentPath())}else{context.set("directoryPath",path);// LocalStoreQuery.set("directoryPath",context._getCurrentPath());
}});LocalStoreQuery.addFieldCallback("selectedPython",function(target){if(!target){context.set("selectedPython","python3");return}if(target.startsWith("other")){context.set("selectedPython","other");if(-1<target.indexOf("---")){context.set("otherPython",target.split("---")[1]||"")}}else{context.set("selectedPython",target)}})}setDirectoryPathInput(e){var context=this;console.log("Calling directory input");if(this.lastDirectoryDebounce){clearTimeout(this.lastDirectoryDebounce);this.set("lastDirectoryDebounce",null)}this.set("lastDirectoryDebounce",setTimeout(function(){LocalStoreQuery.set("directoryPath",context.directoryPath);MiscUtils.Toast.show("Generator directory path updated")},500))}setPythonInput(e){var context=this;console.log("Calling python input");if(this.lastInputDebounce){clearTimeout(this.lastInputDebounce);this.set("lastInputDebounce",null)}this.set("lastInputDebounce",setTimeout(function(){var command="other---"+(context.otherPython||"").trim();LocalStoreQuery.set("selectedPython",command);MiscUtils.Toast.show("Selected python command/location updated")},500))}setPython(){console.log("Calling python common");var context=this;setTimeout(function(){var selectedPython=context.selectedPython;LocalStoreQuery.set("selectedPython",selectedPython);MiscUtils.Toast.show("Selected python command/location updated")},250)}setSelectedTarget(){var context=this;setTimeout(function(){var selectedTarget=context.selectedTarget;LocalStoreQuery.set("selectedTarget",selectedTarget)},250)}_sortName(a,b){var aName=a.name?a.name.toLowerCase().trim():"zzzzzz",bName=b.name?b.name.toLowerCase().trim():"zzzzzz";return aName.localeCompare(bName)}saveCheckboxOption(e){var checkbox=e.target.closest("paper-checkbox"),name=checkbox.getAttribute("name");console.log("Saving:"+name);var context=this;setTimeout(function(){LocalStoreQuery.set(name,!0==context[name]?"true":"false")},250)}updateFolderForGames(){LocalStoreQuery.set("folderForGames",this.folderForGames);MiscUtils.Toast.show("Folder updated")}isString(string1,string2){return string1==string2}reload(){const app=require("electron").remote.app;app.relaunch();app.exit();// window.location.reload();
}static get properties(){return{selectedPython:{type:String,notify:!0,value:"python3"},gamesFolder:{type:String,notify:!0,value:"Games"},selectedTarget:{type:String,notify:!0,value:null},ndsFiles:{type:Array,notify:!0},cardList:{type:Array,notify:!0},page:{type:String,reflectToAttribute:!0,observer:"_pageChanged"},routeData:Object,subroute:Object}}static get observers(){return["_routePageChanged(routeData.page)"]}_routePageChanged(page){// Show the corresponding page according to the route.
//
// If no page was found in the route data, page will be an empty string.
Expand Down

0 comments on commit 0c0a44c

Please sign in to comment.