mirror of
https://github.com/aaddrick/claude-desktop-debian.git
synced 2026-05-17 08:36:35 +03:00
fix: support $-prefixed electron variable names in build patches
The minified electron module variable changed from a plain identifier (e.g., `oe`) to `$e` in Claude Desktop v1.1.4088. Since `\w` doesn't match `$`, extract_electron_variable() captured only `e`, causing all downstream sed patches to insert code between the `$` and `e` — producing `$let _trayStartTime` which is a SyntaxError. - Add `electron_var_re` for regex-escaped variable usage in sed patterns - Update grep patterns with `\$?` to capture optional `$` prefix - Use `grep -Fxv` for safe literal string comparison - Escape `$` in nativeTheme ref replacements and dark_check Fixes #252 Co-Authored-By: Claude <claude@anthropic.com>
This commit is contained in:
@@ -131,6 +131,7 @@ Special thanks to:
|
||||
- **[jarrodcolburn](https://github.com/jarrodcolburn)** for passwordless sudo support in container/CI environments
|
||||
- **[chukfinley](https://github.com/chukfinley)** for experimental Cowork mode support on Linux
|
||||
- **[IliyaBrook](https://github.com/IliyaBrook)** for fixing the platform patch for Claude Desktop >= 1.1.3541 arm64 refactor
|
||||
- **[MichaelMKenny](https://github.com/MichaelMKenny)** for diagnosing the `$`-prefixed electron variable bug with root cause analysis and workaround
|
||||
|
||||
For NixOS users, please refer to [k3d3's repository](https://github.com/k3d3/claude-desktop-linux-flake) for a Nix-specific implementation.
|
||||
|
||||
|
||||
23
build.sh
23
build.sh
@@ -24,6 +24,7 @@ work_dir=''
|
||||
app_staging_dir=''
|
||||
chosen_electron_module_path=''
|
||||
electron_var=''
|
||||
electron_var_re=''
|
||||
asar_exec=''
|
||||
claude_extract_dir=''
|
||||
electron_resources_dest=''
|
||||
@@ -687,10 +688,10 @@ extract_electron_variable() {
|
||||
echo 'Extracting electron module variable name...'
|
||||
local index_js='app.asar.contents/.vite/build/index.js'
|
||||
|
||||
electron_var=$(grep -oP '\b\w+(?=\s*=\s*require\("electron"\))' \
|
||||
electron_var=$(grep -oP '\$?\w+(?=\s*=\s*require\("electron"\))' \
|
||||
"$index_js" | head -1)
|
||||
if [[ -z $electron_var ]]; then
|
||||
electron_var=$(grep -oP '(?<=new )\w+(?=\.Tray\b)' \
|
||||
electron_var=$(grep -oP '(?<=new )\$?\w+(?=\.Tray\b)' \
|
||||
"$index_js" | head -1)
|
||||
fi
|
||||
if [[ -z $electron_var ]]; then
|
||||
@@ -698,6 +699,7 @@ extract_electron_variable() {
|
||||
cd "$project_root" || exit 1
|
||||
exit 1
|
||||
fi
|
||||
electron_var_re="${electron_var//\$/\\$}"
|
||||
echo " Found electron variable: $electron_var"
|
||||
echo '##############################################################'
|
||||
}
|
||||
@@ -708,9 +710,9 @@ fix_native_theme_references() {
|
||||
|
||||
local wrong_refs
|
||||
mapfile -t wrong_refs < <(
|
||||
grep -oP '\b\w+(?=\.nativeTheme)' "$index_js" \
|
||||
grep -oP '\$?\w+(?=\.nativeTheme)' "$index_js" \
|
||||
| sort -u \
|
||||
| grep -v "^${electron_var}$" || true
|
||||
| grep -Fxv "$electron_var" || true
|
||||
)
|
||||
|
||||
if (( ${#wrong_refs[@]} == 0 )); then
|
||||
@@ -719,11 +721,12 @@ fix_native_theme_references() {
|
||||
return
|
||||
fi
|
||||
|
||||
local ref
|
||||
local ref ref_re
|
||||
for ref in "${wrong_refs[@]}"; do
|
||||
echo " Replacing: $ref.nativeTheme -> $electron_var.nativeTheme"
|
||||
ref_re="${ref//\$/\\$}"
|
||||
sed -i -E \
|
||||
"s/\b${ref}\.nativeTheme/${electron_var}.nativeTheme/g" \
|
||||
"s/${ref_re}\.nativeTheme/${electron_var_re}.nativeTheme/g" \
|
||||
"$index_js"
|
||||
done
|
||||
echo '##############################################################'
|
||||
@@ -788,7 +791,7 @@ patch_tray_menu_handler() {
|
||||
echo 'Patching nativeTheme handler for startup delay...'
|
||||
if ! grep -q '_trayStartTime' "$index_js"; then
|
||||
sed -i -E \
|
||||
"s/(${electron_var}\.nativeTheme\.on\(\s*\"updated\"\s*,\s*\(\)\s*=>\s*\{)/let _trayStartTime=Date.now();\1/g" \
|
||||
"s/(${electron_var_re}\.nativeTheme\.on\(\s*\"updated\"\s*,\s*\(\)\s*=>\s*\{)/let _trayStartTime=Date.now();\1/g" \
|
||||
"$index_js"
|
||||
sed -i -E \
|
||||
"s/\((\w+)\(\)\s*,\s*${tray_func}\(\)\s*,/(\1(),Date.now()-_trayStartTime>3e3\&\&${tray_func}(),/g" \
|
||||
@@ -801,11 +804,11 @@ patch_tray_menu_handler() {
|
||||
patch_tray_icon_selection() {
|
||||
echo 'Patching tray icon selection for Linux visibility...'
|
||||
local index_js='app.asar.contents/.vite/build/index.js'
|
||||
local dark_check="$electron_var.nativeTheme.shouldUseDarkColors"
|
||||
local dark_check="${electron_var_re}.nativeTheme.shouldUseDarkColors"
|
||||
|
||||
if grep -qP ':\w="TrayIconTemplate\.png"' "$index_js"; then
|
||||
if grep -qP ':\$?\w="TrayIconTemplate\.png"' "$index_js"; then
|
||||
sed -i -E \
|
||||
"s/:(\w)=\"TrayIconTemplate\.png\"/:\1=${dark_check}?\"TrayIconTemplate-Dark.png\":\"TrayIconTemplate.png\"/g" \
|
||||
"s/:(\\\$?\w)=\"TrayIconTemplate\.png\"/:\1=${dark_check}?\"TrayIconTemplate-Dark.png\":\"TrayIconTemplate.png\"/g" \
|
||||
"$index_js"
|
||||
echo 'Patched tray icon selection for Linux theme support'
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user