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,22 +118,22 @@ 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();
// TODO: Tauri is bugged on mac atm, remove this when resolved: https://github.com/tauri-apps/tauri/issues/4633 try {
if (selectedFile) { // TODO: Tauri is bugged on mac atm, remove this when resolved: https://github.com/tauri-apps/tauri/issues/4633
try { if (selectedFile) {
await writeTextFile(selectedFile, serialised); await writeTextFile(selectedFile, serialised);
} catch (err) { } else {
console.error('Failed to write to file ${this.selectedFile()}', err); const filePath = await save({
} defaultPath: `${this.selectedMessage().name}.json`,
} else { });
const filePath = await save({ if (filePath) {
defaultPath: `${this.selectedMessage().name}.json`, await writeTextFile(filePath, serialised);
}); }
if (filePath) {
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`,
}); });