Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EPIC] Snap and Flatpak compatibility #157

Open
21 tasks
QbDesu opened this issue Jun 4, 2021 · 15 comments · May be fixed by #282
Open
21 tasks

[EPIC] Snap and Flatpak compatibility #157

QbDesu opened this issue Jun 4, 2021 · 15 comments · May be fixed by #282
Labels
enhancement New feature or request

Comments

@QbDesu
Copy link
Contributor

QbDesu commented Jun 4, 2021

The BetterDiscord installer doesn't support Flatpak or Snap. The first Linux distros start seemlessly integrating these types of packages in their software store and as their main method of installation.

Well, to be fair saying that the installer doesn't support snap isn't quite right either. Rather it explicitly blocks installing to snap even though it would otherwise be supported.

if (proposedPath.includes("/snap/")) {
remote.dialog.showErrorBox("BetterDiscord Incompatible", "BetterDiscord is currently incompatible with Snap installs of Discord. Support for snap installs is coming soon!");
return "";
}

Flatpak on the other hand actually needs some more work because of it's sandboxing by the looks of it. More specifically it can't read the betterdiscord.asar from user's config directory, so it needs to be installed in the flatpak's config directory.

The snap installation has a related problem. because it's betterdiscord.asar is in the user config directory while the detected config directory is in the snap package's directory the autoupdate functionality of BD is expected to fail.

From a chat with @Tropix126 I could gather that it wasn't always compatible but changing it to injection method to inject the require statement in the discord_desktop_core/index.js module seems to have made it otherwise compatible. In fact betterdiscordctl's installation method is identical to the installer. The only relevant change for BD installation is changing the config directory detection depending on the detected.

betterdiscordctl's installation steps for comparison (warning: identical to the installer)
  1. Detect config directory
  2. Detect Discord folder in the config directory
  3. Detect version folder in the Discord config directory
  4. Detect the core module folder in the version directory
  5. download betterdiscord.asar from github releases (it looks like it may also be caching the asar though)
  6. create a betterdiscord and betterdiscord/data folder if they don't exist
  7. copy the asar in there
  8. inject require statement in index.js of the core module (only difference I can see is a newline more after the injection using betterdiscordctl)
  • Techincal Requirements
    • Snap support
    • Flatpak support
      • version folder detection (same as snap)
      • install to betterdiscord.asar to the package's home directory
        • check if package update removes the BD config folderwhen doing so
    • BetterDiscord compatibility?
      • BetterDiscord seems to function fine on snap and flatpak but maybe there are details that don't function correctly because they require accessing files outside of the BD config directory
  • Design/UX considerations
    • should the list be exanded to include snap/flatpak?
    • should snap/flatpak be fallback if for automatic detection if the native installation is not found?
    • should snap/flatpak be in separate platform selection dialogs?
      • if so how should those be accessed?
        • keep in mind lots of people won't know what type of installation they have because the software stores of their distro's make it seemless. they probably won't even know what the hell snap/flatpak is. but would still be nice to choose which variant to install to
    • technical: adjustments to internal data structure to keep it clean
      • internal platform name + folderName + display name + image url separate, so you don't need to do .toLowercase().replace(" ","") everywhere
        • also don't hardcode the existing platforms everywhere but base them of a common object where all are defined, this would also allow adding a Discord - Snap and Discord - Flatpak platform as needed,
@QbDesu QbDesu added the enhancement New feature or request label Jun 4, 2021
@ObserverOfTime
Copy link

Flatpak on the other hand actually needs some more work because of it's sandboxing by the looks of it.

Snap is also sandboxed.

keep in mind lots of people won't know what type of installation they have because the software stores of their distro's make it seemless.

This is, unfortunately, true.

@ryleu
Copy link

ryleu commented Jan 25, 2022

Fedora and Ubuntu, two of the biggest distros, according to Panic! at the Distro, now prefer installing through Flatpak and Snap respectively.

@ObserverOfTime
Copy link

Yet another reason to use Arch.

@ryleu
Copy link

ryleu commented Jan 26, 2022

Yet another reason to use Arch.

The solution is not to use Arch. This isn't an Arch vs. other distros thread. Please keep your distro supremacy out of here and make actually useful comments.

@ObserverOfTime
Copy link

The solution in Fedora is to actually use DNF instead of some dumb GUI that may use flatpak.
The solution in Ubuntu is to do yourself a favour and migrate to a decent distro.

@TayouVR
Copy link

TayouVR commented Jul 13, 2022

I have just installed discord via flatpak on my arch based distro and it seems currently installing betterdiscord into the flatpak is not a trivial task and basically not supported? I tried passing the path to the discord executable or the discord directory to npm run inject, but that does not seem to be a thing I can do...
Is currently the only option to install via AUR or can I actually get betterdiscord working on the flatpak somehow?

