Disable image preload

This commit is contained in:
Fedor Indutny 2023-05-01 13:42:34 -07:00 committed by GitHub
parent 6154b83720
commit 00349b5b33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 0 additions and 58 deletions

View file

@ -3,8 +3,6 @@
import { join, relative, normalize } from 'path';
import fastGlob from 'fast-glob';
import glob from 'glob';
import pify from 'pify';
import fse from 'fs-extra';
import { map, isString } from 'lodash';
import normalizePath from 'normalize-path';
@ -113,16 +111,6 @@ export const getAllDraftAttachments = async (
return map(files, file => relative(dir, file));
};
export const getBuiltInImages = async (): Promise<ReadonlyArray<string>> => {
const dir = join(__dirname, '../images');
const pattern = join(dir, '**', '*.svg');
// Note: we cannot use fast-glob here because, inside of .asar files, readdir will not
// honor the withFileTypes flag: https://github.com/electron/electron/issues/19074
const files = await pify(glob)(pattern, { nodir: true });
return map(files, file => relative(dir, file));
};
export const clearTempPath = (userDataPath: string): Promise<void> => {
const tempPath = getTempPath(userDataPath);
return fse.emptyDir(tempPath);

View file

@ -2222,27 +2222,6 @@ ipc.on('delete-all-data', () => {
}
});
ipc.on('get-built-in-images', async () => {
if (!mainWindow) {
getLogger().warn('ipc/get-built-in-images: No mainWindow!');
return;
}
try {
const images = await attachments.getBuiltInImages();
mainWindow.webContents.send('get-success-built-in-images', null, images);
} catch (error) {
if (mainWindow && mainWindow.webContents) {
mainWindow.webContents.send('get-success-built-in-images', error.message);
} else {
getLogger().error(
'Error handling get-built-in-images:',
Errors.toLogFormat(error)
);
}
}
});
ipc.on('get-config', async event => {
const theme = await getResolvedThemeSetting();

View file

@ -543,19 +543,6 @@ export async function startApp(): Promise<void> {
startInteractionMode();
// Load these images now to ensure that they don't flicker on first use
window.preloadedImages = [];
function preload(list: ReadonlyArray<string>) {
for (let index = 0, max = list.length; index < max; index += 1) {
const image = new Image();
image.src = `./images/${list[index]}`;
window.preloadedImages.push(image);
}
}
const builtInImages = await window.IPC.getBuiltInImages();
preload(builtInImages);
// We add this to window here because the default Node context is erased at the end
// of preload.js processing
window.setImmediate = window.nodeSetImmediate;

1
ts/window.d.ts vendored
View file

@ -70,7 +70,6 @@ export type IPCType = {
};
drawAttention: () => void;
getAutoLaunch: () => Promise<boolean>;
getBuiltInImages: () => Promise<Array<string>>;
getMediaCameraPermissions: () => Promise<boolean>;
getMediaPermissions: () => Promise<boolean>;
logAppLoadedEvent?: (options: { processedCount?: number }) => void;

View file

@ -83,17 +83,6 @@ const IPC: IPCType = {
ipc.send('draw-attention');
},
getAutoLaunch: () => ipc.invoke('get-auto-launch'),
getBuiltInImages: () =>
new Promise((resolve, reject) => {
ipc.once('get-success-built-in-images', (_event, error, value) => {
if (error) {
return reject(new Error(error));
}
return resolve(value);
});
ipc.send('get-built-in-images');
}),
getMediaPermissions: () => ipc.invoke('settings:get:mediaPermissions'),
getMediaCameraPermissions: () =>
ipc.invoke('settings:get:mediaCameraPermissions'),