|
1 | 1 | import { spawn, spawnSync } from "node:child_process"; |
| 2 | +import { readFileSync } from "node:fs"; |
2 | 3 | import { resolve } from "node:path"; |
3 | 4 | import { fileURLToPath } from "node:url"; |
4 | 5 |
|
@@ -68,7 +69,7 @@ const holdOpenUntilSignal = ({ uiChild } = {}) => { |
68 | 69 | // alive with a timer until Tauri stops the dev process. |
69 | 70 | const timer = setInterval(() => {}, 60_000); |
70 | 71 |
|
71 | | - let stopping = false; |
| 72 | + let stopping = false; |
72 | 73 |
|
73 | 74 | const stop = () => { |
74 | 75 | if (stopping) return; |
@@ -124,6 +125,73 @@ const runPrepareSidecars = () => { |
124 | 125 | } |
125 | 126 | }; |
126 | 127 |
|
| 128 | +const readLinuxReleaseInfo = () => { |
| 129 | + try { |
| 130 | + const content = readFileSync("/etc/os-release", "utf8"); |
| 131 | + const values = new Map(); |
| 132 | + for (const line of content.split(/\r?\n/)) { |
| 133 | + if (!line || line.startsWith("#") || !line.includes("=")) continue; |
| 134 | + const separator = line.indexOf("="); |
| 135 | + const key = line.slice(0, separator); |
| 136 | + const rawValue = line.slice(separator + 1).trim(); |
| 137 | + const value = rawValue.replace(/^"|"$/g, ""); |
| 138 | + values.set(key, value); |
| 139 | + } |
| 140 | + return { |
| 141 | + id: values.get("ID") ?? "", |
| 142 | + like: values.get("ID_LIKE") ?? "", |
| 143 | + prettyName: values.get("PRETTY_NAME") ?? values.get("NAME") ?? "Linux", |
| 144 | + }; |
| 145 | + } catch { |
| 146 | + return { id: "", like: "", prettyName: "Linux" }; |
| 147 | + } |
| 148 | +}; |
| 149 | + |
| 150 | +const getLinuxDesktopDependencyHint = () => { |
| 151 | + const release = readLinuxReleaseInfo(); |
| 152 | + const family = `${release.id} ${release.like}`.toLowerCase(); |
| 153 | + |
| 154 | + if (family.includes("arch")) { |
| 155 | + return "Install the missing desktop dependency and retry:\n sudo pacman -S --needed webkit2gtk-4.1"; |
| 156 | + } |
| 157 | + |
| 158 | + if (family.includes("ubuntu") || family.includes("debian")) { |
| 159 | + return ( |
| 160 | + "Install the missing desktop dependencies and retry:\n" + |
| 161 | + " sudo apt install libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libayatana-appindicator3-dev librsvg2-dev" |
| 162 | + ); |
| 163 | + } |
| 164 | + |
| 165 | + if (family.includes("fedora") || family.includes("rhel")) { |
| 166 | + return ( |
| 167 | + "Install the missing desktop dependencies and retry:\n" + |
| 168 | + " sudo dnf install webkit2gtk4.1-devel openssl-devel curl wget file libappindicator-gtk3-devel librsvg2-devel" |
| 169 | + ); |
| 170 | + } |
| 171 | + |
| 172 | + return `Install WebKitGTK 4.1 development packages for ${release.prettyName} so pkg-config can resolve both webkit2gtk-4.1 and javascriptcoregtk-4.1, then retry.`; |
| 173 | +}; |
| 174 | + |
| 175 | +const ensureLinuxDesktopDependencies = () => { |
| 176 | + if (process.platform !== "linux") return; |
| 177 | + |
| 178 | + const requiredPkgConfigs = ["webkit2gtk-4.1", "javascriptcoregtk-4.1"]; |
| 179 | + const missing = requiredPkgConfigs.filter((pkg) => { |
| 180 | + const result = spawnSync("pkg-config", ["--exists", pkg], { stdio: "ignore" }); |
| 181 | + return result.status !== 0; |
| 182 | + }); |
| 183 | + |
| 184 | + if (missing.length === 0) return; |
| 185 | + |
| 186 | + console.error( |
| 187 | + "[openwork] Missing Linux desktop system dependencies required by Tauri:\n" + |
| 188 | + ` ${missing.join(", ")}\n\n` + |
| 189 | + `${getLinuxDesktopDependencyHint()}\n\n` + |
| 190 | + "If you only need the web UI, run `pnpm dev:ui`." |
| 191 | + ); |
| 192 | + process.exit(1); |
| 193 | +}; |
| 194 | + |
127 | 195 | const runUiDevServer = () => { |
128 | 196 | const child = spawn(pnpmCmd, ["-w", "dev:ui"], { |
129 | 197 | stdio: "inherit", |
@@ -156,6 +224,7 @@ const runUiDevServer = () => { |
156 | 224 | }; |
157 | 225 |
|
158 | 226 | runPrepareSidecars(); |
| 227 | +ensureLinuxDesktopDependencies(); |
159 | 228 |
|
160 | 229 | const main = async () => { |
161 | 230 | let detectedViteUrl = null; |
|
0 commit comments