Skip to content

Commit

Permalink
fix(dx): merge script and fix host rewrite
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Nov 18, 2024
1 parent a60db7e commit 3fa3bd5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 35 deletions.
33 changes: 0 additions & 33 deletions apps/renderer/__debug_proxy.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
<!doctype html>
<html>
<head>
<script type="module">
const searchParams = new URLSearchParams(window.location.search)
const debugHost = searchParams.get("debug-host")

const resetSessionStorage = () => {
sessionStorage.removeItem("debug-host")
}

const resetParams = searchParams.delete("debug-host")
if (resetParams) {
resetSessionStorage()
}

const debugHostInSessionStorage = sessionStorage.getItem("debug-host")

const host = debugHost || debugHostInSessionStorage || "https://localhost:2233"
if (debugHost) {
sessionStorage.setItem("debug-host", debugHost)
}

const createRefreshRuntimeScript = `
import RefreshRuntime from "${host}/@react-refresh";
RefreshRuntime.injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;
window.__vite_plugin_react_preamble_installed__ = true;
`
const $script = document.createElement("script")
$script.innerHTML = createRefreshRuntimeScript
$script.type = "module"
document.head.appendChild($script)
</script>

<title>Debug Proxy</title>
<script type="module" src="./__debug_proxy.ts"></script>
</head>
Expand Down
33 changes: 31 additions & 2 deletions apps/renderer/__debug_proxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
const host = "https://localhost:2233"

globalThis["__DEBUG_PROXY__"] = true

const searchParams = new URLSearchParams(window.location.search)
const debugHost = searchParams.get("debug-host")

const resetSessionStorage = () => {
sessionStorage.removeItem("debug-host")
}

const resetParams = searchParams.get("reset")
if (resetParams) {
resetSessionStorage()
}

const debugHostInSessionStorage = sessionStorage.getItem("debug-host")

const host = debugHost || debugHostInSessionStorage || "https://localhost:2233"
if (debugHost) {
sessionStorage.setItem("debug-host", debugHost)
}

const createRefreshRuntimeScript = `
import RefreshRuntime from "${host}/@react-refresh";
RefreshRuntime.injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;
window.__vite_plugin_react_preamble_installed__ = true;
`
const $script = document.createElement("script")
$script.innerHTML = createRefreshRuntimeScript
$script.type = "module"
document.head.append($script)

fetch(`${host}`)
.then((res) => res.text())
.then((html) => {
Expand Down

0 comments on commit 3fa3bd5

Please sign in to comment.