Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions electron/main/ipc-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function runExtensionSetup(
}

export function setupIpcHandlers(pythonBridge: PythonBridge, getWindow: WindowGetter): void {
const activeDownloads = new Map<string, { percent: number; file?: string; fileIndex?: number; totalFiles?: number }>()
// Logging from renderer
ipcMain.on('log:error', (_event, message: string) => logger.error(`[Renderer] ${message}`))
ipcMain.handle('log:getPath', () => join(app.getPath('userData'), 'logs', 'modly.log'))
Expand Down Expand Up @@ -317,14 +318,22 @@ export function setupIpcHandlers(pythonBridge: PythonBridge, getWindow: WindowGe
return isModelDownloaded(modelsDir, modelId)
})

ipcMain.handle('model:activeDownloads', () =>
[...activeDownloads.entries()].map(([modelId, progress]) => ({ modelId, ...progress }))
)

ipcMain.handle('model:download', async (event, { repoId, modelId, skipPrefixes }: { repoId: string; modelId: string; skipPrefixes?: string[] }) => {
activeDownloads.set(modelId, { percent: 0 })
try {
await downloadModelFromHF(repoId, modelId, (progress) => {
activeDownloads.set(modelId, progress)
event.sender.send('model:downloadProgress', { modelId, ...progress })
}, skipPrefixes)
return { success: true }
} catch (err) {
return { success: false, error: String(err) }
} finally {
activeDownloads.delete(modelId)
}
})

Expand Down
1 change: 1 addition & 0 deletions electron/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ contextBridge.exposeInMainWorld('electron', {
delete: (modelId: string) => ipcRenderer.invoke('model:delete', modelId),
unloadAll: () => ipcRenderer.invoke('model:unloadAll'),
showInFolder: (modelId: string) => ipcRenderer.invoke('model:showInFolder', modelId),
activeDownloads: (): Promise<{ modelId: string; percent: number; file?: string; fileIndex?: number; totalFiles?: number }[]> => ipcRenderer.invoke('model:activeDownloads'),
onProgress: (cb: (data: { modelId: string; percent: number; file?: string; fileIndex?: number; totalFiles?: number; status?: string }) => void) => {
ipcRenderer.on('model:downloadProgress', (_event, data) => cb(data))
},
Expand Down
10 changes: 9 additions & 1 deletion src/areas/models/ModelsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ export default function ModelsPage(): JSX.Element {
}

useEffect(() => {
loadExtensions().then(() => {
loadExtensions().then(async () => {
const exts = useExtensionsStore.getState().modelExtensions
const active = await window.electron.model.activeDownloads()
if (active.length > 0) {
setDownloading((prev) => {
const next = { ...prev }
for (const { modelId, ...progress } of active) if (!next[modelId]) next[modelId] = progress
return next
})
}
refreshInstalledIds(exts)
})
window.electron.model.onProgress(({ modelId: id, percent, file, fileIndex, totalFiles }) => {
Expand Down
34 changes: 17 additions & 17 deletions src/areas/models/components/ExtensionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@ export function ExtensionCard({ ext, installedIds, downloading, loadError, disab
</svg>
<span className="text-[10px] font-semibold text-emerald-400">Ready</span>
</div>
) : isDownloading ? (
<div className="flex flex-col gap-1">
<div className="flex items-center justify-between">
<span className="text-[10px] text-zinc-500 truncate max-w-[100px]" title={dlFile}>
{dlFile ?? 'Downloading…'}
</span>
<span className="text-[10px] font-mono text-zinc-400 shrink-0 ml-1">
{dlFileIndex && dlTotalFiles ? `${dlFileIndex}/${dlTotalFiles} · ${dlPercent}%` : `${dlPercent}%`}
</span>
</div>
<div className="h-1 rounded-full bg-zinc-800 overflow-hidden">
<div
className="h-full rounded-full bg-accent transition-all duration-300"
style={{ width: `${dlPercent}%` }}
/>
</div>
</div>
) : installed ? (
<div className="flex items-center gap-1.5 px-2 py-1 rounded-lg bg-emerald-950/40 border border-emerald-800/30">
<svg width="8" height="8" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" className="text-emerald-400 shrink-0">
Expand All @@ -192,23 +209,6 @@ export function ExtensionCard({ ext, installedIds, downloading, loadError, disab
</button>
)}
</div>
) : isDownloading ? (
<div className="flex flex-col gap-1">
<div className="flex items-center justify-between">
<span className="text-[10px] text-zinc-500 truncate max-w-[100px]" title={dlFile}>
{dlFile ?? 'Downloading…'}
</span>
<span className="text-[10px] font-mono text-zinc-400 shrink-0 ml-1">
{dlFileIndex && dlTotalFiles ? `${dlFileIndex}/${dlTotalFiles} · ${dlPercent}%` : `${dlPercent}%`}
</span>
</div>
<div className="h-1 rounded-full bg-zinc-800 overflow-hidden">
<div
className="h-full rounded-full bg-accent transition-all duration-300"
style={{ width: `${dlPercent}%` }}
/>
</div>
</div>
) : (
<button
onClick={() => !disabled && onInstall(node, fullId)}
Expand Down