Skip to content

Rework injection to shadow Discord's app.asar - #10

Open
zerebos wants to merge 26 commits into
mainfrom
app-asar-injection
Open

Rework injection to shadow Discord's app.asar#10
zerebos wants to merge 26 commits into
mainfrom
app-asar-injection

Conversation

@zerebos

@zerebos zerebos commented Aug 2, 2026

Copy link
Copy Markdown
Member

Human Sumary

Switches the injection to the Discord resources folder to match the intended injection swap by Doggybootsy. This will in theory allow the client code to hook the updater and survive versioned updates. Also added some additional logic and handling for uninstall and reinjection cases. Added a bunch more testcases.

Important Caveats

  • Global flatpak installs will require sudo
  • Not all macOS versions and security levels will be compatible with or without admin
  • Snap installs on linux are entirely unsupported

Clanker Summary

This pull request introduces several improvements and refactors to the BetterDiscord CLI and injection mechanism. The most significant changes include a complete rewrite of the injection script for improved robustness, updates to path handling throughout the CLI, and enhanced testability for the download logic. Additionally, the install and uninstall commands have been updated to support new options and improved error handling.

Injection script and packaging improvements:

  • Rewrote the Discord injection script to ensure that any failure to load BetterDiscord does not prevent Discord from launching, and switched to a new entry point (index.js) with an accompanying package.json for proper Electron module resolution. The script now safely loads the BetterDiscord asar and falls back to Discord's real app entry point if any error occurs (internal/discord/assets/app_index.js, internal/discord/assets/app_package.json). [1] [2]
  • Removed the old injection script (internal/discord/assets/injection.js).

Path handling refactor:

  • Replaced all uses of CorePath with ResourcesPath in CLI commands and internal logic, ensuring consistency and correctness in install/uninstall reporting and duplicate filtering (cmd/install.go, cmd/uninstall.go, cmd/discover.go). [1] [2] [3] [4] [5] [6]

Install/uninstall command improvements:

  • Updated install and uninstall commands to accept structured options (InstallOptions, UninstallOptions), such as RestartDiscord, and improved error handling/reporting when fetching BetterDiscord install info (cmd/install.go, cmd/uninstall.go). [1] [2] [3] [4]

Download logic and testability:

  • Refactored the BetterDiscord asar download logic to use package-level variables for endpoints, allowing tests to override them. Added comprehensive tests for the download function, including website and GitHub fallback scenarios (internal/betterdiscord/download.go, internal/betterdiscord/download_test.go). [1] [2] [3]

Miscellaneous:

  • Fixed a minor bug in a benchmark by replacing a loop variable with b.Loop() for correctness (internal/betterdiscord/meta_test.go).

@zerebos
zerebos requested a review from Copilot August 2, 2026 15:50
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reworks BetterDiscord injection to “shadow” Discord’s app.asar in the resources directory (preserving the original as betterdiscord.app.asar and injecting an app/ entrypoint), with supporting refactors to install discovery/path handling and expanded test coverage across injection, path resolution, WSL, and download behavior.

Changes:

  • Replaced the old core.asar-based injection with a transactional resources/app.asar shadow injection that is designed to better survive Discord updates.
  • Refactored install path discovery/normalization to be ResourcesPath-centric and more robust across Windows/macOS/Linux/Flatpak/WSL, including build_info-based channel/version detection.
  • Added/expanded tests for injection idempotency/rollback, path resolution edge cases, WSL detection, and BetterDiscord asar download fallback.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/wsl/wsl_test.go Adds WSL Info() tests and a reset helper for one-time cached detection.
internal/utils/strings.go Adds version formatting/parsing helpers used for version directory selection and comparisons.
internal/utils/strings_test.go Introduces tests for the new version helpers.
internal/models/options.go Adds structured option types for install/repair/uninstall flows.
internal/discord/process.go Replaces restart flow with explicit stop/start and adds wait-for-exit behavior.
internal/discord/paths.go Improves channel/version inference from paths and migrates suggested/resolve logic to ResourcesPath.
internal/discord/paths_test.go Expands tests for channel detection across macOS bundle and Flatpak resource paths; updates for ResourcesPath.
internal/discord/paths_linux.go Updates Linux search paths to target resources for the new injection method; omits Snap from search.
internal/discord/paths_darwin.go Switches macOS discovery to application bundles rather than config-based paths.
internal/discord/paths_common.go Rewrites validation to resolve resources directories, handle injected state, and prefer build_info.json for channel/version.
internal/discord/paths_common_test.go Adds extensive tests for resolving installs across injected/broken-update/macOS/flatpak/snap heuristics.
internal/discord/install.go Updates install/repair/uninstall flows for new injection method, options structs, stop/start lifecycle, and Flatpak BD data root derivation.
internal/discord/install_test.go Adds tests for uninstall behavior and Flatpak BD data-root recomputation.
internal/discord/injection.go Implements new app.asar shadow injection with rollback/writability probe and Snap rejection.
internal/discord/injection_test.go Adds comprehensive tests for injection/uninject idempotency, rollback safety, and edge cases.
internal/discord/assets/injection.js Removes the old injection asset used by the core.asar method.
internal/discord/assets/app_package.json Adds a package.json for Electron module resolution in the injected app/ entry.
internal/discord/assets/app_index.js Adds the new injected app entrypoint with safe fallback behavior.
internal/betterdiscord/meta_test.go Fixes benchmark loop using b.Loop().
internal/betterdiscord/download.go Refactors endpoints into overridable package vars and retains website→GitHub fallback.
internal/betterdiscord/download_test.go Adds tests for website success, GitHub fallback, missing asset, and no-op when already downloaded.
cmd/uninstall.go Updates uninstall flow to use structured options and ResourcesPath, and handles BD install lookup errors.
cmd/install.go Updates install flow to use structured options and ResourcesPath, and prints BD build info.
cmd/discover.go Updates discovery output to report ResourcesPath instead of CorePath.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +145 to +147
if !signaled {
return nil
}
Comment thread cmd/install.go
return "native"
}())
output.Printf(" Core Path: %s\n", path.Dir(install.CorePath))
output.Printf(" Core Path: %s\n", path.Dir(install.ResourcesPath))
Comment thread cmd/install.go
Comment on lines +73 to +81
bdinstall, err := install.GetBetterDiscordInstall()
if err != nil {
output.Printf("failed to get BetterDiscord install info: %s", err.Error())
return nil
}
if bdinstall == nil {
output.Printf("BetterDiscord install info is nil")
return nil
}
Comment on lines 124 to 128
// Search for desired process(es)
signaled := false
for _, p := range processes {
n, err := p.Name()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants