1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add holdUntilRendererStaticsExist (untested)

Signed-off-by: Hung-Han (Henry) Chen <1474479+chenhunghan@users.noreply.github.com>
This commit is contained in:
Hung-Han (Henry) Chen 2021-01-07 11:14:53 +08:00
parent bfe8b272ba
commit d32af14a98
No known key found for this signature in database
GPG Key ID: A28B7834EFA73792
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,51 @@
import fs from "fs";
import path from "path";
import logger from "./logger";
import { appName, publicPath } from "../common/vars";
import { webpackLensRenderer } from "../../webpack.renderer";
const rendererConfig = webpackLensRenderer({ showVars: false });
const { optimization } = rendererConfig;
const holdUntilFileExist = ({
file, watchInterval, msg
}: {
file: string, watchInterval: number, msg: string
}): Promise<Boolean> =>
new Promise((resolve) => {
const timeout = setInterval(() => {
const fileExists = fs.existsSync(file);
if (fileExists) {
clearInterval(timeout);
resolve(true);
} else {
logger.info(msg);
}
}, watchInterval);
});
const holdUntilRendererStaticsExist = async (
{ watchInterval }: { watchInterval: number }
): Promise<void> => {
const dir = `${__static}${publicPath}`;
// @ts-ignore (type definition is broken in webpack-dev-server 4 beta0)
const chuckFileName = optimization.splitChunks?.name;
// @ts-ignore (type definition is broken in webpack-dev-server 4 beta0)
const runtimeChuckFileName = optimization.runtimeChunk?.name;
await Promise.all([
`${appName}.js`, `${appName}.html`,
`${chuckFileName}.js`, `${runtimeChuckFileName}.js`
].map((filename) =>
holdUntilFileExist({
file: path.join(dir, filename),
watchInterval,
msg: `waiting for ${filename}... have you compiled renderer process statics? 🤔`
})
));
};
export default holdUntilFileExist;
export { holdUntilRendererStaticsExist };

View File

@ -9,6 +9,7 @@ import { initTray } from "./tray";
import { Singleton } from "../common/utils"; import { Singleton } from "../common/utils";
import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames"; import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames";
import { reload } from "./reload"; import { reload } from "./reload";
import { holdUntilRendererStaticsExist } from "./holdUntilFileExist";
export class WindowManager extends Singleton { export class WindowManager extends Singleton {
protected mainWindow: BrowserWindow; protected mainWindow: BrowserWindow;
@ -31,6 +32,11 @@ export class WindowManager extends Singleton {
} }
async initMainWindow(showSplash = true) { async initMainWindow(showSplash = true) {
if (process.env.NODE_ENV === "development") {
await holdUntilRendererStaticsExist({ watchInterval: 5000 });
}
// Manage main window size and position with state persistence // Manage main window size and position with state persistence
if (!this.windowState) { if (!this.windowState) {
this.windowState = windowStateKeeper({ this.windowState = windowStateKeeper({