From bbed468e67cb9ac629dd60a2ad38850069795c7e Mon Sep 17 00:00:00 2001 From: vato007 Date: Sun, 14 Jul 2024 14:59:30 +0930 Subject: [PATCH] Fix download bugs in browser --- src/app/editor/editor.component.ts | 28 +++++++++---------- .../proto-definition-selector.component.ts | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/app/editor/editor.component.ts b/src/app/editor/editor.component.ts index 95a94c5..a44cc77 100644 --- a/src/app/editor/editor.component.ts +++ b/src/app/editor/editor.component.ts @@ -36,7 +36,7 @@ export class EditorComponent { protected values = signal(undefined); protected downloadName = computed( - () => this.selectedFile() ?? `${this.selectedMessage.name}.json` + () => this.selectedFile() ?? `${this.selectedMessage().name}.json` ); private serialisedValues = computed(() => JSON.stringify(this.values(), undefined, this.indentSize()) @@ -118,22 +118,22 @@ export class EditorComponent { protected async save() { const selectedFile = this.selectedFile(); - if (__TAURI__) { + if (typeof __TAURI__ !== 'undefined') { const serialised = this.serialisedValues(); - // TODO: Tauri is bugged on mac atm, remove this when resolved: https://github.com/tauri-apps/tauri/issues/4633 - if (selectedFile) { - try { + try { + // TODO: Tauri is bugged on mac atm, remove this when resolved: https://github.com/tauri-apps/tauri/issues/4633 + if (selectedFile) { await writeTextFile(selectedFile, serialised); - } catch (err) { - console.error('Failed to write to file ${this.selectedFile()}', err); - } - } else { - const filePath = await save({ - defaultPath: `${this.selectedMessage().name}.json`, - }); - if (filePath) { - await writeTextFile(filePath, serialised); + } else { + const filePath = await save({ + defaultPath: `${this.selectedMessage().name}.json`, + }); + if (filePath) { + await writeTextFile(filePath, serialised); + } } + } catch (err) { + console.error(`Failed to save to file`, err); } } else { this.downloader()?.nativeElement.click(); diff --git a/src/app/proto-definition-selector/proto-definition-selector.component.ts b/src/app/proto-definition-selector/proto-definition-selector.component.ts index b4a2f53..cf2cabb 100644 --- a/src/app/proto-definition-selector/proto-definition-selector.component.ts +++ b/src/app/proto-definition-selector/proto-definition-selector.component.ts @@ -197,7 +197,7 @@ export class ProtoDefinitionSelectorComponent { } protected async exportConfiguration() { - if (__TAURI__) { + if (typeof __TAURI__ !== undefined) { const filePath = await save({ defaultPath: `bufpiv.json`, });