Linux Matters 5: Extending GNOME is hard

I've been writing a no extension, what feature was lacking from GNOME that required you to write an extension? Oh, we're to begin. Oh, I just, of course. The particular thing that I wanted to be able to do, which I couldn't do, I have multiple audio outputs in particular, I have some headphones and I have some speakers and I have it set up so that some applications output to my headphones for things like video calls and some for things like music and podcasts output to my speakers, but there isn't a very easy way to control the volume of two different outputs in GNOME. The best sort of solution that I can find is using the Pavu control GUI, but it's fiddly because it's got loads of stuff in that appears and disappears depending on what's going on and having an app running all the time just so that I can control volume sliders every now and then is not terribly convenient. So I thought, wouldn't it be nice if there was a way of having volume sliders for all of your outputs available instead of just the default output, which is what you get by default with GNOME. And KDE has this, but I didn't really want to switch desktop just to get one tiny little feature like this. So I thought, after looking and realising that it didn't seem to exist, I thought, well, I wonder if I could fright it myself. So I'd like to talk a little bit about the developer experience of writing a GNOME extension. I don't know if either of you two have ever delved into this. No, no. And can I ask before you started developing, did you look for an existing extension that already did this? I did. I had a look on the GNOME extensions website and there was one which looked like it might have done it, but it was wasn't compatible with current versions of GNOME. And there were a few which did similar things, but not the same thing. It was like being able to switch the default output to easily or control what different applications were doing, but not what different outputs were doing and things like that. Right. And were any of those existing extensions useful in your sort of research as to how to go about this? I didn't look there at first because I sort of wanted to try and start from first principles and follow the documentation and find out what's the right way to go about this kind of thing. And did you find documentation which told you what was the right way about going about this? Ah. So I found some documentation for GJS, which is the GNOME JavaScript framework because GNOME shell is written in JavaScript and GNOME extensions are written in JavaScript. And there is a sort of getting started guide to writing a very basic extension which displays an icon with a menu and something happens when you click the thing in the menu, which was a sort of starting ground because I kind of wanted an icon that I pressed and I got a menu of sound devices like a control. And you know, it's easy to get that basic skeleton and run it and you get something, but beyond that, no, quite frankly. It's really hard to find any information at all about how to do things in GNOME extension. There's mention in the documentation about something called Shell Toolkit or ST for adding UI items, but as far as I can tell, it's basically undocumented. So how do people find out how to do that then? That is something I'm not completely sure of either I'm missing something or people who write successful, useful GNOME extensions are people who know quite a lot about GNOME development in the first place. Or do they just copy and paste and cargo cult from other extensions that already exist? That's also a possibility. I mean, although I think one of the things I'm going to have to do now is go and look at the code of some other extensions that do far more complicated things than what I've done and work out what on earth they do because I find it very hard to imagine how I'd get from where I am to doing something like, you know, there's an extension I have that lets you tell particular applications to put their windows in certain places on certain screens and one that implements a spinning desktop cube like comp is and it's like, I've got no idea how you can get from where I am to that sort of thing based on what I've found so far. And yet trying to Google, for example, is very difficult because searching for things in GJS, there's other things called GJS and just googling for JavaScript things in general is very, very difficult to find some things this sort of specific. It mainly ended up you find C libraries or JS documents to kind of pick apart. This being said, I did manage to bodge something together by digging into the source code of the UI classes and working out how to display a slider and how to plug a slider into something happening when you change the value of the slider as far as actually finding the sound devices and controlling the volume, it ended up being shelling out to the PACTL command line tool. I'm not sure if there's a better way of doing it, there is a PulseAudio.js library and npm, I don't know if that would be able to do it as well but this seemed like the easiest way to begin with and I did find actually PACTL does have a nice format equals Jason option. So if you want to get a list of all your audio devices that you can consume easily in JavaScript, you can do that and then there's a command for setting the volume which is ultimately what I needed to do. So putting all of this together, I did manage to create an icon which opens a menu, lists all of the names of your sound outputs with sliders and when you change each slider, it sets the volume for each device. I do feel like it is a tried and tested path for early graphical user interface developers to create something basic which just shells out to command line tools and when you've got PACTL which can do this, it totally makes sense, there may be system calls that will be more efficient. I don't know how efficient it needs to be changing the volume, are you going to notice the latency when you slide that volume slider up and down or performance might be slightly better to use some system call rather than shelling out. But other than that, if it works, use it. Did your background as a web developer help you at all in this journey? I mean, knowing the syntax of JavaScript was probably a bit useful, I think more my experience, you may remember from many moons ago, a project called BT Sync Indicator, which was a project we worked on together to add an app indicator for BitTorrent Sync, which did a similar thing, displaying an icon with some stuff in a menu. I think having done that gave me a bit more confidence that this was probably something I was capable of doing once I worked out how to do it. Have you had any problems with it not being able to enumerate the devices or enumerating the wrong ones or turning the wrong device up and down or any major user flaws? Not yet. I mean, it's very simple at the moment. It just gets a list of all the devices you have, whether you want them or not, and display stuff for them. I'd like to have some configuration to make it a bit more selective so you could just have it show the ones you're using. So that might be something I talk about in the future. How are you going about adding settings and things like that? One thing I did find interesting was trying to debug this and work out what I was doing as I went. You can't actually restart the extension without restarting known shell as a whole, but what you can do is run an embedded session, which appears in a little window and loads the whole desktop and all the extensions, including the latest version of your extension, and then you also get the log from your extension mixed in with all the other logs. So it's a bit of a slog trying to really nail down issues, but it is possible in around about sort of way. And yeah, I suspect there'll be more about this in the future. One thing I'd like to do next is look at the process for actually publishing this on the name extensions website. In the meantime, if you're interested in seeing this, it's actually on my github at github.com slash marks johnson slash advanced volume control. It's advanced, is it? Wow, get you. It's more advanced than the one that you get out of the box. So after just over 30 years, I've decided to weed myself off nano nano is over 30 years old. That's how long I've been using it. Yeah, you're over 30 years old. I'm over 30 years old. And in fact, it's not nano because originally I used to use pico. Right. And then nano is sort of the continuation or rather the GNU free software implementation of the pico editor. So this all started a long, long time ago in my first job where we had Unix servers and our email system was pine. And the default editor for pine was pico. So from the very beginning, went from my first introductions to Unix, I was familiar with the pico editor. And consequently, I never really used Vim or Vi or any of these Vi-based editors because pico was where I started and I stuck with pico and switched to nano when pico got ejected from popular distributions because of license reasons in the mid-1990s. And in fact, most distributions you'll find that nano is still simlinked to pico to this day. So I've been happily using nano as my terminal based text editor for all that time. For the entire time, I've been using Linux as well. But I finally decided that it was time for an upgrade, something newer, something more capable. So I've been making the switch. So in a previous episode, you talked about how you're big into using Apple devices and you're using Apple music for all your music needs. And now you've moved away from nano and you don't really use Vi. Are you really a geek at all? Yeah, one of my last jobs, there was a critical problem on one of the servers and I was leading the ops team at the time and they dragged me over to have me poke around. And as I was looking around, I went and edited one of the files and I nano file name and I heard someone behind me say freak. It was lately considered the not using, you know, Vi or Vim to be, you know, a cardinal sin. But I don't care. Nano has been perfectly serviceable and it's the it's I've only ever used it when I'm on a server. You know, I've always had some other editor that I use for development these days. It's Visual Studio Code. And this is one of the reasons why I decided to move away from nano. What I found is is that I use VS Code so much. I'm so familiar with the key bindings in VS code. When I open something in nano, I often execute the wrong key bindings and do bad things. And consequently, I'll do the same in VS code sometimes and cut lines out of my text when I didn't mean to. So I thought right, I could rebind all of the keys in nano, which you can do. But, you know, the syntax highlighting is okay in nano, it's not great. So I thought, I'm going to go and have a look. See what's out there. It has syntax highlighting. I can forget it that nano has syntax highlighting because it's not enabled by default. Right. And then every so often I'll see someone post a nano screenshot and go, oh yeah, I should enable that on my laptop. And I keep forgetting. So no, I've I think I've seen it like twice in my life. So it's something that I have in my dot files is a nano RC with all of the, well, I say all with a good selection of syntax highlighting, but it's not great. Anyway, so here you go, Alan. If you want to see some syntax highlighting in your terminal editor, I have switched to the terminal editor called micro. Ah, and I am very, very happy with it indeed. So the first reason for switching is that almost one to one, the key bindings in micro are the same as the default key bindings in visual studio code. So gone are the days of conflating which editor you're in and, you know, doing the wrong thing by and large, the same key combinations do the same things in both places. So that was sort of a big win. And also the syntax highlighting is absolutely brilliant. And I think it's nearly 100 languages are supported. So I like that a lot. Did you consider just using VS code? Because I have on occasion used it as a sort of SSH client with built-in file manager and text editor. And it does a really good job of that if you just need to go into another machine and edit files remotely. I didn't consider doing that. No, maybe I should have done. I too have edited files on my home server thinking, oh god, I'll just, I'll just mount it in the file manager and then just drag the file into VS code because I've got the window open right now. And I can't be bothered to press control ALT and then SSH and then nano. It's easier in you know, having Nautilus able to mount using SSHFS or whatever it is. I know this stuff is built into VS code, but I went like the back doorway. But yeah, I can, I can see how using VS code is your standard editor. Once you get used to it, you're totally right. You just want to keep using it for everything. Yeah. Gone are the days of me logging into sort of servers. I have a couple of devices around the house that I log into, but all of the stuff that's you know, on the internet, I don't log into those servers anymore. They're all orchestrated in some fashion or another. So I don't need to log into those and use an editor there. So it's really only a couple of network infrastructure devices that I run on my land that I log into sort of interactively over SSH. And micro is proving to be great for that. Some of the features of micro that I really like is you can do editor tabs and splitting. So you can have a single edit window open and then split it across multiple files, a bit like you can do with some of the terminal emulators that will do splitting. And it has a bunch of plugins, not many of which I've experimented with yet. But you can also do the multiple cursus thing as well, which is really cool. And it has excellent mouse support, which means you can just highlight your stuff. And again, if you have a terminal window open to a thing with micro, you can easily copy and paste your stuff to an editor on your desktop because it all just happens seamlessly with, you know, the mouse. And you can do, and this is a sort of a workflow that I have, which is for a longest time, I have the text editor IDE open. And I always have a terminal window underneath. And I might use that to run a build script or maybe start an interpreter and do some interactive code snippet wrangling whilst I figure out what I want to put in the actual program and micro supports that as well. So you can actually open a terminal beneath the edit window in just the same way. And it also has a nice nano-like help menu system to help you get around and learn the thing when you're just starting out. I've just noticed that I do have GVIM open right now on my laptop because I have a good, a GPG encrypted file with some secrets in it. And I have a plugin that I use with them, VIM GPG, I think it's just called something like that. But it automatically decrypts the file using password in my key ring. And then re-encrypts it when I, you know, control WQ, whatever the right incantation is, it automatically re-encrypts it. I would have thought if I could do that in nano, that would be great. But I think I might give this micro a go. I heard of it because we made a snap of it many years ago when we were both at canonical. And I played with it a little bit, but I wasn't super looking for another editor. But if I could replace VIM and the GPG automatic encryption thing, so I could edit encrypted files directly in micro, that would be amazing. And I would love that. I think there may be a plugin to do what you require. And my final sort of motivation for switching to micro is I have been switching out lots of my common tools and utilities that I use in the terminal with so-called modern unix alternatives. So I've completely embraced the modern unix lifestyle and micro fits in with that uplifting and refitting, sort of, you know, the comfortable place that you go to when you open a terminal. You mean it's written in Rust or Go or something? I don't know what language it's written in, to be honest with you. I think it's Go. I have a feeling it's going to. I don't really care about those implementation details. Right. And I suppose the only thing is that when you've been using something for such a long time, muscle memory is really hard to shake. And to start with, I would micro file and then immediately use the nano key bindings because my brain saw a terminal editor. And so the fingers default to using nano key bindings. So it took a lot of effort to actually shake that behavior. But more frustrating still is when I'd actually got my mind into I'm using micro now. When I was at the terminal, I wanted to edit something. The number of times nano file name came out. My brain's now thinking micro, but I'm in nano when I start controlling control, seeing all the rest of it. And the wrong thing happens. So I've now actually put an AES in my terminal so that when I type nano, it actually runs micro now to prevent that confusion. Would you remove nano? I don't know if nano is in the default install of whatever OS you're using, but I guess you could just remove nano, but that seems a bit brutal. No, no, it's in the default for nix OS and the boom too. That's probably a bit much for some of them to installations, but I'll keep it around, but I am working very hard to just micro all the things now. And if you're looking to change things up with a bit of modern unix, then I highly recommend micro. It's rather excellent. Linux matters is part of the late night Linux family. If you enjoy the show, please consider supporting us and the rest of the late night Linux team using the PayPal or Patreon links at linuxmatters.sh slash support. For five dollars a month on Patreon, you can enjoy an ad free feed of our show or for $10 get access to all the late night Linux shows ad free. You can get in touch with us via email, show at linuxmatters.sh or chat with other listeners in our telegram group. All the details are at linuxmatters.sh slash contact. I want to tell you something I've learned while using askubuntu, but I'm not going to tell you till the end, okay? This is a hear me out. So askubuntu for those you don't know is a question and answer system built on stack exchange like stack overflow. So people post questions, how do I fix this printer? Where do I get this driver? That kind of stuff. And then people in the community either search for answers and then give them a link to the answer and mark it as a duplicate or write an answer or write a comment asking for more information so that they can provide an answer with the goal being to provide useful answers to support questions. And people can upvote the questions and they can upvote the correct answers and they can mark certain answers as correct. I'm sure everyone knows how stack exchange works. That's exactly what askubuntu is. It's been around for 12, nearly 13 years I think now, started by George Castro and Marco Sheppi and Evan Dandrea and a few other people at Canonical and a whole bunch of people in the community and it's still going now and it's still super super active. So we know askubuntu is. So there's some things you need to think about when we talk about technical support and one of them is not everyone is an expert nerd. Some people just want to use a computer. They want to use it as a tool and I think one of the problems that the people in the nerd space and I include us in that is we have a kind of blindness for those people who just want to use a computer and they're not like us, they're normal, right? They just want to turn the computer on, open the web browser, go to whatever it is they want to do. They might want to do some software development, they might want to do some video editing, whatever those workflows are, they want to do those things and when it breaks, they're a bit lost and that's true no matter what operating system they're using. That's not unique to Linux and not everyone wants to switch to Arch. Arch isn't a panacea that fixes all problems. It's the same software underneath, right? It's the same bits that are being compiled, maybe slightly newer, maybe slightly different, maybe slightly faster, who knows, but it's still pretty much the same stuff, right? When something breaks, people want to get it fixed, so reinstall in a switching distro is not always the answer. You want to get something fixed, right? Sometimes it is the answer, but often it isn't. One of the things that nerds need to understand is that people who have broken their system are often very goal oriented and they want to get a thing done and getting to that goal, that's the destination they want to get to. They want to edit a video, print a document, send an email, create a presentation, whatever it is, they want to do that thing and anything that gets in the way is a frustration to them. So often these people are quite frustrated because something is not working the way it should and they don't understand why and it should work, why doesn't it work? And there are often ways in which they solve these problems by going online and just copying and pasting stuff they find because they're frustrated and they don't know any better, right? A nerd will say, oh, you don't copy and paste off of the internet, you don't download random packages, you don't use that repo and all that kind of stuff, but they don't know this because they're not part of the community, they're just people using computers, right? And you might find some interesting ways in which people break their systems and I'll give you some examples of what I've learned, a surprisingly high number of people do to knacker their computer and I mean properly knacker it so it doesn't it doesn't work and they need help. Installing random depths without dependencies from third parties, for example, their goal is I would like this piece of software that I have seen somewhere or I have heard of and so the googling turns up a page which has a link to a blog, which has a link to a deb, they click the deb, they install the deb and it breaks and it might break because it's a third party repository that's only built for an old version of Ubuntu and there's a missing library that they don't have or it could be that they downloaded a deb linked directly from a repository from an old version of Ubuntu and it's built against some ancient version of Lib SSL or Lib C or something like that. People do this. And as you're saying all of that, you're exampleing you being a nerd and how this ancient decrepit software doesn't even feature on the radar of the people that are trying to install this stuff in order to get a task completed. They don't understand why installing a deb from an eight year old version of Ubuntu is a bad thing to do. Yes, I used to help this guy out many years ago in the days of Dawson Windows and there was a text editor he would use that he paid for. Now, we're talking a long time ago and he continued to use that because he was using it to write programs to run a milling machine that made little widgets out of strips of metal in his garage. Now, all the way through MSDOS, all the way through Windows, he used that same text editor running off of a floppy disk because he was inclined not to change, he was familiar with this tool. And the same thing happens on Linux. People get familiar with applications. They may not have a technology person nearby and their familiarity means that when they upgrade their system or they get a new laptop, they want that familiarity of that piece of software. And so they go hunting it down. And yes, they find it in some old repository. They'll find an old wiki page or something like that because there's that comfort of using a piece of software that you've been using. Maybe for 30 years, like a text editor. And so there's a good example of a way in which someone could break their system or break an application on the system. It's just finding a random devil for the internet and trying to install it. That's straightforward and easy to understand. Another thing that nerds often find are often incredulous about is that people remove software from their system. Like, I don't know what that is, so I've removed it. And they could do that at the package level. They could apt remove or they could use synaptic or they could use some package manager and remove packages. Or they might be more brutal and say, oh, why is that taking up space? I don't recognize what that is. And a little knowledge is a dangerous thing, pseudo RM, and then they wipe out all of VAR. And things like that, you can say, well, he's being an idiot. He's removed all of VAR. He's removed a crucial file, but they don't know any better. And they're not protected because it's their computer. And we give them the gun and the bullets. And if they want to shoot themselves in the foot, they can. And sometimes do often do. In fact, interesting point about you saying, you know, this isn't a unique thing with Linux. This is just how people use computers. There's an interesting point that the developer of curl makes that sometimes antivirus software on Windows flags curl.exe as being a vulnerability. And people go into the Windows system directory and delete curl.exe and things break because that's a thing you can do. Yeah. Yeah. In fact, you reminded me of a guy when I used to work at the local college, he removed the system folder from Windows. Now, we're talking nine early to mid 1990s, like 93, I left that job. And he just deleted or moved the system folder into the recycle bin or trash or whatever you call it. And I was like, well, don't do that. And he's like, why not? It was taking up loads of space. And this thing's got a small hard drive and it was running out of space. Why should I not? It was just taking up loads of space. And it's like, this is an age old problem. Computers are very, very complicated things. And software is very, very, very complicated. And there's no guard rails to stop you doing that. Yeah, you could just like, hold on a fold and bin it. And it's like, okay, well, you get to keep all the pieces now. Well done. So I think that there's another interesting way to break your system, which fits into this perfectly, which is you have a problem. You find a solution to the problem that you have that tells you to do a bunch of things. And you don't understand the bunch of things that it's telling you to do, but you do them anyway. And what you don't realize is you've you've just started a time bomb ticking because you've actually created another problem that you're going to experience at a future date as a result of the things that you've just done. Yeah, absolutely. That's actually something that used to happen in the old days in Ubuntu is there was a piece of software called Automatics. And it was a script that someone wrote. And it did loads of really wacky stuff. If you want to learn what it did, go and find Matthew Garrett's tearing apart blog post of Automatics. It did load of crazy stuff like killed processes, ran, deep package, and apt with a minus y. So, you know, just ran. It was hideous. And it would cause support nightmares for those of us who have to help people who run this stuff. And people do go and find these useful pieces of software and then just run them. And then it might not break now, but it might break in six months time when you come to upgrade your system. Or if you're on an LTS, it might break in two years time. And you've got no idea what you did two years ago that broke this system. So it's sometimes very hard to pick apart, you know, forensically figure out what it was that they did, especially over a web forum where you're asking for detailed output of commands and stuff. It's a hard problem to solve. And there's other stuff like, you know, installing random kernels. And the big one that I've seen a lot recently is people updating the version of Python. They go and find a new version of Python and replace the system version of Python. That breaks the world. It breaks apt, breaks deep package. It breaks all kinds of things. Sometimes you'll be left with a terminal. You won't even be able to get into the desktop. Others, you know, the package you system just goes a bit wonky. But all of these problems, I think I've figured like we've got a whole community of people who are willing to help these people and want to help these people. If you ask a question and ask a bunch of, most of the time in under an hour, you'll get an answer or you'll get questions for like more information. And that's free. That's volunteers giving their time for free to help you get out of the hole that you've got yourself in or the problem that you've vined in front of you. And it staggers me. It amazes me that people are willing to give their time. I'm one of them. Like I've been, I've got an active account on ask of entry for 12 years. And I've answered a lot of questions in my time. And I enjoy doing it and I enjoy helping people. It's a thing that gives me pleasure when we fix something and they say, yeah, that helped, that helped solve my problem. But the thing when I introduce this is I've learned and it's taken a painfully too long to learn is I think the answer to a lot of these questions is the immutable desktop. I really am coming round to this idea that not necessarily for everyone and certainly not necessarily for every nerd, but for normal folk who are very quick on the trigger and able to break a system doing things that the platform allows them to do should probably be given an immutable desktop. So they are less likely to shoot themselves in the foot. Like it gives them the bullets but not the gun. And so they can probably unlock it. And yeah, with all of these immutable systems, there's buttons you can press to make it so you can write to stuff and you can certainly still break it. And I'm not saying it's perfect, but I certainly think there is room for a better way to distribute the Linux desktop where we're less likely to have people just trying to install a new package and it utterly hoses their system. And I completely off the mark, I think this might be the selling point for the immutable desktop. I can imagine a situation where you have something like a default immutable setup where you install them into and by default, you can't go and delete stuff from user slash lib. But if you are someone like us who knows enough to be dangerous, you can run a command or flicker switch like you can on steam OS, for example, if you want to make your system writable, which you know, I haven't on steam OS, because I will absolutely no reason to. I use it for playing games, not for screwing around. I have plenty of other systems for that, but you know, nerds like us who want to screw around can, but people who want to get stuff done and don't want a broken system won't do it by accident or are less likely or less likely. I suppose that the other the other problem is that what you end up with is is all of these things that say run these commands. The first command is run this command that says unlock your system and then paste all of this stuff into your terminal. Yeah, that certainly is a potential, you know, possible outcome of this is everyone just says, well, the first thing you do is, you know, disable the security system, which is exactly what happens on Red Hat when, you know, people complain about SC Linux. The first thing the first thing you do is disable SC Linux. And it was for a while when people had problems with snaps. A lot of the answers I'll ask a bunch of when someone said this thing doesn't work. And the question would be how did you install it? Was it a snap? If the answer is yes, they'd say remove the snap and install the dead. That's actually less now because a lot of those problems have been ironed out. I think it will be like that. There will be a period, a transitionary period where a lot of people will just say, I'll just turn all that off throw that away. But I think there is room for not hardcore nerds, but normal people to have a more pleasurable experience that isn't so fragile.