@TayouVR
Copy link

TayouVR commented Jul 13, 2022

I have just installed discord via flatpak on my arch based distro and it seems currently installing betterdiscord into the flatpak is not a trivial task and basically not supported? I tried passing the path to the discord executable or the discord directory to npm run inject, but that does not seem to be a thing I can do... Is currently the only option to install via AUR or can I actually get betterdiscord working on the flatpak somehow?

ahh, the betterdiscord installer I guess can't handle it, but the (older?) betterdiscordctl can do it? (https://gist.github.com/ObserverOfTime/d7e60eb9aa7fe837545c8cb77cf31172)

@Arcitec
Copy link

Arcitec commented Aug 16, 2022

Hey... I don't see what all the fuss is about and why this has been discussed for years, or even why anyone needs or trusts those "fancy" "betterdiscordctl" or "BetterDiscord-Installer.AppImage" tools anyway. It's literally just 1 little .asar file that needs to be placed in the Discord folder, and one little config edit. No need for all that hassle or all those bloated applications just to do such a simple little job.

 

I wrote this oneliner which automatically installs/updates BetterDiscord. It's really that easy, yes. Compare my simple line below to the huge, bloated code (example) of the other methods...

 

📓 The Code:

DISC_CONFIG="$HOME/.var/app/com.discordapp.Discord/config/discord" && BD_ASAR=betterdiscord.asar && wget --timestamping -P "${DISC_CONFIG}/../BetterDiscord/data" -- "https://github.com/BetterDiscord/BetterDiscord/releases/latest/download/${BD_ASAR}" && DISC_VER="$(ls --sort=time --time=creation "${DISC_CONFIG}" | grep -E -m 1 '^[0-9]+\.[0-9]+\.[0-9]+$')" && echo -e "require('../../../../BetterDiscord/data/${BD_ASAR}');\nmodule.exports = require('./core.asar');" | tee "${DISC_CONFIG}/${DISC_VER}/modules/discord_desktop_core/index.js" && echo -e "\nBetterDiscord installed. Restart Discord if currently running." || echo -e "\nInstallation failed."

 

😎 You can set the Discord version that you want to install into as follows:

  • Edit the DISC_CONFIG variable at the start of the line, by only modifying the path that comes after HOME/.
  • Discord Flatpak (Already DEFAULT in command above, NO NEED to edit anything if you're using this): .var/app/com.discordapp.Discord/config/discord
  • Discord Native: .config/discord
  • Discord CANARY Flatpak: .var/app/com.discordapp.DiscordCanary/config/discordcanary
  • Discord CANARY Native: .config/discordcanary

 

🍓 How to use:

Just run that command, and it will do the following:

  • This is only for the Flatpak and Native versions of Discord and Discord CANARY, obviously. I don't use Snap.
  • Automatically downloads the latest BetterDiscord, but only if an update is available. It doesn't download anything at all if there are no updates. It does this by looking at the installed betterdiscord.asar file modification timestamp.
  • Injects the betterdiscord.asar into Discord's loader script for the latest installed Discord version (version is auto-detected).
  • Verifies every step of the installation process and tells you if it succeeded or if there were any issues.

That's it. Just save this command somewhere. Run it once. That's it. Run it again when you want to update BetterDiscord. You can run it as many times as you want, since it won't change anything if BetterDiscord is already installed and up-to-date.

 

⬆️ Making an easy auto-update alias:

You can even make an alias in your ~/.zshrc or ~/.bashrc if you want to easily run this command in your terminal anytime in the future:

alias betterdiscord-update="DISC_CONFIG=\"\$HOME/.var/app/com.discordapp.Discord/config/discord\" && BD_ASAR=betterdiscord.asar && wget --timestamping -P \"\${DISC_CONFIG}/../BetterDiscord/data\" -- \"https://github.com/BetterDiscord/BetterDiscord/releases/latest/download/\${BD_ASAR}\" && DISC_VER=\"\$(ls --sort=time --time=creation \"\${DISC_CONFIG}\" | grep -E -m 1 '^[0-9]+\\.[0-9]+\\.[0-9]+\$')\" && echo -e \"require('../../../../BetterDiscord/data/\${BD_ASAR}');\\nmodule.exports = require('./core.asar');\" | tee \"\${DISC_CONFIG}/\${DISC_VER}/modules/discord_desktop_core/index.js\" && echo -e \"\\nBetterDiscord installed. Restart Discord if currently running.\" || echo -e \"\\nInstallation failed.\""

(Be sure to set your personal DISC_CONFIG path here if you aren't using the default Flatpak version of Discord.)

 

⚠️ Important:

Note that GitHub presents oneliners as a very long line. Be sure to copy these correctly, or use the "copy text" button that GitHub provides.

 

🚀 Updating BetterDiscord:

As for long-term usage and updates, it's very simple too: When Discord starts up, BetterDiscord always does a version check and shows a popup screen to let you know when a new version is available.

In some situations, Discord updates will break BetterDiscord so that it doesn't load at all, and in that case you won't see any notification, but you'll easily notice that BetterDiscord isn't working anymore. In that case, simply run my command to update BetterDiscord to the latest version.

In both scenarios, it's literally brainless. You don't have to think at all. You just look at the built-in Discord notification saying that a new BetterDiscord version is available, or you notice that BetterDiscord is suddenly broken, and you do the update.

It's that easy! ⭐

 

🍌 The End 🍌

Have fun! I hope this helps someone else who just wants a simple, clean and totally safe way to install BetterDiscord for Linux Flatpaks and Native alike, while also helping you effortlessly install BD regardless of whether you use Discord or the Discord CANARY client! This is important since CANARY isn't supported by any of the other installation tools. 🏖️

In fact, if you're using the Flatpak version of Discord together with my installation method, then you will be totally protected along every step of the way, for both the installation of BetterDiscord itself (there's no malicous code in my script, which is super easy to audit), and you'll also be protected for the usage of all 3rd party plugins inside BetterDiscord itself (since they will run inside the Flatpak sandbox and won't be able to steal all your personal files). That's the installation method that I would recommend to people! 💟

