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:
parent
bfe8b272ba
commit
d32af14a98
51
src/main/holdUntilFileExist.ts
Normal file
51
src/main/holdUntilFileExist.ts
Normal 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 };
|
||||||
@ -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({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user