Skip to content

Commit 70348d0

Browse files
committed
Automatically install missing browser dependencies in a terminal on WSL launch failure
- in wsl, when libs are missing to run chrome, detect distro and auto run terminal with missing libraries installation command, instead of showing notification.
1 parent dd5390d commit 70348d0

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-run-browser.ts‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,88 @@ const get_log_tail = (log_path: string) => {
2828
}
2929
}
3030

31+
const chrome_debian_packages = [
32+
'libnss3',
33+
'libatk1.0-0',
34+
'libatk-bridge2.0-0',
35+
'libcups2',
36+
'libdrm2',
37+
'libxkbcommon0',
38+
'libxcomposite1',
39+
'libxdamage1',
40+
'libxfixes3',
41+
'libxrandr2',
42+
'libgbm1'
43+
]
44+
45+
const get_distro_ids = (): string[] => {
46+
try {
47+
const content = fs.readFileSync('/etc/os-release', 'utf-8')
48+
const ids: string[] = []
49+
for (const line of content.split('\n')) {
50+
const match = line.match(/^(ID|ID_LIKE)=(.*)$/)
51+
if (match) {
52+
ids.push(
53+
...match[2]
54+
.replace(/["']/g, '')
55+
.trim()
56+
.toLowerCase()
57+
.split(/\s+/)
58+
.filter(Boolean)
59+
)
60+
}
61+
}
62+
return ids
63+
} catch {
64+
return []
65+
}
66+
}
67+
68+
const get_install_command = (): string | undefined => {
69+
const ids = get_distro_ids()
70+
const is_distro = (...names: string[]) =>
71+
names.some((name) => ids.includes(name))
72+
73+
if (is_distro('debian', 'ubuntu')) {
74+
const asound_package =
75+
'$(apt-cache show libasound2t64 >/dev/null 2>&1 && echo libasound2t64 || echo libasound2)'
76+
return `sudo apt-get update && sudo apt-get install -y ${chrome_debian_packages.join(' ')} ${asound_package}`
77+
}
78+
79+
if (is_distro('fedora', 'rhel', 'centos')) {
80+
return 'sudo dnf install -y nss atk at-spi2-atk cups-libs libdrm libxkbcommon libXcomposite libXdamage libXfixes libXrandr mesa-libgbm alsa-lib pango cairo'
81+
}
82+
83+
if (is_distro('arch')) {
84+
return 'sudo pacman -S --needed --noconfirm nss atk at-spi2-core cups libdrm libxkbcommon libxcomposite libxdamage libxfixes libxrandr mesa alsa-lib pango cairo'
85+
}
86+
87+
if (is_distro('opensuse', 'suse', 'sles')) {
88+
return 'sudo zypper install -y mozilla-nss libatk-1_0-0 libatk-bridge-2_0-0 cups-libs libdrm2 libxkbcommon0 libXcomposite1 libXdamage1 libXfixes3 libXrandr2 libgbm1 libasound2'
89+
}
90+
91+
return undefined
92+
}
93+
94+
const run_in_terminal = (command: string) => {
95+
const terminal = vscode.window.createTerminal({
96+
name: 'Install browser dependencies'
97+
})
98+
terminal.show()
99+
terminal.sendText(command)
100+
}
101+
31102
const show_launch_error = (reason: string, log_path: string) => {
32103
const log_tail = get_log_tail(log_path)
104+
105+
if (is_wsl() && /shared libraries/i.test(log_tail)) {
106+
const install_command = get_install_command()
107+
if (install_command) {
108+
run_in_terminal(install_command)
109+
return
110+
}
111+
}
112+
33113
const hint = /shared libraries/i.test(log_tail)
34114
? '\nSystem libraries required by Chrome are missing. Install them, e.g. on Ubuntu/Debian: sudo apt install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 (libasound2t64 on newer releases).'
35115
: ''

0 commit comments

Comments
 (0)