Skip to content

Commit

Permalink
Re-create the clients when they are updated via HMR
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed May 16, 2024
1 parent 45d0b8a commit a7d9594
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion web/src/context/installer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,28 @@ function InstallerClientProvider({
return;
}

console.warn(`Failed to connect to D-Bus (attempt ${attempt + 1})`);
console.warn(`Failed to connect to Agama API (attempt ${attempt + 1})`);
await new Promise(resolve => setTimeout(resolve, interval));
setAttempt(attempt + 1);
};

// allow hot replacement for the clients code
if (module.hot) {
// if anything coming from `import ... from "~/client"` is updated then this hook is called
module.hot.accept("~/client", async function() {
console.log("[Agama HMR] A client module has been updated");

const updated_client = await createDefaultClient();
if (await updated_client.isConnected()) {
console.log("[Agama HMR] Using new clients");
setValue(updated_client);
} else {
console.warn("[Agama HMR] Updating clients failed, using full page reload");
window.location.reload();
}
});
}

if (!value) connectClient();
}, [setValue, value, setAttempt, attempt, interval]);

Expand Down

0 comments on commit a7d9594

Please sign in to comment.