sezanzeb / input-remapper

🎮 ⌨ An easy to use tool to change the behaviour of your input devices.
GNU General Public License v3.0
3.79k stars 156 forks source link

Installing as Flatpak from Flathub #21

Closed sojusnik closed 3 years ago

sojusnik commented 3 years ago

Thanks for creating such an useful app!

Did you think about offering this app as a Flatpak on Flathub to be easily installable and updatable?

sezanzeb commented 3 years ago

I don't have any experience with Flatpak, never used it.

I played around a little with flatpak-builder --user --install build-dir key-mapper.yml and

app-id: key-mapper
runtime: org.gnome.Platform
runtime-version: '3.38'
sdk: org.gnome.Sdk
rename-appdata-file: key-mapper.appdata.xml
rename-desktop-file: key-mapper.desktop
rename-icon: key-mapper
command: key-mapper
finish-args:
  - --socket=fallback-x11
  - --socket=wayland
modules:
  - name: python-evdev
    buildsystem: simple
    build-commands:
      - python3 setup.py install --prefix=/app
    sources:
      - type: git
        url: https://github.com/gvalkov/python-evdev.git
  - name: key-mapper
    buildsystem: simple
    build-commands:
      - python3 setup.py install --root=/app
    sources:
      - type: git
        url: https://github.com/sezanzeb/key-mapper.git
        branch: main

But it fails, maybe somebody with experience can do this. pydbus and setuptools also needs to be added.

to be easily installable and updatable? Are the deb files from the releases and the AUR package not easily installable and updatable?

I use the pip installation method during development, that one can be a bit tricky though, especially since ubuntu likes to put all sorts of things into a different prefix (I think /usr/local/share), and using setup.py install makes it hard to uninstall the stuff.

@jmaibaum has experience in this stuff, he did the flatpak package for soundconverter :)

jmaibaum commented 3 years ago

@sezanzeb What is the actual error?

From a first glance, IIRC, the app-id has to be in reverse TLD format for flatpaks, so, instead of key-mapper, something like io.github.sezanzeb.KeyMapper or similar should be used.

But I guess you will face other issues. Flatpaks are running apps in pretty restricted sandboxes, where you are usually not allowed to change the host OS's system settings. I never used or heard of Key Mapper before receiving this @-mention, so I don't know anything about what it does and how it does it exactly, but changing your system-wide keyboard mappings is most-likely out of scope for a standard flatpak without adding special permissions (none are added above).

I'd suggest reading up https://docs.flatpak.org/en/latest/sandbox-permissions.html to check if a key-mapper flatpak could work via some of the available portals or other system permissions.

sezanzeb commented 3 years ago

Thanks for answering!

Yeah I never know what to use for the reverse website url names when no actual website exists. It's the same for pkexec files and dbus names.

It grabs exclusive access to read stuff from /dev/input/event* and writes to /dev/uinput. Maybe it could work with --filesystem=/dev/uinput and --device=all

EDIT: at least --filesystem won't work

These directories are blacklisted: /lib, /lib32, /lib64, /bin, /sbin, /usr, /boot, /root, /tmp, /etc, /app, /run, /proc, /sys, /dev, /var

➜  key-mapper git:(main) ✗ rm build-dir -r && flatpak-builder --user --install build-dir org.flatpak.key-mapper.yml
Downloading sources
Fetching git repo https://github.com/gvalkov/python-evdev.git, ref refs/heads/master
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
Fetching full git repo https://github.com/sezanzeb/key-mapper.git
Starting build of whatever.idk.key-mapper
Cache hit for python-evdev, skipping build
Cache hit for key-mapper, skipping build
Cache miss, checking out last cache hit
Cleaning up
Renaming key-mapper.desktop to whatever.idk.key-mapper.desktop
Error: Error moving file /mnt/data/Code/key-mapper/.flatpak-builder/rofiles/rofiles-6twjw0/files/share/applications/key-mapper.desktop: No such file or directory
jmaibaum commented 3 years ago