🐈

@Arcitec

This comment was marked as off-topic.

@Parent5446
Copy link

It's always amusing seeing someone so confidently proclaim, "that code is so bloated! just use this: {700 character unreadable one-liner with a quarter the functionality".

@Arcitec
Copy link

Arcitec commented Aug 20, 2022

@Parent5446 You seriously mean that you work at Google yet are incapable of reading two shell commands? One wget to download BetterDiscord, and one tee to write it to Discord's loader.

And I would rather be 45 easily audited, clean words (652 characters) than the 670 awfully written, self-updating spaghetti LINES (20661 characters/2301 words) with such awful newbie practices such as hard-coding the absolute path to the BetterDiscord.asar, meaning that Discord breaks if it's moved, lmfao.

Seriously, the hard-coded path is astonishing since the default index.js literally contains a relative path already, as if to hint "hey, use a relative path, dummy". But not only is it bloated and shoddily written. You also have to trust the author never to add malware to it.

Both solutions install BetterDiscord into any Discord or Canary client. What else exactly do you need? 😂 My solution also supports the Discord CANARY Flatpak by the way, unlike the one you use. So my one-liner has more features.

In fact, my solution does error checking along every step of the installation, so it is completely reliable.

Seriously, what else do you need? If you are gonna say "uninstallation" then lmao, why would you uninstall BetterDiscord? And if you do, then it is literally just a matter of deleting the BetterDiscord folder and removing the reference to it from Discord's index.js. Something that doesn't need a script, since it is super obvious from the one-liner exactly where that file resides. But again, why would anyone uninstall BetterDiscord? It is literally a better version of Discord.

I will never use your bloated, pointless script for something so easily solved in 45 words.

@TayouVR
Copy link

TayouVR commented Aug 20, 2022

Hey... I don't see what all the fuss is about and why this has been discussed for years, or even why anyone needs or trusts those "fancy" "betterdiscordctl" or "BetterDiscord-Installer.AppImage" tools anyway. It's literally just 1 little .asar file that needs to be placed in the Discord folder, and one little config edit. No need for all that hassle or all those bloated applications just to do such a simple little job.

