display models that have not been fully downloaded in Downloads page, even if the program is restarted

This commit is contained in:
josc146
2023-06-23 16:03:57 +08:00
parent 447f4572b1
commit 97f6af595e
7 changed files with 73 additions and 19 deletions

View File

@@ -224,12 +224,12 @@ export const Configs: FC = observer(() => {
modelName: data.value
});
}}>
{!commonStore.modelSourceList.find(item => item.name === selectedConfig.modelParameters.modelName)?.isLocal
{!commonStore.modelSourceList.find(item => item.name === selectedConfig.modelParameters.modelName)?.isComplete
&& <option key={-1}
value={selectedConfig.modelParameters.modelName}>{selectedConfig.modelParameters.modelName}
</option>}
{commonStore.modelSourceList.map((modelItem, index) =>
modelItem.isLocal && <option key={index} value={modelItem.name}>{modelItem.name}</option>
modelItem.isComplete && <option key={index} value={modelItem.name}>{modelItem.name}</option>
)}
</Select>
<ToolTipButton desc={t('Manage Models')} icon={<DataUsageSettings20Regular />} onClick={() => {

View File

@@ -7,7 +7,7 @@ import { Divider, Field, ProgressBar } from '@fluentui/react-components';
import { bytesToGb, bytesToKb, bytesToMb, refreshLocalModels } from '../utils';
import { ToolTipButton } from '../components/ToolTipButton';
import { Folder20Regular, Pause20Regular, Play20Regular } from '@fluentui/react-icons';
import { ContinueDownload, OpenFileFolder, PauseDownload } from '../../wailsjs/go/backend_golang/App';
import { AddToDownloadList, OpenFileFolder, PauseDownload } from '../../wailsjs/go/backend_golang/App';
export type DownloadStatus = {
name: string;
@@ -30,10 +30,27 @@ export const Downloads: FC = observer(() => {
console.log('finishedModelsLen:', finishedModelsLen);
}, [finishedModelsLen]);
let displayList = commonStore.downloadList.slice();
const downloadListNames = displayList.map(s => s.name);
commonStore.lastUnfinishedModelDownloads.forEach((status) => {
const unfinishedIndex = downloadListNames.indexOf(status.name);
if (unfinishedIndex === -1) {
displayList.push(status);
} else {
const unfinishedStatus = displayList[unfinishedIndex];
if (unfinishedStatus.transferred < status.transferred) {
status.downloading = unfinishedStatus.downloading;
delete displayList[unfinishedIndex];
displayList.push(status);
}
}
});
displayList = displayList.reverse();
return (
<Page title={t('Downloads')} content={
<div className="flex flex-col gap-2 overflow-y-auto overflow-x-hidden p-1">
{commonStore.downloadList.slice().reverse().map((status, index) => {
{displayList.map((status, index) => {
const downloadProgress = `${status.progress.toFixed(2)}%`;
const downloadSpeed = `${status.downloading ? bytesToMb(status.speed) : '0'}MB/s`;
let downloadDetails: string;
@@ -59,7 +76,7 @@ export const Downloads: FC = observer(() => {
if (status.downloading)
PauseDownload(status.url);
else
ContinueDownload(status.url);
AddToDownloadList(status.path, status.url);
}} />}
<ToolTipButton desc={t('Open Folder')} icon={<Folder20Regular />} onClick={() => {
OpenFileFolder(status.path, false);

View File

@@ -31,7 +31,9 @@ export type ModelSourceItem = {
SHA256?: string;
url?: string;
downloadUrl?: string;
isComplete?: boolean;
isLocal?: boolean;
localSize?: number;
lastUpdatedMs?: number;
hide?: boolean;
};
@@ -125,7 +127,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
createTableColumn<ModelSourceItem>({
columnId: 'actions',
compare: (a, b) => {
return a.isLocal ? -1 : 1;
return a.isComplete ? -1 : 1;
},
renderHeaderCell: () => {
const { t } = useTranslation();
@@ -140,12 +142,12 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
<TableCellLayout>
<div className="flex gap-1">
{
item.isLocal &&
item.isComplete &&
<ToolTipButton desc={t('Open Folder')} icon={<Folder20Regular />} onClick={() => {
OpenFileFolder(`${commonStore.settings.customModelsPath}/${item.name}`, true);
}} />
}
{item.downloadUrl && !item.isLocal &&
{item.downloadUrl && !item.isComplete &&
<ToolTipButton desc={t('Download')} icon={<ArrowDownload20Regular />} onClick={() => {
toastWithButton(`${t('Downloading')} ${item.name}`, t('Check'), () => {
navigate({ pathname: '/downloads' });
@@ -203,7 +205,7 @@ export const Models: FC = observer(() => {
<div className="overflow-y-auto overflow-x-hidden">
<DataGridBody<ModelSourceItem>>
{({ item, rowId }) => (
(!item.hide || item.isLocal) &&
(!item.hide || item.isComplete) &&
<DataGridRow<ModelSourceItem> key={rowId}>
{({ renderCell }) => (
<DataGridCell>{renderCell(item)}</DataGridCell>