I might be wrong, but you might be lucky with just --device=all alone. --filesystem=... is usually meant for data users are editing/creating via the app in their home directories. It cannot be used for resources where you usually need root access for (any of the blacklisted resources above, as those are all restricted by the flatpak sandbox).

sezanzeb commented 3 years ago

yeah so no idea why it doesn't work, and I honestly have had enough fun already with making the deb and getting it to run on ubuntu and its derivatives

Downloading sources
Initialized empty Git repository in /mnt/data/Code/key-mapper/.flatpak-builder/git/https_github.com_sezanzeb_key-mapper.git-3E4GX0/
Fetching git repo https://github.com/sezanzeb/key-mapper.git, ref refs/heads/main
remote: Enumerating objects: 86, done.
remote: Counting objects: 100% (86/86), done.
remote: Compressing objects: 100% (83/83), done.
remote: Total 86 (delta 5), reused 22 (delta 0), pack-reused 0
Unpacking objects: 100% (86/86), 243.47 KiB | 814.00 KiB/s, done.
From https://github.com/sezanzeb/key-mapper
 * [new branch]      main       -> main
Initializing build dir
Committing stage init to cache
Starting build of com.github.key-mapper
========================================================================
Building module key-mapper in /mnt/data/Code/key-mapper/.flatpak-builder/build/key-mapper-1
========================================================================
Switched to branch 'main'
Running: python3 setup.py install --root=/app --prefix=""
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/keymapper
copying keymapper/state.py -> build/lib/keymapper
copying keymapper/getdevices.py -> build/lib/keymapper
copying keymapper/paths.py -> build/lib/keymapper
copying keymapper/daemon.py -> build/lib/keymapper
copying keymapper/key.py -> build/lib/keymapper
copying keymapper/logger.py -> build/lib/keymapper
copying keymapper/presets.py -> build/lib/keymapper
copying keymapper/config.py -> build/lib/keymapper
copying keymapper/data.py -> build/lib/keymapper
copying keymapper/mapping.py -> build/lib/keymapper
copying keymapper/__init__.py -> build/lib/keymapper
creating build/lib/keymapper/dev
copying keymapper/dev/macros.py -> build/lib/keymapper/dev
copying keymapper/dev/reader.py -> build/lib/keymapper/dev
copying keymapper/dev/injector.py -> build/lib/keymapper/dev
copying keymapper/dev/keycode_mapper.py -> build/lib/keymapper/dev
copying keymapper/dev/utils.py -> build/lib/keymapper/dev
copying keymapper/dev/permissions.py -> build/lib/keymapper/dev
copying keymapper/dev/event_producer.py -> build/lib/keymapper/dev
copying keymapper/dev/__init__.py -> build/lib/keymapper/dev
creating build/lib/keymapper/gtk
copying keymapper/gtk/row.py -> build/lib/keymapper/gtk
copying keymapper/gtk/window.py -> build/lib/keymapper/gtk
copying keymapper/gtk/__init__.py -> build/lib/keymapper/gtk
running install_lib
creating /app/lib
creating /app/lib/python3.8
creating /app/lib/python3.8/site-packages
creating /app/lib/python3.8/site-packages/keymapper
copying build/lib/keymapper/state.py -> /app/lib/python3.8/site-packages/keymapper
copying build/lib/keymapper/getdevices.py -> /app/lib/python3.8/site-packages/keymapper
creating /app/lib/python3.8/site-packages/keymapper/gtk
copying build/lib/keymapper/gtk/row.py -> /app/lib/python3.8/site-packages/keymapper/gtk
copying build/lib/keymapper/gtk/window.py -> /app/lib/python3.8/site-packages/keymapper/gtk
copying build/lib/keymapper/gtk/__init__.py -> /app/lib/python3.8/site-packages/keymapper/gtk
copying build/lib/keymapper/paths.py -> /app/lib/python3.8/site-packages/keymapper
copying build/lib/keymapper/daemon.py -> /app/lib/python3.8/site-packages/keymapper
copying build/lib/keymapper/key.py -> /app/lib/python3.8/site-packages/keymapper
copying build/lib/keymapper/logger.py -> /app/lib/python3.8/site-packages/keymapper
copying build/lib/keymapper/presets.py -> /app/lib/python3.8/site-packages/keymapper
creating /app/lib/python3.8/site-packages/keymapper/dev
copying build/lib/keymapper/dev/macros.py -> /app/lib/python3.8/site-packages/keymapper/dev
copying build/lib/keymapper/dev/reader.py -> /app/lib/python3.8/site-packages/keymapper/dev
copying build/lib/keymapper/dev/injector.py -> /app/lib/python3.8/site-packages/keymapper/dev
copying build/lib/keymapper/dev/keycode_mapper.py -> /app/lib/python3.8/site-packages/keymapper/dev
copying build/lib/keymapper/dev/utils.py -> /app/lib/python3.8/site-packages/keymapper/dev
copying build/lib/keymapper/dev/permissions.py -> /app/lib/python3.8/site-packages/keymapper/dev
copying build/lib/keymapper/dev/event_producer.py -> /app/lib/python3.8/site-packages/keymapper/dev
copying build/lib/keymapper/dev/__init__.py -> /app/lib/python3.8/site-packages/keymapper/dev
copying build/lib/keymapper/config.py -> /app/lib/python3.8/site-packages/keymapper
copying build/lib/keymapper/data.py -> /app/lib/python3.8/site-packages/keymapper
copying build/lib/keymapper/mapping.py -> /app/lib/python3.8/site-packages/keymapper
copying build/lib/keymapper/__init__.py -> /app/lib/python3.8/site-packages/keymapper
byte-compiling /app/lib/python3.8/site-packages/keymapper/state.py to state.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/getdevices.py to getdevices.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/gtk/row.py to row.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/gtk/window.py to window.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/gtk/__init__.py to __init__.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/paths.py to paths.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/daemon.py to daemon.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/key.py to key.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/logger.py to logger.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/presets.py to presets.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/dev/macros.py to macros.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/dev/reader.py to reader.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/dev/injector.py to injector.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/dev/keycode_mapper.py to keycode_mapper.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/dev/utils.py to utils.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/dev/permissions.py to permissions.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/dev/event_producer.py to event_producer.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/dev/__init__.py to __init__.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/config.py to config.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/data.py to data.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/mapping.py to mapping.cpython-38.pyc
byte-compiling /app/lib/python3.8/site-packages/keymapper/__init__.py to __init__.cpython-38.pyc
running install_data
creating /app/usr
creating /app/usr/share
creating /app/usr/share/key-mapper
copying data/key-mapper.service -> /app/usr/share/key-mapper/
copying data/key-mapper.desktop -> /app/usr/share/key-mapper/
copying data/key-mapper.svg -> /app/usr/share/key-mapper/
copying data/key-mapper.policy -> /app/usr/share/key-mapper/
copying data/key-mapper-autoload.desktop -> /app/usr/share/key-mapper/
copying data/key-mapper.glade -> /app/usr/share/key-mapper/
copying data/keymapper.Control.conf -> /app/usr/share/key-mapper/
copying data/style.css -> /app/usr/share/key-mapper/
creating /app/usr/share/applications
copying data/key-mapper.desktop -> /app/usr/share/applications/
creating /app/usr/share/polkit-1
creating /app/usr/share/polkit-1/actions
copying data/key-mapper.policy -> /app/usr/share/polkit-1/actions/
creating /app/usr/lib
creating /app/usr/lib/systemd
creating /app/usr/lib/systemd/system
copying data/key-mapper.service -> /app/usr/lib/systemd/system
creating /app/etc
creating /app/etc/dbus-1
creating /app/etc/dbus-1/system.d
copying data/keymapper.Control.conf -> /app/etc/dbus-1/system.d/
creating /app/etc/xdg
creating /app/etc/xdg/autostart
copying data/key-mapper-autoload.desktop -> /app/etc/xdg/autostart/
creating /app/usr/bin
copying bin/key-mapper-gtk -> /app/usr/bin/
copying bin/key-mapper-gtk-pkexec -> /app/usr/bin/
copying bin/key-mapper-service -> /app/usr/bin/
copying bin/key-mapper-control -> /app/usr/bin/
running install_egg_info
running egg_info
creating key_mapper.egg-info
writing key_mapper.egg-info/PKG-INFO
writing dependency_links to key_mapper.egg-info/dependency_links.txt
writing requirements to key_mapper.egg-info/requires.txt
writing top-level names to key_mapper.egg-info/top_level.txt
writing manifest file 'key_mapper.egg-info/SOURCES.txt'
reading manifest file 'key_mapper.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'key_mapper.egg-info/SOURCES.txt'
Copying key_mapper.egg-info to /app/lib/python3.8/site-packages/key_mapper-0.6.0-py3.8.egg-info
running install_scripts
Committing stage build-key-mapper to cache
Cleaning up
Renaming key-mapper.desktop to com.github.key-mapper.desktop
Error: Error moving file /mnt/data/Code/key-mapper/.flatpak-builder/rofiles/rofiles-WhZ7zl/files/share/applications/key-mapper.desktop: No such file or directory

https://github.com/sezanzeb/key-mapper/tree/flatpak

https://github.com/sezanzeb/key-mapper/blob/flatpak/com.github.key-mapper.yml

waiting for someone who knows how this stuff works to make a pull request for a working yml file now

likern commented 3 years ago

@sezanzeb I also doesn't quite now how Flatpak works. Information is quite limited. https://github.com/sezanzeb/key-mapper/pull/31 what I could achieve.

I can run application and it starts successfully. But later it checks that systemd service, which you provide, is running and quits with message that I should run it. That's where I get stuck.

After reading all of the available information I think it's not possible to package your application using Flatpak. I think the same applies for AppImage and Snap.

sezanzeb commented 3 years ago

Thanks a lot @likern! Usually when the systemd service is not running the GUI starts its own instance of the service class that ends with the gui process. I'll try it out soon!

reesericci commented 3 years ago

flatpak support would be AMAZING! It would allow for distro-free packaging that works.

sezanzeb commented 3 years ago

see https://github.com/sezanzeb/key-mapper/pull/31, as far as I can tell flatpak doesn't work at all since key-mapper needs root access to the devnodes.

Should we close this and the related PR?

sezanzeb commented 3 years ago

ok, thanks anyway @likern for also investigating into this!

reesericci commented 3 years ago

