Skip to content

Commit

Permalink
Merge pull request #89 from vemonet/add-flatpak
Browse files Browse the repository at this point in the history
📦️ Add flatpak support
  • Loading branch information
tom-james-watson authored Apr 23, 2023
2 parents f71e41b + 9d37106 commit 9f8f94b
Show file tree
Hide file tree
Showing 22 changed files with 821 additions and 281 deletions.
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
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
OS := $(shell uname)
.PHONY: dev dev-debug install update-emojis flatpak flatpak-install flatpak-requirements flatpak-validate flatpak-clean flathub

dev:
ENV=dev GDK_BACKEND="x11" pipenv run start
Expand All @@ -17,3 +18,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
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.

108 changes: 91 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,29 @@ sudo snap install emote

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

## Guide
Enable autostart:

```bash
cp -L "/var/lib/flatpak/exports/share/applications/com.tomjwatson.Emote.desktop" ~/.config/autostart/
# Or if it was installed locally:
cp -L "cp ~/.local/share/flatpak/exports/share/applications/com.tomjwatson.Emote.desktop" ~/.config/autostart/
```

## 📖 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 +75,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 +99,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 +129,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 +143,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 +159,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
4 changes: 3 additions & 1 deletion emote/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os


app_id = "com.tomjwatson.Emote"
is_debug = os.environ.get("GTK_DEBUG") == "interactive"
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:
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}"')
Loading

0 comments on commit 9f8f94b

Please sign in to comment.