chore: Fix app

This commit is contained in:
2026-07-14 00:41:05 +02:00
parent 3e090933fd
commit edc4d935d8
98 changed files with 2878 additions and 155 deletions
@@ -9,8 +9,15 @@ import {
import { DOCUMENT } from '@angular/common';
import { Injector, runInInjectionContext } from '@angular/core';
const isCapacitorNativeRuntimeMock = vi.fn(() => false);
vi.mock('../../../../infrastructure/mobile/logic/platform-detection.rules', () => ({
isCapacitorNativeRuntime: () => isCapacitorNativeRuntimeMock()
}));
import { AttachmentDownloadService } from './attachment-download.service';
import { ElectronBridgeService } from '../../../../core/platform/electron/electron-bridge.service';
import { CapacitorAttachmentExportService } from '../../infrastructure/services/capacitor-attachment-export.service';
import type { Attachment } from '../../domain/models/attachment.model';
describe('AttachmentDownloadService', () => {
@@ -21,8 +28,11 @@ describe('AttachmentDownloadService', () => {
let documentStub: Document;
let saveExistingFileAs: ReturnType<typeof vi.fn>;
let saveFileAs: ReturnType<typeof vi.fn>;
let exportToDevice: ReturnType<typeof vi.fn>;
beforeEach(() => {
isCapacitorNativeRuntimeMock.mockReturnValue(false);
exportToDevice = vi.fn(async () => true);
saveExistingFileAs = vi.fn(async () => ({ saved: true, cancelled: false }));
saveFileAs = vi.fn(async () => ({ saved: true, cancelled: false }));
@@ -53,6 +63,7 @@ describe('AttachmentDownloadService', () => {
providers: [
AttachmentDownloadService,
{ provide: ElectronBridgeService, useValue: electronBridge },
{ provide: CapacitorAttachmentExportService, useValue: { exportToDevice } },
{ provide: DOCUMENT, useValue: documentStub }
]
});
@@ -78,6 +89,28 @@ describe('AttachmentDownloadService', () => {
expect(saveFileAs).not.toHaveBeenCalled();
});
it('delegates to the Capacitor export service on a native mobile shell', async () => {
isCapacitorNativeRuntimeMock.mockReturnValue(true);
electronBridge.getApi = vi.fn(() => null);
const service = createService();
const attachment: Attachment = {
id: 'file-3',
messageId: 'message-3',
filename: 'photo.png',
mime: 'image/png',
size: 2048,
available: true,
savedPath: 'metoyou/server/room/files/photo.png'
};
await expect(service.downloadToUserLocation(attachment)).resolves.toBe(true);
expect(exportToDevice).toHaveBeenCalledWith(attachment);
expect(saveExistingFileAs).not.toHaveBeenCalled();
expect(saveFileAs).not.toHaveBeenCalled();
});
it('does nothing when the attachment is not downloadable yet', async () => {
const service = createService();
const attachment: Attachment = {
@@ -2,12 +2,15 @@ import { DOCUMENT } from '@angular/common';
import { Injectable, inject } from '@angular/core';
import { ElectronBridgeService } from '../../../../core/platform/electron/electron-bridge.service';
import { isCapacitorNativeRuntime } from '../../../../infrastructure/mobile/logic/platform-detection.rules';
import { canDownloadAttachment, resolveAttachmentDiskPath } from '../../domain/logic/attachment-download.rules';
import type { Attachment } from '../../domain/models/attachment.model';
import { CapacitorAttachmentExportService } from '../../infrastructure/services/capacitor-attachment-export.service';
@Injectable({ providedIn: 'root' })
export class AttachmentDownloadService {
private readonly electronBridge = inject(ElectronBridgeService);
private readonly capacitorExport = inject(CapacitorAttachmentExportService);
private readonly document = inject(DOCUMENT);
async downloadToUserLocation(attachment: Attachment): Promise<boolean> {
@@ -15,6 +18,10 @@ export class AttachmentDownloadService {
return false;
}
if (isCapacitorNativeRuntime()) {
return this.capacitorExport.exportToDevice(attachment);
}
const electronApi = this.electronBridge.getApi();
const diskPath = resolveAttachmentDiskPath(attachment);