Getting Linux and Linux Snap Apps to Behave Nicely in the ChromeOS Tray (Installing Authy)

Posted Saturday March 14, 2020

The Setup

I have a Pixelbook and I love it. I love running Android, ChromeOS, and Linux apps on it because it gives me a diversity of options to choose from when I want to interact with my favorite tools. One of those favorite tools is Authy, an excellent two-factor authentication (2FA) app. Authy, unlike other 2FA apps has the ability to run from multiple, different devices. I wanted to get it set up on my Pixelbook one Saturday morning, but I quickly found that Authy has deprecated there ChromeOS app in preference to their mobile and desktop (Windows, macOS, and Linux) apps. I could have just installed the Android app on my Pixelbook, but I wanted to have a little fun, and that is when I started off installing the Linux desktop version of Authy.

Prerequisites

Okay, I'm not going to go into everything, so if you want to try this at home, you have to have some items in place beforehand.

A Chromebook That Can Run Linux

The header says it all. I'm doing this on a Pixelbook. If you want to give it a shot, you'll need to be on a Chromebook that supports Google's distro of Linux.

SnapD is Already Installed

To be completely honest, I don't even remember when I did this on my Pixelbook and any headaches I've ran into when it came to setting this up. If you need some help with this, hop on over to Chrome Unboxed.

Acknowledgement that I'm Not a Linux Pro

This is a big one. I dabble. Do I fully know what I'm doing. No. I am persistent and good at doing Google searches, though.

Install Authy or Your Snap App

Not much to do here. Just go to snapcraft.io/install/authy/ubuntu and follow the instructions or to wherever your instructions are posted.

TroubleShoot ChromeOS Not Wanting to Open a Display

Yeah, so all was good with the install. It worked, but that wasn't that big of a deal. I go to type "authy" (no quotes) in the terminal and I get a funky warning about how GTK+ won't open my display. I do a bit of searching in the Google-verse and find out that Linux on ChromeOS doesn't like to give up permission for apps to use the display. In other words, it doesn't do this automatically.

I do a bit more searching and I find out a little bit about the "xhost" command. Apparently this is the command that you can use to tell Linux that your apps can have access to your display. I find out that if you execute the "xhost +" (no quotes) command by itself it will free up your display. This is described here: www.reddit.com/r/chromeos/comments/9acnsd/question_certain_linux_apps_unable_to_launch_due/. If you do a bit more searching you may find that there are better ways to run this command other than using the "+" attribute, but I'll leave that up to you to dig around.

So now if you type "xhost +" (no quotes) on one line; hit return; type "authy" on another line; and hit return, Authy for Linux will launch!

Okay, that's great and all, but a bit clunky. I may like to run Linux apps on my Pixelbook, but I want it to be convenient to run them!

So this lead me down a path of searching that involved getting a nice, little icon to show up in the ChromeOS app tray.

Linux Snapd Apps in the Tray

Like you can see in the screenshot to the left, my other Linux apps (installed via "sudo apt get") were showing up in the tray, so why can't I get Linux Snapd apps to show up in the tray? The answer is that you can, but it takes a bit of configuration.

The template that I used for doing this can be found here: www.reddit.com/r/Crostini/comments/8qqlmf/how_to_add_a_firefox_icon_to_the_shelf_to_make_it/

Here's the content of the plain text file that you need to create:

[Desktop Entry] Name=Firefox
Comment=Browse the World Wide Web
Icon=/opt/firefox/browser/chrome/icons/default/default128.png
Exec=/opt/firefox/firefox %u
Type=Application Categories=Network;WebBrowser;

You should swap out the Firefox stuff above with the information that is relevant for your Snap application. Just as a heads up, for me on my Pixelbook, my snaps are referenced from "/snap/bin/[snap app]" (without quotes). So you would use this for the Exec attribure above.

Once all is good, you need to make sure to save this plain text file as "[name of application].desktop" without quotes. You need to make sure the file is stored in ~/.local/share/applications. For my fellow Linux newbs out there, the "~" means your user folder, so for me that's /home/joshharder.

When you do this, the icon will show up in the ChromeOS tray.

BONUS: Two Commands for the Price of ONe

So what if you're a bit lazy like me and you don't want to have to open terminal and run that "xhost +" command every time you restart your Chromebook? You might think, "Maybe I can issue two commands at the same time for the Exec attribute in the .desktop file". Unfortunately you cannot do this directly in the .desktop file. It wants only one command. So, the workaround is to use a bash script.

A bash script is a simple text file with a command on each line. Here's the format:

#!/bin/bash
first_command_here
second_command_here

So, I did the following:

#!/bin/bash
xhost +
/snap/bin/[put the name of your snap app her]

Next you need to make your bash script executable, which you can do be following the wonderful instructions here: www.andrewcbancroft.com/blog/musings/make-bash-script-executable/.

Now that it's executable, you need to go back to the .desktop file and swap out the attribute for the Exec line to point to your freshly created bash script. There, now when you click on the icon for your Snap app you'll be running two commands.