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 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();