/matebook-applet

System tray applet/control app for Huawei Matebook

Primary LanguageGoGNU General Public License v3.0GPL-3.0

matebook-applet

System tray applet/control app for Huawei Matebook

Build Status codecov Go Report Card

This simple applet is designed to make some of the proptietary Huawei PC Manager's functionality available via GUI on Linux.

Applet screenshot

It can be used as a system tray applet (above) or as a windowed app (below).

Windowed screenshot

Table of Contents

Help matebook-applet get better!

Join the development (or just buy me a coffee, that helps, too).

Installation and setup

The applet requires no installation as such (although you may want to add it to autorun so that it gets started automatically when you load your DE). However, it depends on GTK+ and libappindicator to be installed on your system, and it relies on underlying pieces of software to be installed so that it is user-accessible (more on that below).

Debian users can add this repo:

deb http://evgenykuznetsov.org/repo/ buster main

to their /etc/apt/sources.list and add the public key:

$ wget -qO - https://raw.githubusercontent.com/nekr0z/matebook-applet/master/matebook-applet.key | sudo apt-key add -

The repository used to be signed by another public key, so if you installed matebook-applet .deb package via this repository in 2019, you may still have the old key in your APT trusted keyring. This poses no security issue as such (because the key in question was never used to sign any packages except for matebook-applet, and will not be used to sign packages in future), but you may still want to remove that key from your system just to be sure:

sudo apt-key del 0BA9571368CD3C34EFCA7D40466F4F38E60211B0

From there, the applet is just a sudo apt install matebook-applet away.

Huawei-WMI driver

Starting with version 1.2 the best way to get the matebook-applet working is to install Huawei-WMI driver by Ayman Bagabas. You'll need at least version 3.0 of his driver. Be advised that the driver is only compatible with Linux kernel 5.0 or later.

Linux kernel 5.5 includes version 3.3 of the driver, so from that version on there's no need to install the driver separately.

After installing the driver you may start using the matebook-applet right away. However, it will only be able to display the current settings, not change them. In order to do that you either need to run the applet as root (absolutely not recommended), or make sure all the necessary files (the hooks in /sys/devices/platform/huawei-wmi as well as /etc/default/huawei-wmi/ directory) are user-writable. A good way to set everything up is to make use of Rouven Spreckels' awesome project. Debian users will have it installed from the abovementioned repository, the rest can:

$ git clone https://github.com/qu1x/huawei-wmi.git
$ cd huawei-wmi/generic
$ sudo make install

You may need to re-login for adding your user to group to take effect.

Embedded controller scripts

On Linux kernels earlier than 5.0 you can make this matebook-applet work using the two scripts as explained below. Any one of them is enough, but you need both for full functionality. You may download them both in one archive here. Please note that these scripts are for MateBook 13 and will not work on other MateBooks (you can still get them to work by changing them to address EC registers proper for your particular model, but make sure you know exactly what you're doing, you've been warned).

Both scripts depend on ioport to work, so make sure to install it first. Debian packages are available in main repository, and there is a way to get it on Arch, too.

  • To get battery protection functionality:

    1. Download the batpro script, make it executable and copy to root executables path, i.e.:
      # mv batpro /usr/sbin/
      
    2. Allow your user to execute the script without providing sudo credentials. One way to do this would be to explicitly add sudoers permission (please be aware of possible security implications):
      # echo "your_username ALL = NOPASSWD: /usr/sbin/batpro" >> /etc/sudoers.d/batpro
      # chmod 0440 /etc/sudoers.d/batpro
      
    3. Double check that you can successfully run the script without providing additional authentication (i.e. password):
      $ sudo batpro status
      
  • To get Fn-Lock functionality:

    1. Download the fnlock script, make it executable and copy to root executables path, i.e.:

      # mv fnlock /usr/sbin/
      
    2. Allow your user to execute the script without providing sudo credentials. One way to do this would be to explicitly add sudoers permission (please be aware of possible security implications):

       # echo "your_username ALL = NOPASSWD: /usr/sbin/fnlock" >> /etc/sudoers.d/fnlock
       # chmod 0440 /etc/sudoers.d/fnlock
      
    3. Double check that you can successfully run the script without providing additional authentication (i.e. password):

       $ sudo fnlock status
      

Compiling matebook-applet

You can always download precompiled amd64 binary from releases page, but it's also perfectly OK to compile matebook-applet yourself. Provided that you have the dependencies (GTK+ and libappindicator) installed (on Debian you can sudo apt install libgtk-3-dev libappindicator3-dev), all you need to do is:

    $ git clone https://github.com/nekr0z/matebook-applet.git
    $ cd matebook-applet
    $ go run build.go

Usage

The user interface is intentionally as simple as they get. You get an icon in system tray that you can click and get a menu. The menu consists of current status, options to change it, and an option to quit the applet. Please be aware that the applet does not probe for current status on its own (this is intentional), so if you change your battery protection settings by other means it will not reflect the change. Clicking on the status line (top of the menu) updates it.

The entry that shows current Fn-Lock status is clickable, too, that toggles Fn-Lock (from ON to OFF or vice versa). Again, no probing here, so if you change Fn-Lock status by other means it will not reflect the change until clicked, but then it will toggle Fn-Lock again.

Command line option -w launches the applet in windowed (app) mode, i.e.:

$ matebook-applet -w

Other command line options can be found on the included manpage:

$ man -l matebook-applet.1
  or, if you installed applet from repository or .deb package,
$ man matebook-applet

Gnome

As of Gnome 3.26 the "legacy tray" is removed. Launching the applet in windowed (app) mode still works. An extension is needed for the system tray icon to show up, for example AppIndicator.

Development

Pull requests are always welcome!

Contributing translations

In case you don't want to install any Go tools, the notion of having to use git scares you, and you don't feel like figuring out what a pull request is and how to make one, but you still feel like contributing a translation, just drop me an email, we'll figure something out. ;-)

The intended way to go about contributing translations to the project is using go-i18n tool. Make sure you have it installed and available, clone the repository, and:

$ cd assets/translations
$ ls
$ touch active.xx.toml

(where xx is your language)

$ goi18n merge active.*.toml

This will generate translate.xx.toml with all the lines that need to be translated to the language xx. Go ahead and translate it. Please make sure you delete all the messages you don't feel like translating before the next step, so that English messages don't creep in disguised as messages in your language.

$ goi18n merge active.*.toml translate.*.toml

Now all you've translated is in active.xx.toml and you can make a pull request.

Credits

This software includes the following software or parts thereof:

Translations:

Packages are built using fpm and nekr0z/changelog.

Big THANK YOU to Ayman Bagabas for all his work and support. Without him, there would be no matebook-applet.

Kudos to Rouven Spreckels for sorting out udev and systemd.