Skip to content

Commit

Permalink
Add app reload hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Dec 15, 2023
1 parent 4aeca56 commit 942b2d0
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions toltec/hooks/app-reload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Build hook for automatically reloading applications in oxide
After the artifacts are packaged, this hook looks for files in either
/opt/etc/draft or /opt/usr/share/applications and adds reload-oxide-apps to
configure, postupgrade, and postremove
"""
import os
import logging

from toltec.builder import Builder
from toltec.recipe import Package
from toltec.util import listener

logger = logging.getLogger(__name__)

oxide_hook = """
if systemctl --quiet is-active tarnish.service 2> /dev/null; then
echo -n "Reloading Oxide applications: "
local ret
if type update-desktop-database &> /dev/null; then
update-desktop-database --quiet
ret=$?
else
/opt/bin/rot apps call reload 2> /dev/null
ret=$?
fi
if [ $ret -eq 0 ]; then
echo "Done!"
else
echo "Failed!"
fi
fi
"""


def register(builder: Builder) -> None:
@listener(builder.post_package)
def post_package(
builder: Builder, package: Package, src_dir: str, pkg_dir: str
) -> None:
if os.path.exists(
os.path.join(pkg_dir, "opt/usr/share/applications")
) or os.path.exists(os.path.join(pkg_dir, "opt/etc/draft")):
package.configure += oxide_hook
package.postupgrade += oxide_hook
package.postremove += oxide_hook

0 comments on commit 942b2d0

Please sign in to comment.