1
0
Fork 0
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:
Andrew Simachev 2021-09-15 23:19:05 +03:00
parent 076ff30394
commit b972b86de1
2 changed files with 21 additions and 15 deletions

3
.gitignore vendored
View file

@ -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/

View file

@ -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 () {