Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 3072d70

Browse files
committed
Fixed user prompt settings save
1 parent 8fc6a2f commit 3072d70

File tree

1 file changed

+47
-44
lines changed

1 file changed

+47
-44
lines changed

main.ts

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ class Args {
1414
pythonExe: string;
1515
dotFile: string;
1616

17-
constructor(pass_vault_path: boolean, pass_current_file: boolean, additional_args: string[], prompted: boolean[]) {
17+
constructor(pass_vault_path: boolean, pass_current_file: boolean, additional_args: string[], prompted: boolean[], pythonExe: string = "", dotFile: string = "") {
1818
this.pass_vault_path = pass_vault_path;
1919
this.pass_current_file = pass_current_file;
20+
2021
this.additional_args = additional_args;
2122
this.prompted = prompted;
2223
this.length = additional_args.length;
24+
25+
this.pythonExe = pythonExe;
26+
this.dotFile = dotFile;
2327
}
2428
}
2529

@@ -100,6 +104,7 @@ export default class PythonScripterPlugin extends Plugin {
100104
// Setting Environment Variables
101105
let dot_file = additional_args.dotFile;
102106
if (dot_file != "") {
107+
// console.log(`${dot_file}`);
103108
if (!path.isAbsolute(dot_file)) {
104109
dot_file = path.join(basePath, dot_file);
105110
}
@@ -130,15 +135,14 @@ export default class PythonScripterPlugin extends Plugin {
130135

131136
if (additional_args.pythonExe != "") {
132137
python_exe = additional_args.pythonExe;
138+
if (!fs.existsSync(python_exe)) {
139+
new Notice(`Python Exe: $python_exe} for ${fileName} does not exist`)
140+
console.log(`Python Exe: ${python_exe} for ${fileName} does not exist`)
141+
return;
142+
}
133143
}
134-
if (!fs.existsSync(python_exe)) {
135-
new Notice(`Python Exe: $python_exe} for ${fileName} does not exist`)
136-
console.log(`Python Exe: ${python_exe} for ${fileName} does not exist`)
137-
return;
138-
}
139-
140144

141-
console.log(`Python Exe: ${python_exe}`)
145+
// console.log(`Python Exe: ${python_exe}`)
142146

143147
// Getting Main File
144148
let main_file = "";
@@ -199,7 +203,7 @@ export default class PythonScripterPlugin extends Plugin {
199203
await sleep(20);
200204

201205
}
202-
console.log(`Arg ${i + 1}: ${args[i + buffer]}`);
206+
// console.log(`Arg ${i + 1}: ${args[i + buffer]}`);
203207
}
204208
// Running the script
205209
let command = `${python_exe} \"${main_file}\"`;
@@ -384,27 +388,27 @@ class PythonScripterSettingTab extends PluginSettingTab {
384388
new Setting(containerEl)
385389
.setName(`Arg ${i + 3}`)
386390
.addText((area) => {
391+
const index = i;
387392
area
388393
.setPlaceholder('Enter argument')
389-
.setValue(this.plugin.settings.args[file].additional_args[i])
390-
.onChange(async (value) => {
391-
this.plugin.settings.args[file].additional_args[i] = value;
392-
await this.plugin.saveSettings();
394+
.setValue(this.plugin.settings.args[file].additional_args[index])
395+
.onChange((value) => {
396+
this.plugin.settings.args[file].additional_args[index] = value;
397+
this.plugin.saveSettings();
393398
});
394399
});
395400
new Setting(containerEl)
396401
.setName(`Prompt User for Arg ${i + 3}`)
397402
.setDesc(`Whether to prompt user for manual input for arg ${i + 3}`)
398403
.addToggle((area) => {
404+
const index = i;
399405
area
400406
.setValue(this.plugin.settings.args[file].prompted[i])
401-
.onChange(async (value) => {
402-
console.log(this.plugin.settings.args[file]);
403-
this.plugin.settings.args[file].prompted[i] = value;
404-
console.log(this.plugin.settings.args[file]);
407+
.onChange((value) => {
408+
this.plugin.settings.args[file].prompted[index] = value;
405409
resize(this.plugin.settings.args[file].additional_args, this.plugin.settings.args[file].length, "");
406410
resize(this.plugin.settings.args[file].prompted, this.plugin.settings.args[file].length, false);
407-
await this.plugin.saveSettings();
411+
this.plugin.saveSettings();
408412
});
409413
});
410414
}
@@ -422,27 +426,27 @@ class PythonScripterSettingTab extends PluginSettingTab {
422426
new Setting(containerEl)
423427
.setName(`Arg ${i + 2}`)
424428
.addText((area) => {
429+
const index = i;
425430
area
426431
.setPlaceholder('Enter argument')
427-
.setValue(this.plugin.settings.args[file].additional_args[i])
428-
.onChange(async (value) => {
429-
this.plugin.settings.args[file].additional_args[i] = value;
430-
await this.plugin.saveSettings();
432+
.setValue(this.plugin.settings.args[file].additional_args[index])
433+
.onChange((value) => {
434+
this.plugin.settings.args[file].additional_args[index] = value;
435+
this.plugin.saveSettings();
431436
});
432437
});
433438
new Setting(containerEl)
434439
.setName(`Prompt User for Arg ${i + 2}`)
435440
.setDesc(`Whether to prompt user for manual input for arg ${i + 2}`)
436441
.addToggle((area) => {
442+
const index = i;
437443
area
438-
.setValue(this.plugin.settings.args[file].prompted[i])
439-
.onChange(async (value) => {
440-
console.log(this.plugin.settings.args[file]);
441-
this.plugin.settings.args[file].prompted[i] = value;
442-
console.log(this.plugin.settings.args[file]);
444+
.setValue(this.plugin.settings.args[file].prompted[index])
445+
.onChange((value) => {
446+
this.plugin.settings.args[file].prompted[index] = value;
443447
resize(this.plugin.settings.args[file].additional_args, this.plugin.settings.args[file].length, "");
444448
resize(this.plugin.settings.args[file].prompted, this.plugin.settings.args[file].length, false);
445-
await this.plugin.saveSettings();
449+
this.plugin.saveSettings();
446450
});
447451
});
448452
}
@@ -460,27 +464,27 @@ class PythonScripterSettingTab extends PluginSettingTab {
460464
new Setting(containerEl)
461465
.setName(`Arg ${i + 2}`)
462466
.addText((area) => {
467+
const index = i;
463468
area
464469
.setPlaceholder('Enter argument')
465-
.setValue(this.plugin.settings.args[file].additional_args[i])
466-
.onChange(async (value) => {
467-
this.plugin.settings.args[file].additional_args[i] = value;
468-
await this.plugin.saveSettings();
470+
.setValue(this.plugin.settings.args[file].additional_args[index])
471+
.onChange((value) => {
472+
this.plugin.settings.args[file].additional_args[index] = value;
473+
this.plugin.saveSettings();
469474
});
470475
});
471476
new Setting(containerEl)
472477
.setName(`Prompt User for Arg ${i + 2}`)
473478
.setDesc(`Whether to prompt user for manual input for arg ${i + 2}`)
474479
.addToggle((area) => {
480+
const index = i;
475481
area
476482
.setValue(this.plugin.settings.args[file].prompted[i])
477-
.onChange(async (value) => {
478-
console.log(this.plugin.settings.args[file]);
479-
this.plugin.settings.args[file].prompted[i] = value;
480-
console.log(this.plugin.settings.args[file]);
483+
.onChange((value) => {
484+
this.plugin.settings.args[file].prompted[index] = value;
481485
resize(this.plugin.settings.args[file].additional_args, this.plugin.settings.args[file].length, "");
482486
resize(this.plugin.settings.args[file].prompted, this.plugin.settings.args[file].length, false);
483-
await this.plugin.saveSettings();
487+
this.plugin.saveSettings();
484488
});
485489
});
486490
}
@@ -489,28 +493,27 @@ class PythonScripterSettingTab extends PluginSettingTab {
489493
new Setting(containerEl)
490494
.setName(`Arg ${i + 1}`)
491495
.addText((area) => {
492-
496+
const index = i;
493497
area
494498
.setPlaceholder('Enter argument')
495499
.setValue(this.plugin.settings.args[file].additional_args[i])
496500
.onChange(async (value) => {
497-
this.plugin.settings.args[file].additional_args[i] = value;
501+
this.plugin.settings.args[file].additional_args[index] = value;
498502
await this.plugin.saveSettings();
499503
});
500504
});
501505
new Setting(containerEl)
502506
.setName(`Prompt User for Arg ${i + 1}`)
503507
.setDesc(`Whether to prompt user for manual input for arg ${i + 1}`)
504508
.addToggle((area) => {
509+
const index = i;
505510
area
506511
.setValue(this.plugin.settings.args[file].prompted[i])
507-
.onChange(async (value) => {
508-
console.log(this.plugin.settings.args[file]);
509-
this.plugin.settings.args[file].prompted[i] = value;
510-
console.log(this.plugin.settings.args[file]);
512+
.onChange((value) => {
513+
this.plugin.settings.args[file].prompted[index] = value;
511514
resize(this.plugin.settings.args[file].additional_args, this.plugin.settings.args[file].length, "");
512515
resize(this.plugin.settings.args[file].prompted, this.plugin.settings.args[file].length, false);
513-
await this.plugin.saveSettings();
516+
this.plugin.saveSettings();
514517
});
515518
});
516519
}

0 commit comments

Comments
 (0)