update
This commit is contained in:
@@ -13,11 +13,12 @@ import {
|
||||
Textarea
|
||||
} from '@fluentui/react-components';
|
||||
import {ToolTipButton} from '../components/ToolTipButton';
|
||||
import {ArrowClockwise20Regular, ArrowDownload20Regular, Open20Regular} from '@fluentui/react-icons';
|
||||
import {ArrowClockwise20Regular, ArrowDownload20Regular, Folder20Regular, Open20Regular} from '@fluentui/react-icons';
|
||||
import {observer} from 'mobx-react-lite';
|
||||
import commonStore, {ModelSourceItem} from '../stores/commonStore';
|
||||
import {BrowserOpenURL} from '../../wailsjs/runtime';
|
||||
import {DownloadFile} from '../../wailsjs/go/backend_golang/App';
|
||||
import {DownloadFile, OpenFileFolder} from '../../wailsjs/go/backend_golang/App';
|
||||
import manifest from '../../../manifest.json';
|
||||
|
||||
const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
createTableColumn<ModelSourceItem>({
|
||||
@@ -39,7 +40,10 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
createTableColumn<ModelSourceItem>({
|
||||
columnId: 'desc',
|
||||
compare: (a, b) => {
|
||||
return a.desc['en'].localeCompare(b.desc['en']);
|
||||
if (a.desc && b.desc)
|
||||
return a.desc['en'].localeCompare(b.desc['en']);
|
||||
else
|
||||
return 0;
|
||||
},
|
||||
renderHeaderCell: () => {
|
||||
return 'Desc';
|
||||
@@ -47,7 +51,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
renderCell: (item) => {
|
||||
return (
|
||||
<TableCellLayout>
|
||||
{item.desc['en']}
|
||||
{item.desc && item.desc['en']}
|
||||
</TableCellLayout>
|
||||
);
|
||||
}
|
||||
@@ -75,7 +79,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
a.lastUpdatedMs = Date.parse(a.lastUpdated);
|
||||
if (!b.lastUpdatedMs)
|
||||
b.lastUpdatedMs = Date.parse(b.lastUpdated);
|
||||
return a.lastUpdatedMs - b.lastUpdatedMs;
|
||||
return b.lastUpdatedMs - a.lastUpdatedMs;
|
||||
},
|
||||
renderHeaderCell: () => {
|
||||
return 'Last updated';
|
||||
@@ -88,7 +92,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
createTableColumn<ModelSourceItem>({
|
||||
columnId: 'actions',
|
||||
compare: (a, b) => {
|
||||
return a.isDownloading ? 0 : a.isLocal ? 1 : 2;
|
||||
return a.isDownloading ? 0 : a.isLocal ? -1 : 1;
|
||||
},
|
||||
renderHeaderCell: () => {
|
||||
return 'Actions';
|
||||
@@ -97,12 +101,19 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
return (
|
||||
<TableCellLayout>
|
||||
<div className="flex gap-1">
|
||||
<ToolTipButton desc="Download" icon={<ArrowDownload20Regular/>} onClick={() => {
|
||||
DownloadFile(`./models/${item.name}`, item.downloadUrl);
|
||||
}}/>
|
||||
<ToolTipButton desc="Open Url" icon={<Open20Regular/>} onClick={() => {
|
||||
BrowserOpenURL(item.url);
|
||||
}}/>
|
||||
{
|
||||
item.isLocal &&
|
||||
<ToolTipButton desc="Open Folder" icon={<Folder20Regular/>} onClick={() => {
|
||||
OpenFileFolder(`.\\${manifest.localModelPath}\\${item.name}`);
|
||||
}}/>
|
||||
}
|
||||
{item.downloadUrl && !item.isLocal &&
|
||||
<ToolTipButton desc="Download" icon={<ArrowDownload20Regular/>} onClick={() => {
|
||||
DownloadFile(`./${manifest.localModelPath}/${item.name}`, item.downloadUrl!);
|
||||
}}/>}
|
||||
{item.url && <ToolTipButton desc="Open Url" icon={<Open20Regular/>} onClick={() => {
|
||||
BrowserOpenURL(item.url!);
|
||||
}}/>}
|
||||
</div>
|
||||
</TableCellLayout>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import commonStore, {ModelSourceItem} from './stores/commonStore';
|
||||
import {ReadJson, SaveJson} from '../wailsjs/go/backend_golang/App';
|
||||
import {ListDirFiles, ReadJson, SaveJson} from '../wailsjs/go/backend_golang/App';
|
||||
import manifest from '../../manifest.json';
|
||||
|
||||
export async function startup() {
|
||||
@@ -15,14 +15,53 @@ async function initConfig() {
|
||||
await ReadJson('cache.json').then((cacheData: Cache) => {
|
||||
cache = cacheData;
|
||||
}).catch(
|
||||
() => {
|
||||
async () => {
|
||||
cache = {models: manifest.models};
|
||||
SaveJson('cache.json', cache).catch(() => {
|
||||
await SaveJson('cache.json', cache).catch(() => {
|
||||
});
|
||||
}
|
||||
);
|
||||
// built-in
|
||||
commonStore.setModelSourceList(cache.models);
|
||||
|
||||
await ListDirFiles(manifest.localModelPath).then((data) => {
|
||||
cache.models.push(...data.flatMap(d => {
|
||||
if (!d.isDir && d.name.endsWith('.pth'))
|
||||
return [{
|
||||
name: d.name,
|
||||
size: d.size,
|
||||
lastUpdated: d.modTime,
|
||||
isLocal: true
|
||||
}];
|
||||
return [];
|
||||
}));
|
||||
}).catch(() => {
|
||||
});
|
||||
|
||||
for (let i = 0; i < cache.models.length; i++) {
|
||||
if (!cache.models[i].lastUpdatedMs)
|
||||
cache.models[i].lastUpdatedMs = Date.parse(cache.models[i].lastUpdated);
|
||||
|
||||
for (let j = i + 1; j < cache.models.length; j++) {
|
||||
if (!cache.models[j].lastUpdatedMs)
|
||||
cache.models[j].lastUpdatedMs = Date.parse(cache.models[j].lastUpdated);
|
||||
|
||||
if (cache.models[i].name === cache.models[j].name && cache.models[i].size === cache.models[j].size) {
|
||||
if (cache.models[i].lastUpdatedMs! < cache.models[j].lastUpdatedMs!) {
|
||||
cache.models[i] = Object.assign({}, cache.models[i], cache.models[j]);
|
||||
} else {
|
||||
cache.models[i] = Object.assign({}, cache.models[j], cache.models[i]);
|
||||
}
|
||||
cache.models.splice(j, 1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
// local files
|
||||
commonStore.setModelSourceList(cache.models);
|
||||
await SaveJson('cache.json', cache).catch(() => {
|
||||
});
|
||||
|
||||
const manifestUrls = commonStore.modelSourceManifestList.split(/[,,;;\n]/);
|
||||
const requests = manifestUrls.filter(url => url.endsWith('.json')).map(
|
||||
url => fetch(url, {cache: 'no-cache'}).then(r => r.json()));
|
||||
@@ -40,7 +79,8 @@ async function initConfig() {
|
||||
cache.models = cache.models.filter((model, index, self) => {
|
||||
return model.name.endsWith('.pth') && index === self.findIndex(m => m.SHA256 === model.SHA256 && m.size === model.size);
|
||||
});
|
||||
// remote files
|
||||
commonStore.setModelSourceList(cache.models);
|
||||
SaveJson('cache.json', cache).catch(() => {
|
||||
await SaveJson('cache.json', cache).catch(() => {
|
||||
});
|
||||
}
|
||||
@@ -9,12 +9,12 @@ export enum ModelStatus {
|
||||
|
||||
export type ModelSourceItem = {
|
||||
name: string;
|
||||
desc: { [lang: string]: string; };
|
||||
size: number;
|
||||
lastUpdated: string;
|
||||
SHA256: string;
|
||||
url: string;
|
||||
downloadUrl: string;
|
||||
desc?: { [lang: string]: string; };
|
||||
SHA256?: string;
|
||||
url?: string;
|
||||
downloadUrl?: string;
|
||||
isLocal?: boolean;
|
||||
isDownloading?: boolean;
|
||||
lastUpdatedMs?: number;
|
||||
|
||||
Reference in New Issue
Block a user