Skip to content

Commit

Permalink
Wait for DOM updates before showing hub window (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Oct 5, 2024
1 parent b4ae616 commit 49c045e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 42 deletions.
7 changes: 7 additions & 0 deletions src/hub/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,13 @@ setInterval(() => {

async function handleMainMessage(message: NamedMessage) {
switch (message.name) {
case "show-when-ready":
// Wait for DOM updates to finish
window.requestAnimationFrame(() => {
window.sendMainMessage("show");
});
break;

case "restore-state":
restoreState(message.data);
break;
Expand Down
88 changes: 46 additions & 42 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ async function handleHubMessage(window: BrowserWindow, message: NamedMessage) {
if (window.isDestroyed()) return;
let windowId = window.id;
switch (message.name) {
case "show":
window.show();
break;

case "alert":
dialog.showMessageBox(window, {
type: "info",
Expand Down Expand Up @@ -2225,48 +2229,6 @@ function createHubWindow(state?: WindowState) {
});

// Show window when loaded
window.once("ready-to-show", () => {
window.show();
if (isBeta()) {
if (isBetaExpired()) {
dialog
.showMessageBox(window, {
type: "info",
title: "Alert",
message: "Beta is complete",
detail:
"The AdvantageScope beta is complete. " +
(DISTRIBUTOR === Distributor.WPILib
? "Please update to the latest stable release of WPILib."
: "Please download the latest stable release of AdvantageScope from GitHub."),
buttons: ["Quit", "Ignore"],
defaultId: 0
})
.then((result) => {
if (result.response === 0) app.quit();
});
} else if (!isBetaWelcomeComplete()) {
openBetaWelcome(window);
} else if (shouldPromptBetaSurvey()) {
dialog
.showMessageBox(window, {
type: "info",
title: "Alert",
message: "We need your help!",
detail:
"Please take 10 minutes to give us some feedback on the AdvantageScope beta. Users like you help us make AdvantageScope better for everyone!",
buttons: ["Give Feedback", "Not Now"]
})
.then((result) => {
if (result.response === 0) {
openBetaSurvey();
} else {
delayBetaSurvey();
}
});
}
}
});
let firstLoad = true;
let createPorts = () => {
const { port1, port2 } = new MessageChannelMain();
Expand Down Expand Up @@ -2300,6 +2262,7 @@ function createHubWindow(state?: WindowState) {
});
sendMessage(window, "show-update-button", updateChecker.getShouldPrompt());
sendMessage(window, "show-feedback-button", isBeta());
sendMessage(window, "show-when-ready");
sendAllPreferences();
sendActiveSatellites();
if (fs.existsSync(TYPE_MEMORY_FILENAME)) {
Expand All @@ -2314,6 +2277,47 @@ function createHubWindow(state?: WindowState) {
}
}
firstLoad = false;

// Beta init
if (isBeta()) {
if (isBetaExpired()) {
dialog
.showMessageBox(window, {
type: "info",
title: "Alert",
message: "Beta is complete",
detail:
"The AdvantageScope beta is complete. " +
(DISTRIBUTOR === Distributor.WPILib
? "Please update to the latest stable release of WPILib."
: "Please download the latest stable release of AdvantageScope from GitHub."),
buttons: ["Quit", "Ignore"],
defaultId: 0
})
.then((result) => {
if (result.response === 0) app.quit();
});
} else if (!isBetaWelcomeComplete()) {
openBetaWelcome(window);
} else if (shouldPromptBetaSurvey()) {
dialog
.showMessageBox(window, {
type: "info",
title: "Alert",
message: "We need your help!",
detail:
"Please take 10 minutes to give us some feedback on the AdvantageScope beta. Users like you help us make AdvantageScope better for everyone!",
buttons: ["Give Feedback", "Not Now"]
})
.then((result) => {
if (result.response === 0) {
openBetaSurvey();
} else {
delayBetaSurvey();
}
});
}
}
});
window.on("close", (event) => {
if (hubExportingIds.has(window.id)) {
Expand Down

0 comments on commit 49c045e

Please sign in to comment.