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

Flatpak/snap compatibility #26

Closed
TheOPtimal opened this issue Apr 2, 2021 · 24 comments · May be fixed by #282
Closed

Flatpak/snap compatibility #26

TheOPtimal opened this issue Apr 2, 2021 · 24 comments · May be fixed by #282
Labels
enhancement New feature or request

Comments

@TheOPtimal
Copy link

Is your feature request related to a problem? Please describe.
The current installer doesn't work in Flatpak.

Describe the solution you'd like
Add flatpak support. You might want to look into the code of betterdiscordctl to see how that would be done.

Describe alternatives you've considered
I've tried changing the discord path to ~/.var/app/com.discordapp.Discord/config/discord, but Discord just spit out a "fatal javascript error".

@TheOPtimal TheOPtimal added the enhancement New feature or request label Apr 2, 2021
@ObserverOfTime
Copy link

Honestly, supporting flatpak and snap in betterdiscordctl has been a PITA…

@ObserverOfTime
Copy link

ObserverOfTime commented Apr 3, 2021

This function should be able to find the paths for both flatpak and snap but I haven't tested it:

const {execSync} = require("child_process");

const getLinuxBasedir = function(channel) {
    if (channel == "flatpak") {
        const output = execSync("flatpak run --command=sh com.discordapp.Discord -c 'printf -- \"$XDG_CONFIG_HOME\"'");
        return path.join(output.toString(), "discord");
    }
    if (channel == "snap") {
        const output = execSync("echo 'printf -- \"$SNAP_USER_DATA\"' | snap run --shell discord");
        return path.join(output.toString(), ".config", "discord");
    }
    return path.join(remote.app.getPath("userData"), "..", channel.toLowerCase().replace(" ", ""))
}

It's up to you on how (and if) you will adapt the installer accordingly.

@zerebos
Copy link
Member

zerebos commented Apr 3, 2021

Yeah I'm not sure yet about snap and flatpak support. It would also require a corresponding change in BD (at least for snap).

@ObserverOfTime
Copy link

Flatpak is also sandboxed so I assume it would require the same change.

@TheOPtimal
Copy link
Author

Also, don't forget Nix.

@ObserverOfTime
Copy link

Nix seems to work fine: NixOS/nixpkgs#118471

@TheOPtimal
Copy link
Author

Good. Unfortunately, I have left discord (because it's garbage) so farewell, I won't be able to test it.

@guihkx
Copy link

guihkx commented Apr 12, 2021

I was interested in this feature myself, so I made this half-assed build with Flatpak compatibility. It seems to work, though. :)

Here's how:

  1. Download the pre-compiled AppImage from here (alternatively, you can build it yourself from the flatpak-dev branch).
  2. Give the AppImage execute permission (if you don't know how, Google it)
  3. Run the AppImage
  4. Follow the installer instructions

I've tested the install/repair/remove features and all of them work.

I don't plan on upstreaming that garbage masterpiece, but if someone else wants to, be my guest. However, I do plan to keep the code in sync with upstream (unless Flatpak support is added to the official installer, of course).

@TheOPtimal
Copy link
Author

About that fork, maybe flatpak option could be automatically applied when ~/.var/app/com.discordapp.Discord/ is detected?

@ObserverOfTime
Copy link

Or automatically applied anyway since it's a fork made specifically for flatpak…

@guihkx
Copy link

guihkx commented Apr 12, 2021

Thanks for the suggestions! It does make sense to make Flatpak the default one, so I did just that.

I've updated the AppImage and instructions as well.

@zerebos zerebos changed the title Flatpak compatibility Flatpak/snap compatibility May 7, 2021
@ghost
Copy link

ghost commented May 14, 2021

if it ever gets installable on the normal installer put some more focus on flatpak. snap has security issues and flatpak has more priority on non canonical distros

@ObserverOfTime
Copy link

You can try betterdiscordctl now that it has been updated.

@TheOPtimal
Copy link
Author

TheOPtimal commented May 27, 2021 via email

@reesericci
Copy link

any update on this?

@dav1312
Copy link
Contributor

dav1312 commented Oct 2, 2021

any update on this?

Try betterdiscordctl as ObserverOfTime already said

@reesericci
Copy link

That's not an update

@ObserverOfTime
Copy link

It took you 2 months to come up with that retort?

@reesericci
Copy link

reesericci commented Dec 6, 2021

yes lol. i havent checked my gh notifs

@marcussacana
Copy link

If we give the flatpak discord directory manually we get missing asar error, I solved by running this command:
sudo flatpak override com.discordapp.Discord --filesystem=~/.config/BetterDiscord

@kaosine
Copy link

kaosine commented Jul 19, 2022

While ctl works for normal flatpak it'd be nice to see both beta and normal version since the beta on flathub is canary too. It stinks having to go back to the standard flatpak just to get compatibility on that end with @ObserverOfTime 's clt and just not having luck plugging in where it should be installed from what I can gather....

@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
Copy link

Arcitec commented Aug 16, 2022

@ObserverOfTime LMFAO. You're the guy who made "betterdiscordctl". I noticed that you downvoted my clean solution 30 minutes after I posted it. The amount of saltiness in you doing without a word is hilarious. I'll upvote myself just to annoy you even more. 💋

@zerebos
Copy link
Member

zerebos commented Mar 4, 2023

Moving all discussion to #157

@zerebos zerebos closed this as completed Mar 4, 2023
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
9 participants