mirror of
https://github.com/anyproto/anytype-ts.git
synced 2025-06-08 05:57:02 +09:00
fix image preloading
This commit is contained in:
parent
076ff30394
commit
b972b86de1
2 changed files with 21 additions and 15 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -16,4 +16,5 @@ docs/*
|
|||
electron/env.json
|
||||
src/json/schema
|
||||
dist/bundle-back.js
|
||||
dist/builder-debug.yml
|
||||
dist/builder-debug.yml
|
||||
dist/mac-arm64/
|
||||
|
|
|
@ -307,27 +307,32 @@ class App extends React.Component<Props, State> {
|
|||
this.setWindowEvents();
|
||||
};
|
||||
|
||||
preload (callBack?: () => void) {
|
||||
preload () {
|
||||
const prefix = './dist/';
|
||||
const fr = new RegExp(/\.png|gif|jpg|svg/);
|
||||
const images: string[] = [];
|
||||
|
||||
const readDir = (prefix: string, folder: string) => {
|
||||
const fp = path.join(prefix, folder);
|
||||
const files = fs.readdirSync(fp);
|
||||
|
||||
for (let file of files) {
|
||||
const fn = path.join(fp, file);
|
||||
const isDir = fs.lstatSync(fn).isDirectory();
|
||||
if (isDir) {
|
||||
readDir(fp, file);
|
||||
} else
|
||||
if (file.match(fr)) {
|
||||
images.push(fn.replace(/^dist\//, ''));
|
||||
fs.readdir(fp, (err: any, files: string[]) => {
|
||||
if (err) {
|
||||
return;
|
||||
};
|
||||
};
|
||||
|
||||
let images: string[] = [];
|
||||
for (let file of files) {
|
||||
const fn = path.join(fp, file);
|
||||
const isDir = fs.lstatSync(fn).isDirectory();
|
||||
if (isDir) {
|
||||
readDir(fp, file);
|
||||
} else
|
||||
if (file.match(fr)) {
|
||||
images.push(fn.replace(/^dist\//, ''));
|
||||
};
|
||||
};
|
||||
Util.cacheImages(images);
|
||||
});
|
||||
};
|
||||
readDir(prefix, 'img');
|
||||
Util.cacheImages(images, callBack);
|
||||
};
|
||||
|
||||
setIpcEvents () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue