diff --git a/src/helpers/file-handling-api.ts b/src/helpers/file-handling-api.ts index dc1ac799..aafbd9ef 100644 --- a/src/helpers/file-handling-api.ts +++ b/src/helpers/file-handling-api.ts @@ -1,4 +1,3 @@ -import type { FileSystemHandle } from 'browser-fs-access'; import type { DrawingContext } from '../models/drawing-context'; import { loadFileAndAdjustCanvas } from './load-file-and-adjust-canvas'; @@ -9,7 +8,7 @@ export function getLaunchImage(drawingContext: DrawingContext): void { if (handle) { const file = await handle.getFile(); drawingContext.document.title = file.name; - drawingContext.document.handle = handle as unknown as FileSystemHandle; + drawingContext.document.handle = handle; await loadFileAndAdjustCanvas(file, drawingContext); } }); diff --git a/src/helpers/register-drag-drop.ts b/src/helpers/register-drag-drop.ts index d6d7d564..1d2b41dc 100644 --- a/src/helpers/register-drag-drop.ts +++ b/src/helpers/register-drag-drop.ts @@ -1,4 +1,3 @@ -import type { FileSystemHandle } from 'browser-fs-access'; import type { DrawingContext } from '../models/drawing-context'; import { loadFileAndAdjustCanvas } from './load-file-and-adjust-canvas'; import { updateDocumentContext } from './update-document-context'; @@ -22,20 +21,22 @@ export function registerDragDrop( ); for (const file of files) { const handle = await file.getAsFileSystemHandle(); - if (handle?.kind !== 'file') { + if (!handle || !isFileHandle(handle)) { continue; } - const blob = await (handle as FileSystemFileHandle).getFile(); + const blob = await handle.getFile(); await loadFileAndAdjustCanvas(blob, drawingContext); - updateDocumentContext( - handle as unknown as FileSystemHandle, - handle.name, - drawingContext, - ); + updateDocumentContext(handle, handle.name, drawingContext); return; } }); } + +function isFileHandle( + handle: FileSystemHandle, +): handle is FileSystemFileHandle { + return handle.kind === 'file'; +} diff --git a/src/helpers/update-document-context.ts b/src/helpers/update-document-context.ts index fe97a644..105c5c59 100644 --- a/src/helpers/update-document-context.ts +++ b/src/helpers/update-document-context.ts @@ -1,4 +1,3 @@ -import type { FileSystemHandle } from 'browser-fs-access'; import type { DrawingContext } from '../models/drawing-context'; import { updateContext } from './update-context'; diff --git a/src/menus/file/open.ts b/src/menus/file/open.ts index 74fc65b5..118f0c89 100644 --- a/src/menus/file/open.ts +++ b/src/menus/file/open.ts @@ -3,7 +3,6 @@ import { loadFileAndAdjustCanvas } from '../../helpers/load-file-and-adjust-canv import { updateDocumentContext } from '../../helpers/update-document-context'; import type { MenuAction } from '../../models/menu-action'; import type { DrawingContext } from '../../models/drawing-context'; -import type { FileSystemHandle } from 'browser-fs-access'; export class OpenAction implements MenuAction { async execute(drawingContext: DrawingContext): Promise { @@ -11,11 +10,7 @@ export class OpenAction implements MenuAction { extensions: ['.png'], description: 'PNG Files', }); - updateDocumentContext( - file.handle as unknown as FileSystemHandle, - file.name, - drawingContext, - ); + updateDocumentContext(file.handle, file.name, drawingContext); await loadFileAndAdjustCanvas(file, drawingContext); } diff --git a/src/models/drawing-context.ts b/src/models/drawing-context.ts index d15a3c4e..51cc2ae9 100644 --- a/src/models/drawing-context.ts +++ b/src/models/drawing-context.ts @@ -1,4 +1,3 @@ -import type { FileSystemHandle } from 'browser-fs-access'; import type { History } from '../helpers/history'; import type { Brush } from './brush'; import type { FillStyle } from './fill-style';