Skip to content

Add launcherctl #795

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

Merged
merged 27 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
93 changes: 93 additions & 0 deletions package/draft/launcherctl-draft
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
set -e
draft_pid() {
systemctl show --no-pager --property MainPID draft.service | sed 's|MainPID=||'
}
kill_pid() {
pid="$1"
if [[ "$(awk '{print $3}' "/proc/${pid}/stat")" == "T" ]]; then
kill -CONT "$pid"
fi
kill -TERM "$pid"
# Wait 5s for process to exit
start="$(date +'%s')"
while kill -0 "$pid" 2> /dev/null; do
sleep 0.5
if [ "$(date +'%s')" -gt $((start + 5)) ]; then
break
fi
done
if kill -0 "$pid" 2> /dev/null; then
# If process is still running, force kill it
kill -KILL "$pid"
fi
}
case "$1" in
is-active)
systemctl is-active --quiet draft.service
;;
is-enabled)
systemctl is-enabled --quiet draft.service
;;
logs)
if [ $# -eq 2 ] && [[ "$2" == "-f" ]] || [[ "$2" == "--follow" ]]; then
journalctl --follow --all --unit draft.service
else
journalctl --no-pager --all --unit draft.service
fi
;;
start)
systemctl start draft.service
;;
stop)
systemctl stop draft.service
;;
enable)
systemctl enable draft.service
;;
disable)
systemctl disable draft.service
;;
apps)
find {/opt,}/etc/draft -maxdepth 1 -type f | while read -r file; do
grep 'name=' "$file" | sed 's|^name=||'
done
;;
close)
find {/opt,}/etc/draft -maxdepth 1 -type f | while read -r file; do
if [[ "$(grep 'name=' "$file" | sed 's|^name=||')" == "$2" ]]; then
term="$(grep 'term=' "$file" | sed 's|^term=||')"
if [ -z "$term" ]; then
echo "No term= configuration specified for ${2}"
exit 1
fi
$term
call="$(grep 'call=' "$file" | sed 's|^call=||')"
name="$(grep 'name=' "$file" | sed 's|^name=||')"
/opt/libexec/ps-procps-ng --ppid "$(draft_pid)" -o pid | tail -n +2 | while read -r pid; do
if [[ "$(tr -d '\0' < "/proc/${pid}/cmdline")" == "$call" ]]; then
kill_pid "$pid"
break
fi
done
fi
done
;;
running)
pid=$(draft_pid)
find {/opt,}/etc/draft -maxdepth 1 -type f | while read -r file; do
call="$(grep 'call=' "$file" | sed 's|^call=||')"
name="$(grep 'name=' "$file" | sed 's|^name=||')"
/opt/libexec/ps-procps-ng --ppid "$(draft_pid)" -o pid | tail -n +2 | while read -r pid; do
if [[ "$(tr -d '\0' < "/proc/${pid}/cmdline")" == "$call" ]]; then
echo "$name"
break
fi
done
done
;;
*)
echo "Draft does not support this method"
exit 1
;;
esac
16 changes: 11 additions & 5 deletions package/draft/package
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@
pkgnames=(draft)
pkgdesc="Launcher which wraps around the standard interface"
url=https://github.com/dixonary/draft-reMarkable
pkgver=0.2.0-22
pkgver=0.2.0-23
timestamp=2020-07-20T10:23Z
section="launchers"
maintainer="Mattéo Delabre <[email protected]>"
license=Apache-2.0
installdepends=(xochitl display)
installdepends=(xochitl display procps-ng-ps)
flags=(patch_rm2fb)

image=qt:v2.1
source=(
https://github.com/dixonary/draft-reMarkable/archive/5bd660a2fd07eba166c6110d2b48cfc58ee67e58.zip
draft.service
launcherctl-draft
)
sha256sums=(
c41d7a4fd537c54d787018fd764421dbf7dd64306ca800875283e05eef99173e
SKIP
SKIP
)