big bummer. Would an AppImage work? @sezanzeb

sezanzeb commented 3 years ago

maybe, but you have to add it to autostart yourself and you'll have to enter your password each time it launches. I don't know how appimages are made though.

reesericci commented 3 years ago

the docs are really good for making appimages

Aqua1ung commented 1 year ago

Seeing as this seems to be an issue of permissions, it may be worth noting that there's a new GUI tool that might help in this respect. Would you guys care to take another stab at it?

sezanzeb commented 1 year ago

I doubt this tool will help, because this is a fundamental restriction of flatpak. Having a GUI for that doesn't change that. Prove me wrong by trying it out and contributing.

See https://github.com/flatpak/flatpak/issues/4137

If you don't have a particular privilege (for example access to /dev/uinput) before entering the Flatpak sandbox, then you still won't have that privilege inside the sandbox. If you did, that would be a security vulnerability.

I have seen all of your four comments on this matter by the way. I deleted two of them. Please don't spam this everywhere. Everyone who participated in the issues you posted that link got an email. Some of them (like me) multiple times.

Aqua1ung commented 1 year ago

Apologies for the unintentional spamming. I figured that by commenting on closed tickets, people might not be seeing my comments. And thanks for the explanation.

Here's a wild idea: if Flatpak is out of the question, how about packaging IR for Clear Linux? Would that be a huge chore?

sezanzeb commented 1 year ago

Allright, don't worry :)

edit: moved to https://github.com/sezanzeb/input-remapper/issues/661#issuecomment-1483225869