Rework injection to shadow Discord's app.asar - #10
Open
zerebos wants to merge 26 commits into
Open
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
There was a problem hiding this comment.
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 transactionalresources/app.asarshadow 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 | ||
| } |
| return "native" | ||
| }()) | ||
| output.Printf(" Core Path: %s\n", path.Dir(install.CorePath)) | ||
| output.Printf(" Core Path: %s\n", path.Dir(install.ResourcesPath)) |
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() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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:
index.js) with an accompanyingpackage.jsonfor 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]internal/discord/assets/injection.js).Path handling refactor:
CorePathwithResourcesPathin 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:
InstallOptions,UninstallOptions), such asRestartDiscord, and improved error handling/reporting when fetching BetterDiscord install info (cmd/install.go,cmd/uninstall.go). [1] [2] [3] [4]Download logic and testability:
internal/betterdiscord/download.go,internal/betterdiscord/download_test.go). [1] [2] [3]Miscellaneous:
b.Loop()for correctness (internal/betterdiscord/meta_test.go).