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

📦️ Add flatpak support #89

Merged
merged 22 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
05edcc1
Add config to build and run Emote as a flatpak package using the meso…
vemonet Mar 31, 2023
46470f4
Enable desktop entry for flatpak
vemonet Apr 1, 2023
366daf9
Add keybinder and xdotool modules
vemonet Apr 1, 2023
c6b4e79
move flatpak config files to flatpak folder
vemonet Apr 1, 2023
49c0051
added metainfo.xml file for better integration in packaging hubs and …
vemonet Apr 1, 2023
175be0c
cleanup meson.build files
vemonet Apr 1, 2023
d6f5d49
Improve flatpak cmds in Makefile
vemonet Apr 1, 2023
bd0d7c6
Cleanup emote.in and run black formatting
vemonet Apr 1, 2023
96482d2
add metainfo and desktop file validation for flathub, and fix metainf…
vemonet Apr 1, 2023
1c9e2c8
readme
vemonet Apr 1, 2023
d27c6a8
Update the emojis list, and remove the SEQUENCE_BLOCKLIST for flatpak…
vemonet Apr 2, 2023
b4501df
small change to metainfo.xml
vemonet Apr 2, 2023
8af7cae
add bugtracker to metainfo.xml
vemonet Apr 2, 2023
1aed897
Add supports metadata to metainfo.xml
vemonet Apr 2, 2023
ee09057
Fix copy to the clipboard on wayland by adding the wl-clipboard modul…
vemonet Apr 2, 2023
cd1d609
Fix wl-copy call, and move time.sleep only for x11 (not required on w…
vemonet Apr 2, 2023
4536ce3
Fix user data path to store emoji history
vemonet Apr 2, 2023
4ef9e0e
Update Makefile
vemonet Apr 2, 2023
816e7c5
Update flatpak/com.tomjwatson.Emote.metainfo.xml
vemonet Apr 2, 2023
f9bfab1
fix makefile phony
vemonet Apr 2, 2023
6e8bf9e
fix config
vemonet Apr 2, 2023
9d37106
add some changes to improve enabling autostart
vemonet Apr 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ dist
venv
*.snap

# Flatpak
.flatpak-builder
/requirements.txt
flatpak-pip-generator

# Editors
.vim
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,34 @@ package:

clean:
snapcraft clean
rm -r .flatpak-builder build/

update-emojis:
wget -O static/emojis.csv https://raw.githubusercontent.com/hfg-gmuend/openmoji/master/data/openmoji.csv

flatpak:
flatpak-builder --user --install --force-clean build flatpak/com.tomjwatson.Emote.yml
flatpak run com.tomjwatson.Emote

flatpak-install:
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak install flathub -y org.flatpak.Builder org.gnome.Platform//43 org.gnome.Sdk//43 org.freedesktop.appstream-glib
wget -N https://raw.githubusercontent.com/flatpak/flatpak-builder-tools/master/pip/flatpak-pip-generator
chmod +x flatpak-pip-generator

flatpak-requirements:
pipenv lock
pipenv requirements > requirements.txt
pipenv run flatpak-pip-generator --runtime='org.gnome.Sdk//43' --output python3-requirements -r requirements.txt
vemonet marked this conversation as resolved.
Show resolved Hide resolved
mv python3-requirements.json flatpak/python3-requirements.json

flatpak-validate:
desktop-file-validate flatpak/com.tomjwatson.Emote.desktop
flatpak run org.freedesktop.appstream-glib validate flatpak/com.tomjwatson.Emote.metainfo.xml

flatpak-clean:
rm -r .flatpak-builder build/
flatpak remove com.tomjwatson.Emote -y

flathub:
flatpak-builder --repo=flathub --force-clean build flatpak/com.tomjwatson.Emote.yml
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ url = "https://pypi.org/simple"
verify_ssl = true

[packages]
pygobject = "==3.38.0"
pygobject = "==3.42.2"
manimpango = "==0.3.0"
setproctitle = "==1.2.2"

[dev-packages]
black = "==19.10b0"
flake8 = "*"
requirements-parser = "*"

[requires]
python_version = "3.8"
Expand Down
281 changes: 145 additions & 136 deletions Pipfile.lock

Large diffs are not rendered by default.

100 changes: 83 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@

Emote is a modern emoji picker for Linux 🚀. Written in GTK3, Emote is lightweight and stays out of your way.

Launch the emoji picker with the configurable keyboard shortcut `Ctrl+Alt+E` and select one or more emojis to have them be automatically pasted into your currently focused app.
Launch the emoji picker with the configurable keyboard shortcut `Ctrl+Alt+E`, and select one or more emojis to have them be automatically pasted into your currently focused app.

Note - Emote under Wayland cannot automatically paste the emoji into other apps and also requires manual registering of a global keyboard shortcut - [Hotkey In Wayland](https://github.com/tom-james-watson/Emote/wiki/Hotkey-In-Wayland). This is due to intentional restrictions in the design of Wayland itself.
* 🍾 Built as a popup: quick invocation, and disappears when not needed, does not stay as a standalone window
* 🫠 Provide a large and up-to-date list of emojis retrieved from [openmoji.org](https://openmoji.org/)
* 🧠 Shows the last used emojis by default
* 🔎 Search text box automatically focused and ready to type when invoked
* ⌨️ Can use shortcuts to navigates and select emojis
* ✒️ Selected emoji automatically pasted to your currently focused app (on X11 only)

ℹ️ Note:

- ⚡️ Emote [shows up faster](https://github.com/tom-james-watson/Emote/issues/54) when invoked using the built-in keyboard shortcut (`Ctrl+Alt+E` by default), than when using a manually registered keyboard shortcut.
- 🪟 Emote under Wayland cannot automatically paste the emoji into other apps, and also requires manual registering of a global keyboard shortcut - [Hotkey In Wayland](https://github.com/tom-james-watson/Emote/wiki/Hotkey-In-Wayland). This is due to intentional restrictions in the design of Wayland itself.

<p align="center">
<img width="500" src="https://raw.githubusercontent.com/tom-james-watson/Emote/master/images/screenshot.png">
</p>

## Installation
## 📥️ Installation

[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-black.svg)](https://snapcraft.io/emote)

Expand All @@ -29,21 +39,21 @@ sudo snap install emote

An unofficial build of Emote is also available in the AUR : https://aur.archlinux.org/packages/emote.

## Guide
## 📖 Guide

### Launching
### 🚀 Launching

Emote runs in the background and automatically starts when you log in.

The emoji picker can be opened with either the keyboard shortcut or by clicking the app icon again.
The emoji picker can be opened with either the keyboard shortcut, or by clicking the app icon again.

### Usage
### ℹ️ Usage

Select an emoji to and have it be pasted to your currently focused app. The emoji will also be copied to your clipboard, so you can then paste the emoji wherever you need.

You can select multiple emojis by selecting them with right click.

### Keyboard Shortcuts
### ⌨️ Keyboard Shortcuts

Open Emoji Picker: `Ctrl+Alt+E` (configurable)

Expand All @@ -57,14 +67,16 @@ Next Emoji Category: `Ctrl+Tab`

Previous Emoji Category: `Ctrl+Shift+Tab`

## Development
## 🧑‍💻 Development

### Requirements
### 📥️ Requirements

Install development libraries:

```bash
sudo apt install xdotool libgtk-3-dev libgirepository1.0-dev python3-venv gir1.2-keybinder-3.0 libkeybinder-dev
sudo apt install xdotool libgtk-3-dev libgirepository1.0-dev python3-venv gir1.2-keybinder-3.0 libkeybinder-dev desktop-file-utils
# or with dnf
sudo dnf install xdotool gtk3-devel keybinder3-devel libgirepository1.0-dev desktop-file-utils
```

Install pipenv:
Expand All @@ -79,15 +91,23 @@ Install dependencies:
make install
```

### Running
### 🛩️ Running

Run the development version:

```bash
make dev
```

### Debugging GTK3 with GtkInspector
### 🔄 Update emojis

To update the list of emojis to the latest available on [openmoji.org](https://openmoji.org), run:

```bash
make update-emojis
```

### 🐞 Debugging GTK3 with GtkInspector

Enable debug keybinding:

Expand All @@ -101,7 +121,7 @@ Launch app in debug mode with interactive inspector:
make dev-debug
```

### Packaging
### 🦜 Packaging with Snap

Ensure you have `snapcraft` installed:

Expand All @@ -115,7 +135,7 @@ Create a packaged `.snap` file:
make package
```

### Publishing
**Publishing**:

First, ensure a git tag for the current version has been pushed.

Expand All @@ -131,6 +151,52 @@ Push the packaged snap to the `edge` channel on the snap store.
snapcraft push --release=edge <path to .snap>
```

### Attribution
### 📦️ Packaging with Flatpak

You will need to have [`flatpak`](https://flatpak.org/setup/) installed.

Install `flatpak-builder`, the GNOME SDK, and `flatpak-pip-generator`:

```bash
make flatpak-install
```

Optionally re-generate the `flatpak/python3-requirements.json` if the dependencies in the `Pipfile` have been changed:

```bash
make flatpak-requirements
```

Build the flatpak package and install it locally:

```bash
make -B flatpak
```

Run Emote with flatpak (can also be done from the desktop entry):

```bash
flatpak run com.tomjwatson.Emote
```

**Build and publish to Flathub**:

```bash
make flathub
```

In case you are facing issues with the cache not properly updating, use the `-B` flag with `make`, or you can clean the cache with:

```bash
make flatpak-clean
```

Use `journalctl -f` to see the app logs, run the command below if you want to access inside the containerized flatpak app to debug.

```bash
flatpak run --command=sh --devel com.tomjwatson.Emote
```

### 🤝 Attribution

Emoji data is sourced from https://raw.githubusercontent.com/hfg-gmuend/openmoji/master/data/openmoji.csv which is compiled by the lovely people at https://openmoji.org.
Emoji data is sourced from https://raw.githubusercontent.com/hfg-gmuend/openmoji/master/data/openmoji.csv which is compiled by the lovely people at https://openmoji.org.🫠
3 changes: 3 additions & 0 deletions emote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
gi.require_version("Gtk", "3.0")
gi.require_version("Keybinder", "3.0")
from gi.repository import Gtk, Keybinder

from emote import picker, css, emojis, user_data, config

# Register updated emoji font
if config.is_snap:
manimpango.register_font(f"{config.snap_root}/static/NotoColorEmoji.ttf")
elif config.is_flatpak:
manimpango.register_font(f"{config.flatpak_root}/static/NotoColorEmoji.ttf")
else:
manimpango.register_font("static/NotoColorEmoji.ttf")

Expand Down
2 changes: 2 additions & 0 deletions emote/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
is_dev = os.environ.get("ENV") == "dev"
is_snap = os.environ.get("SNAP") is not None
snap_root = os.environ.get("SNAP")
is_flatpak = os.environ.get("FLATPAK") is not None
flatpak_root = os.environ.get("FLATPAK")
is_wayland = os.environ.get("XDG_SESSION_TYPE", "").lower() == "wayland"
2 changes: 2 additions & 0 deletions emote/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def load_css():

if config.is_snap:
css_provider.load_from_path(f"{config.snap_root}/static/style.css")
elif config.is_flatpak:
css_provider.load_from_path(f"{config.flatpak_root}/static/style.css")
else:
css_provider.load_from_path("static/style.css")

Expand Down
4 changes: 3 additions & 1 deletion emote/emojis.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ def init():
filename = (
f"{config.snap_root}/static/emojis.csv"
if config.is_snap
else f"{config.flatpak_root}/static/emojis.csv"
if config.is_flatpak
else "static/emojis.csv"
)

Expand All @@ -263,7 +265,7 @@ def init():
shortcode = row["annotation"].lower().replace("-", " ")
shortcode = re.sub(r"[^\w\s]", "", shortcode).replace(" ", "_")

if shortcode in SEQUENCE_BLOCKLIST:
if not config.is_flatpak and shortcode in SEQUENCE_BLOCKLIST:
vemonet marked this conversation as resolved.
Show resolved Hide resolved
continue

emoji = {
Expand Down
14 changes: 14 additions & 0 deletions emote/emote.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!@PYTHON@

import os
import sys

VERSION = '@VERSION@'
pkgdatadir = '@pkgdatadir@'

sys.path.insert(1, pkgdatadir)
os.environ["FLATPAK"] = pkgdatadir

if __name__ == '__main__':
from emote import main
sys.exit(main())
19 changes: 19 additions & 0 deletions emote/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
moduledir = join_paths(pkgdatadir, 'emote')
python = import('python')

conf = configuration_data()
conf.set('PYTHON', python.find_installation('python3').path())
conf.set('VERSION', meson.project_version())
conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('pkgdatadir', pkgdatadir)

configure_file(
input: 'emote.in',
output: 'emote',
configuration: conf,
install: true,
install_dir: get_option('bindir')
)

install_subdir('.', install_dir: moduledir)
13 changes: 8 additions & 5 deletions emote/picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def init_category_selectors(self):
self.category_selectors = []
self.selected_emoji_category = "recent"

for (category, _, category_image) in emojis.get_category_order():
for category, _, category_image in emojis.get_category_order():
category_selector = Gtk.ToggleButton(
label=category_image, name="category_selector_button"
)
Expand Down Expand Up @@ -329,6 +329,8 @@ def open_about(self):
logo_path = (
f"{config.snap_root}/static/logo.svg"
if config.is_snap
else f"{config.flatpak_root}/static/logo.svg"
if config.is_flatpak
else "static/logo.svg"
)
logo = Pixbuf.new_from_file(logo_path)
Expand Down Expand Up @@ -391,7 +393,7 @@ def on_category_selector_toggled(self, toggled_category_selector):
def on_cycle_category(self, backwards=False):
index = None

for (i, category_selector) in enumerate(self.category_selectors):
for i, category_selector in enumerate(self.category_selectors):
if category_selector.category == self.selected_emoji_category:
index = i
break
Expand Down Expand Up @@ -461,7 +463,7 @@ def render_emoji_search_results(self, query):
def get_category_display_name(self, category):
category_display_name = None

for (c, display_name, _) in emojis.get_category_order():
for c, display_name, _ in emojis.get_category_order():
if c == category:
category_display_name = display_name
break
Expand Down Expand Up @@ -628,9 +630,8 @@ def on_emoji_select(self, emoji):

self.destroy()

time.sleep(0.15)

if not config.is_wayland:
time.sleep(0.15)
os.system("xdotool key ctrl+v")

def add_emoji_to_recent(self, emoji):
Expand All @@ -640,3 +641,5 @@ def add_emoji_to_recent(self, emoji):
def copy_to_clipboard(self, content):
cb = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
cb.set_text(content, -1)
if config.is_wayland:
os.system(f'wl-copy "{content}"')
Comment on lines +644 to +645
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this is necessary? Copying on wayland worked fine before as far as I understand

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question!

As I understand it it should be done by Gtk.Clipboard, but it was just not doing it with wayland for me, and no logs. Maybe there are some additional GTK dependencies that are missing from the flatpak for wayland?

You mentioned wanting to potentially migrate to GTK4, we could take a deeper look at it at this moment

10 changes: 10 additions & 0 deletions flatpak/com.tomjwatson.Emote.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Desktop Entry]
Name=Emote
Type=Application
GenericName=Emoji picker
Comment=Modern popup emoji picker
Exec=emote
Categories=Utility;GTK;
Keywords=emoji,smiley,emoticon,icon
Icon=com.tomjwatson.Emote
Terminal=false
Loading