From 7bded465ebf5c2802eb9fdcc376c4d159811166c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mart=C3=ADn=20Fern=C3=A1ndez?=
<975883+pazos@users.noreply.github.com>
Date: Sat, 18 May 2024 13:21:59 +0200
Subject: [PATCH] SDL: add flatpak flavor (#11833)
* ship metadata with generic linux binaries
* append release version & data at build time
---
Makefile | 5 +++--
datastorage.lua | 2 +-
frontend/device/sdl/device.lua | 8 ++++++++
make/appimage.mk | 2 +-
make/linux.mk | 1 +
platform/appimage/koreader.appdata.xml | 3 +++
platform/linux/do_debian_package.sh | 1 +
7 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index c537f426c..f9567c157 100644
--- a/Makefile
+++ b/Makefile
@@ -3,11 +3,12 @@ KOR_BASE?=base
include $(KOR_BASE)/Makefile.defs
+RELEASE_DATE := $(shell git show -s --format=format:"%cd" --date=short HEAD)
# We want VERSION to carry the version of the KOReader main repo, not that of koreader-base
-VERSION:=$(shell git describe HEAD)
+VERSION := $(shell git describe HEAD)
# Only append date if we're not on a whole version, like v2018.11
ifneq (,$(findstring -,$(VERSION)))
- VERSION:=$(VERSION)_$(shell git show -s --format=format:"%cd" --date=short HEAD)
+ VERSION := $(VERSION)_$(RELEASE_DATE)
endif
# releases do not contain tests and misc data
diff --git a/datastorage.lua b/datastorage.lua
index ffed6826b..511ccf730 100644
--- a/datastorage.lua
+++ b/datastorage.lua
@@ -17,7 +17,7 @@ function DataStorage:getDataDir()
local package_name = app_id:match("^(.-)_")
-- confined ubuntu app has write access to this dir
data_dir = string.format("%s/%s", os.getenv("XDG_DATA_HOME"), package_name)
- elseif os.getenv("APPIMAGE") or os.getenv("KO_MULTIUSER") then
+ elseif os.getenv("APPIMAGE") or os.getenv("FLATPAK") or os.getenv("KO_MULTIUSER") then
if os.getenv("XDG_CONFIG_HOME") then
data_dir = string.format("%s/%s", os.getenv("XDG_CONFIG_HOME"), "koreader")
if lfs.attributes(os.getenv("XDG_CONFIG_HOME"), "mode") ~= "directory" then
diff --git a/frontend/device/sdl/device.lua b/frontend/device/sdl/device.lua
index 41211a85f..38c6879ab 100644
--- a/frontend/device/sdl/device.lua
+++ b/frontend/device/sdl/device.lua
@@ -120,6 +120,12 @@ local Desktop = Device:extend{
hasExitOptions = notOSX,
}
+local Flatpak = Device:extend{
+ model = "Flatpak",
+ isDesktop = yes,
+ canExternalDictLookup = no,
+}
+
local Emulator = Device:extend{
model = "Emulator",
isEmulator = yes,
@@ -436,6 +442,8 @@ io.write("Starting SDL in " .. SDL.getBasePath() .. "\n")
-------------- device probe ------------
if os.getenv("APPIMAGE") then
return AppImage
+elseif os.getenv("FLATPAK") then
+ return Flatpak
elseif os.getenv("KO_MULTIUSER") then
return Desktop
elseif os.getenv("UBUNTU_APPLICATION_ISOLATION") then
diff --git a/make/appimage.mk b/make/appimage.mk
index 7fccbf6ac..827cf9c26 100644
--- a/make/appimage.mk
+++ b/make/appimage.mk
@@ -7,9 +7,9 @@ update: all
# remove old package if any
rm -f koreader-appimage-$(MACHINE)-$(VERSION).appimage
$(SYMLINK) $(abspath $(APPIMAGE_DIR)/AppRun) $(INSTALL_DIR)/koreader/
- $(SYMLINK) $(abspath $(APPIMAGE_DIR)/koreader.appdata.xml) $(INSTALL_DIR)/koreader/
$(SYMLINK) $(abspath $(APPIMAGE_DIR)/koreader.desktop) $(INSTALL_DIR)/koreader/
$(SYMLINK) $(abspath resources/koreader.png) $(INSTALL_DIR)/koreader/
+ sed -e 's/%%VERSION%%/$(VERSION)/' -e 's/%%DATE%%/$(RELEASE_DATE)/' $(APPIMAGE_DIR)/koreader.appdata.xml >$(INSTALL_DIR)/koreader/koreader.appdata.xml
# TODO at best this is DebUbuntu specific
$(SYMLINK) /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0 $(INSTALL_DIR)/koreader/libs/libSDL2.so
# required for our stock Ubuntu SDL even though we don't use sound
diff --git a/make/linux.mk b/make/linux.mk
index 26fe6e756..973cb8d96 100644
--- a/make/linux.mk
+++ b/make/linux.mk
@@ -9,6 +9,7 @@ update: all
$(INSTALL_DIR)/linux/share/applications \
$(INSTALL_DIR)/linux/share/doc/koreader \
$(INSTALL_DIR)/linux/share/man/man1
+ sed -e 's/%%VERSION%%/$(VERSION)/' -e 's/%%DATE%%/$(RELEASE_DATE)/' $(PLATFORM_DIR)/appimage/koreader.appdata.xml >$(INSTALL_DIR)/linux/koreader.appdata.xml
cp -pv resources/koreader.png $(INSTALL_DIR)/linux/share/pixmaps
cp -pv $(LINUX_DIR)/koreader.desktop $(INSTALL_DIR)/linux/share/applications
cp -pv $(LINUX_DIR)/copyright COPYING $(INSTALL_DIR)/linux/share/doc/koreader
diff --git a/platform/appimage/koreader.appdata.xml b/platform/appimage/koreader.appdata.xml
index 28848e2c3..28b3e4bf1 100644
--- a/platform/appimage/koreader.appdata.xml
+++ b/platform/appimage/koreader.appdata.xml
@@ -50,5 +50,8 @@
Viewer
Literature
+
+
+
diff --git a/platform/linux/do_debian_package.sh b/platform/linux/do_debian_package.sh
index 8c8c43a3e..679f0edf8 100755
--- a/platform/linux/do_debian_package.sh
+++ b/platform/linux/do_debian_package.sh
@@ -65,6 +65,7 @@ fi
mkdir -p tmp-debian/usr
chmod 0755 tmp-debian/usr
tar -xf "${1}" -C tmp-debian/usr
+rm -f tmp-debian/usr/koreader.appdata.xml
ARCH="$(echo "${1}" | cut -d '-' -f3)"
VERSION="$(cut -f2 -dv "tmp-debian/usr/lib/koreader/git-rev" | cut -f1,2 -d-)"
DEB_ARCH="$(uname_to_debian "${ARCH}")"