build() {
Expand All @@ -46,21 +48,25 @@ package() {
mv "$pkgdir"/opt/etc/draft/{99-,}shutdown

install -D -m 644 -t "$pkgdir"/lib/systemd/system "$srcdir"/draft.service
install -D -m 755 -t "$pkgdir"/opt/share/launcherctl/"$pkgname" "$srcdir"/launcherctl-draft
}

configure() {
systemctl daemon-reload

if ! is-enabled "$pkgname.service"; then
if ! launcherctl is-current-launcher "$pkgname"; then
echo ""
echo "Run the following command(s) to use $pkgname as your launcher"
how-to-enable "$pkgname.service"
echo "launcherctl switch-launcher --start $pkgname"
echo ""
fi
}

preremove() {
disable-unit "$pkgname.service"
# Just in case more than one launcher is active, do individual checks
if launcherctl is-active-launcher "$pkgname" || launcherctl is-enabled-launcher "$pkgname"; then
launcherctl switch-launcher --start xochitl
fi
}

postremove() {
Expand Down
41 changes: 41 additions & 0 deletions package/koreader/launcherctl-koreader
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -e
case "$1" in
is-active)
systemctl is-active --quiet koreader.service
;;
is-enabled)
systemctl is-enabled --quiet koreader.service
;;
logs)
if [ $# -eq 2 ] && [[ "$2" == "-f" ]] || [[ "$2" == "--follow" ]]; then
journalctl --follow --all --unit koreader.service
else
journalctl --no-pager --all --unit koreader.service
fi
;;
start | launch)
systemctl start koreader.service
;;
stop | close)
systemctl stop koreader.service
;;
enable)
systemctl enable koreader.service
;;
disable)
systemctl disable koreader.service
;;
apps)
echo "koreader"
;;
running)
if "$0" is-active; then
echo "koreader"
fi
;;
*)
echo "KOReader does not support this method"
exit 1
;;
esac
22 changes: 13 additions & 9 deletions package/koreader/package
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pkgnames=(koreader)
pkgdesc="Ebook reader supporting PDF, DjVu, EPUB, FB2 and many more formats"
url=https://github.com/koreader/koreader
pkgver=2024.04-1
pkgver=2024.04-2
timestamp=2024-04-29T19:56:05Z
section="readers"
maintainer="raisjn <[email protected]>"
Expand All @@ -19,13 +19,15 @@ source=(
KOReader.oxide
koreader-toltec.service
koreader
launcherctl-koreader
)
sha256sums=(
e6b3a5a2c8cde8ca0c469fe542d6e170502fcf39b9a55e4447a7acd02b4a12c0
SKIP
SKIP
SKIP
SKIP
SKIP
)

package() {
Expand All @@ -41,6 +43,7 @@ package() {
install -D -m 644 "$srcdir"/koreader-toltec.service "$pkgdir"/lib/systemd/system/koreader.service
install -D -m 644 -t "$pkgdir"/opt/etc/draft/icons/ "$srcdir"/resources/koreader.png
install -D -m 755 -t "$pkgdir"/opt/bin/ "$srcdir"/koreader
install -D -m 755 -t "$pkgdir"/opt/share/launcherctl/"$pkgname" "$srcdir"/launcherctl-koreader
}

configure() {
Expand All @@ -51,18 +54,19 @@ configure() {

systemctl daemon-reload

if ! is-enabled "$pkgname.service"; then
cat << MSG

Run the following command(s) to use $pkgname as your launcher
$(how-to-enable "$pkgname.service")

MSG
if ! launcherctl is-current-launcher "$pkgname"; then
echo ""
echo "Run the following command(s) to use $pkgname as your launcher"
echo "launcherctl switch-launcher --start $pkgname"
echo ""
fi
}

preremove() {
disable-unit "$pkgname.service"
# Just in case more than one launcher is active, do individual checks
if launcherctl is-active-launcher "$pkgname" || launcherctl is-enabled-launcher "$pkgname"; then
launcherctl switch-launcher --start xochitl
fi
}

postremove() {
Expand Down
Loading
Loading