Skip to content

Commit

Permalink
conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu-dev committed Oct 11, 2024
2 parents e8e2d3b + 007f83a commit cdf6394
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
43 changes: 35 additions & 8 deletions main/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,37 @@ function createGraphqlSeverProcess() {
});
}

app.on("ready", () => {
async function isGraphQLServerReady(url: string): Promise<boolean> {
try {
const response = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query: "{ __typename }" }),
});
console.log(url, response);
return response.ok;
} catch (error) {
console.error("Error pinging GraphQL server:", error);
return false;
}
}

async function waitForGraphQLServer(
url: string,
timeout: number = 30000,
): Promise<void> {
const startTime = Date.now();
while (Date.now() - startTime < timeout) {
const isReady = await isGraphQLServerReady(url);
if (isReady) {
return;
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
throw new Error("Timed out starting GraphQL server");
}

app.on("ready", async () => {
mainWindow = createWindow("main", {
width: 1280,
height: 680,
Expand All @@ -72,16 +102,13 @@ app.on("ready", () => {
});
Menu.setApplicationMenu(initMenu(mainWindow, isProd));
createGraphqlSeverProcess();
await waitForGraphQLServer("http://localhost:9002/graphql");

if (isProd) {
setTimeout(async () => {
await mainWindow.loadURL("app://./");
}, 3000);
await mainWindow.loadURL("app://./");
} else {
setTimeout(async () => {
const port = process.argv[2];
await mainWindow.loadURL(`http://localhost:${port}`);
}, 2500);
const port = process.argv[2];
await mainWindow.loadURL(`http://localhost:${port}`);
}

// hit when middle-clicking buttons or <a href/> with a target set to _blank
Expand Down
8 changes: 5 additions & 3 deletions main/helpers/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ export function initMenu(
if (focusedWindow) focusedWindow.webContents.toggleDevTools();
},
},
{
type: "separator",
},
isProd
? { label: "hidden", visible: false }
: {
type: "separator",
},
{
label: "Import File",
accelerator: "CmdOrCtrl+I",
Expand Down

0 comments on commit cdf6394

Please sign in to comment.