as an end user I prefer graphical applications. And betterdiscordctl is at least readable and easy to use.
Instead of complaining and posting a lengthy comment, that nobody cares about, how about you fork betterdicordctl and give a PR back to fix the issues you have with it. (e.g. don't hardcode paths, etc.)
OR, PR this installer and fix the issues in it...

If you don't wanna do either of those, then at least you could have written your comment not as toxic as you did. Just say you would rather use a single line of stacked commands and anyone, who prefers that, there u go.
No need to be so toxic. ^^

@ObserverOfTime
Copy link

Thoughts on your code being "unreliable spaghetti with awful newbie practices". @bb010g

@bb010g
Copy link

bb010g commented Aug 21, 2022

Please direct design criticism of betterdiscordctl at me, not @ObserverOfTime.

And I would rather be 45 easily audited, clean words (652 characters) than the 670 awfully written, self-updating spaghetti LINES (20661 characters/2301 words) with such awful newbie practices such as hard-coding the absolute path to the BetterDiscord.asar, meaning that Discord breaks if it's moved, lmfao.

237 lines are help text & argument parsing. The argument parsing is extremely boilerplate & easily auditable. Bash is not a great language.

66 lines are semver parsing & comparison for the auto-updating functionality, which you can disable in one line, and is disabled when betterdiscordctl is packaged. I'm trying to be robust here. Bash is not a great language.

I would love to have a better updating system than the current setup, and when available, I'd recommend using betterdiscordctl through your distribution's package manager (which will not auto-update). The current self-updating system works and doesn't waste bandwidth.

I do believe that betterdiscordctl has very good code for a Bash script, and that it behaves very well as a Unix CLI tool.

betterdiscordctl status is useful for debugging, and can tell you when stuff is messed up when BetterDiscord changes installation methods, which has happened. betterdiscordctl has also cleaned up properly after itself after BetterDiscord changed installation methods.

Seriously, the hard-coded path is astonishing since the default index.js literally contains a relative path already, as if to hint "hey, use a relative path, dummy". But not only is it bloated and shoddily written. You also have to trust the author never to add malware to it.

$bd_asar sits under $bd_config/data/$bd_asar_name. $bd_config is found at $xdg_config/BetterDiscord. We write to $d_modules/discord_desktop_core/index.js. $d_modules can be user-specified via --d-modules <d_modules>, but it defaults to the lexicographically greatest path matching "$d_config/"+([0-9]).+([0-9]).+([0-9])/modules. $d_config is found at $xdg_config/discord${d_flavor,,} if not using Flatpak or Snap, and found at $xdg_config/discord if using Flatpak or Snap. So, a relative path (pivoting at $xdg_config) could be used if $d_modules is not user-specified, but the current behavior is more consistent and has not caused reported issues so far. For now, it's not a priority. If you move $XDG_CONFIG_HOME without running betterdiscordctl reinstall, you are correct that it will break.

You do have to trust me not to add malware to it. If you want to manually review changes, disable auto-update.

Both solutions install BetterDiscord into any Discord or Canary client. What else exactly do you need? 😂 My solution also supports the Discord CANARY Flatpak by the way, unlike the one you use. So my one-liner has more features.

This is an open issue (bb010g/betterdiscordctl#143). I've been busy with work, but will get to this in the next few days if nobody else does first.

Seriously, what else do you need? If you are gonna say "uninstallation" then lmao, why would you uninstall BetterDiscord? And if you do, then it is literally just a matter of deleting the BetterDiscord folder and removing the reference to it from Discord's index.js. Something that doesn't need a script, since it is super obvious from the one-liner exactly where that file resides. But again, why would anyone uninstall BetterDiscord? It is literally a better version of Discord.

This may be simple for technical users, but not everyone wants to bother discovering how BetterDiscord's internals work, and betterdiscordctl is useful there. Even if you do know how it works, it can be handy. It's your choice on whether to use it or not. I still like having an easy option available that's more lightweight than an Electron-based installer.

If someone wants to uninstall BetterDiscord, betterdiscordctl respects that. I don't presume to know people's reasons.

@Arcitec
Copy link

Arcitec commented Aug 21, 2022

@TayouVR

OR, PR this installer and fix the issues in it...

Sure, I'll have a look at fixing the BetterDiscord-Installer code.

@bb010g Don't worry, you're in good company. The BetterDiscord-Installer code is spaghetti too, such as defining static variables with dynamic values outside functions, using dynamic data that is created inside other functions, and then using those global, static variables as input data for functions that take ZERO arguments, all while passing data to other scripts by importing those scripts so that they inherit the variables (rather than using function parameters). It's a total... mess.

In pseudocode, BetterDiscord-Installer does things like this:

// file: core.js:

const discordPath = getDiscordPath();

require("./install.js");


// file: install.js:

const bdFile = path.join(discordPath, "BetterDiscord.asar");
function write() {
   writeto(bdFile);
}

They literally forgot how passing arguments works. 🤣 It will make it a bit trickier to fix the bugs and untangle some of this mess. I'll see about making BetterDiscord-Installer work on Linux again, and adding Flatpak support to it. The code is a mess but it shouldn't be too terrible to rewrite the spaghetti parts that are involved with paths and installation. 👍

Edit: It's done. Releasing the pull request tomorrow since it's time to sleep.

Edit: Today, instead of submitting the pull request, I decided to throw in a lot more surprises for people (you'll have to wait and see, otherwise it wouldn't be a surprise). But I didn't have much time today since this is a project that I don't personally use, and I have a lot of other important things to do. But everything related to BetterDiscord-Installer is done now, and the pull request and an AppImage for users will be released tomorrow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
7 participants