Fix download bugs in browser

This commit is contained in:
2024-07-14 14:59:30 +09:30
parent 39a1a80ebb
commit bbed468e67
2 changed files with 15 additions and 15 deletions

View File

@@ -36,7 +36,7 @@ export class EditorComponent {
protected values = signal<any>(undefined); protected values = signal<any>(undefined);
protected downloadName = computed( protected downloadName = computed(
() => this.selectedFile() ?? `${this.selectedMessage.name}.json` () => this.selectedFile() ?? `${this.selectedMessage().name}.json`
); );
private serialisedValues = computed(() => private serialisedValues = computed(() =>
JSON.stringify(this.values(), undefined, this.indentSize()) JSON.stringify(this.values(), undefined, this.indentSize())
@@ -118,15 +118,12 @@ export class EditorComponent {
protected async save() { protected async save() {
const selectedFile = this.selectedFile(); const selectedFile = this.selectedFile();
if (__TAURI__) { if (typeof __TAURI__ !== 'undefined') {
const serialised = this.serialisedValues(); const serialised = this.serialisedValues();
try {
// TODO: Tauri is bugged on mac atm, remove this when resolved: https://github.com/tauri-apps/tauri/issues/4633 // TODO: Tauri is bugged on mac atm, remove this when resolved: https://github.com/tauri-apps/tauri/issues/4633
if (selectedFile) { if (selectedFile) {
try {
await writeTextFile(selectedFile, serialised); await writeTextFile(selectedFile, serialised);
} catch (err) {
console.error('Failed to write to file ${this.selectedFile()}', err);
}
} else { } else {
const filePath = await save({ const filePath = await save({
defaultPath: `${this.selectedMessage().name}.json`, defaultPath: `${this.selectedMessage().name}.json`,
@@ -135,6 +132,9 @@ export class EditorComponent {
await writeTextFile(filePath, serialised); await writeTextFile(filePath, serialised);
} }
} }
} catch (err) {
console.error(`Failed to save to file`, err);
}
} else { } else {
this.downloader()?.nativeElement.click(); this.downloader()?.nativeElement.click();
} }

View File

@@ -197,7 +197,7 @@ export class ProtoDefinitionSelectorComponent {
} }
protected async exportConfiguration() { protected async exportConfiguration() {
if (__TAURI__) { if (typeof __TAURI__ !== undefined) {
const filePath = await save({ const filePath = await save({
defaultPath: `bufpiv.json`, defaultPath: `bufpiv.json`,
}); });