From 199fc4be1afe18f97202d50cf524fcb8e13ccfb9 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Wed, 20 Nov 2024 23:38:17 -0500 Subject: [PATCH] Fix leaked electron impl in types library (#320) --- src/constants.ts | 9 +++++++++ src/main_types.ts | 7 +------ src/models/DownloadManager.ts | 11 ++--------- src/preload.ts | 4 ++-- vite.types.config.ts | 1 + 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 5e973bef..74bc5d99 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -108,3 +108,12 @@ export const DEFAULT_SERVER_ARGS = { }; export type ServerArgs = typeof DEFAULT_SERVER_ARGS; + +export enum DownloadStatus { + PENDING = 'pending', + IN_PROGRESS = 'in_progress', + COMPLETED = 'completed', + PAUSED = 'paused', + ERROR = 'error', + CANCELLED = 'cancelled', +} diff --git a/src/main_types.ts b/src/main_types.ts index d8ef1e8f..b03d0dc5 100644 --- a/src/main_types.ts +++ b/src/main_types.ts @@ -1,8 +1,3 @@ export * from './constants'; -export * from './models/DownloadManager'; +export type { DownloadManager, Download } from './models/DownloadManager'; export type { ElectronAPI } from './preload'; - -import { ElectronAPI } from './preload'; -declare global { - const electronAPI: ElectronAPI; -} diff --git a/src/models/DownloadManager.ts b/src/models/DownloadManager.ts index 6f627235..88badcf5 100644 --- a/src/models/DownloadManager.ts +++ b/src/models/DownloadManager.ts @@ -3,7 +3,8 @@ import * as path from 'path'; import * as fs from 'fs'; import { IPC_CHANNELS } from '../constants'; import log from 'electron-log/main'; -import { AppWindow } from '../main-process/appWindow'; +import type { AppWindow } from '../main-process/appWindow'; +import { DownloadStatus } from '../main_types'; export interface Download { url: string; @@ -13,14 +14,6 @@ export interface Download { item: DownloadItem | null; } -export enum DownloadStatus { - PENDING = 'pending', - IN_PROGRESS = 'in_progress', - COMPLETED = 'completed', - PAUSED = 'paused', - ERROR = 'error', - CANCELLED = 'cancelled', -} export interface DownloadState { url: string; filename: string; diff --git a/src/preload.ts b/src/preload.ts index f117070d..da1556a8 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -1,6 +1,6 @@ import { contextBridge, ipcRenderer } from 'electron'; -import { IPC_CHANNELS, ELECTRON_BRIDGE_API, ProgressStatus } from './constants'; -import { DownloadState, DownloadStatus } from './models/DownloadManager'; +import { IPC_CHANNELS, ELECTRON_BRIDGE_API, ProgressStatus, DownloadStatus } from './constants'; +import type { DownloadState } from './models/DownloadManager'; import path from 'node:path'; /** diff --git a/vite.types.config.ts b/vite.types.config.ts index ffcf2005..76fa6c80 100644 --- a/vite.types.config.ts +++ b/vite.types.config.ts @@ -13,6 +13,7 @@ export default defineConfig({ rollupOptions: { external: ['electron'], }, + minify: false, }, plugins: [ dts({