Skip to content

Commit

Permalink
feat: Update Electron Download types (#1621)
Browse files Browse the repository at this point in the history
* feat: Update Electron Download types

* Fix vite rollup

---------

Co-authored-by: Oto Ciulis <oto.ciulis@gmail.com>
Co-authored-by: huchenlei <huchenlei@proton.me>
  • Loading branch information
3 people authored Nov 21, 2024
1 parent c857e7d commit 94f5031
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},
"dependencies": {
"@atlaskit/pragmatic-drag-and-drop": "^1.3.1",
"@comfyorg/comfyui-electron-types": "^0.2.16",
"@comfyorg/comfyui-electron-types": "^0.3.1",
"@comfyorg/litegraph": "^0.8.31",
"@primevue/themes": "^4.0.5",
"@vueuse/core": "^11.0.0",
Expand Down
24 changes: 13 additions & 11 deletions src/stores/electronDownloadStore.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
import { isElectron, electronAPI } from '@/utils/envUtil'
import { DownloadState, DownloadStatus } from '@comfyorg/comfyui-electron-types'

export interface ElectronDownload {
url: string
status: 'paused' | 'in_progress' | 'cancelled'
progress: number
savePath: string
filename: string
export interface ElectronDownload
extends Pick<DownloadState, 'url' | 'filename'> {
progress?: number
savePath?: string
status?: DownloadStatus
}

/** Electron donwloads store handler */
Expand All @@ -20,15 +20,14 @@ export const useElectronDownloadStore = defineStore('downloads', () => {

const initialize = async () => {
if (isElectron()) {
const allDownloads: ElectronDownload[] =
(await DownloadManager.getAllDownloads()) as unknown as ElectronDownload[]
const allDownloads = await DownloadManager.getAllDownloads()

for (const download of allDownloads) {
downloads.value.push(download)
}

// ToDO: replace with ElectronDownload type
DownloadManager.onDownloadProgress((data: any) => {
DownloadManager.onDownloadProgress((data) => {
if (!findByUrl(data.url)) {
downloads.value.push(data)
}
Expand All @@ -51,8 +50,11 @@ export const useElectronDownloadStore = defineStore('downloads', () => {
url,
savePath,
filename
}: Pick<ElectronDownload, 'url' | 'savePath' | 'filename'>) =>
DownloadManager.startDownload(url, savePath, filename)
}: {
url: string
savePath: string
filename: string
}) => DownloadManager.startDownload(url, savePath, filename)
const pause = (url: string) => DownloadManager.pauseDownload(url)
const resume = (url: string) => DownloadManager.resumeDownload(url)
const cancel = (url: string) => DownloadManager.cancelDownload(url)
Expand Down
5 changes: 4 additions & 1 deletion vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ export default defineConfig({
rollupOptions: {
// Disabling tree-shaking
// Prevent vite remove unused exports
treeshake: false
treeshake: false,
external: [
'electron'
]
}
},

Expand Down

0 comments on commit 94f5031

Please sign in to comment.