summaryrefslogtreecommitdiff
diff options
authorNathan Pratta Teodosio <nathan.teodosio@canonical.com>2024-11-27 16:03:56 +0100
committerNathan Pratta Teodosio <nathan.teodosio@canonical.com>2024-11-27 16:04:53 +0100
commit12bffe90a46acfaf0e83c3c8dd805f2fdda50f52 (patch)
tree487c20aebc1e80209412262834ab9532225bf5f2
parent20f725d0eb8439d9e885a96cc84101dc5e722a4e (diff)
Merge the daemon app from the dev branch.
-rwxr-xr-xlauncher/chromium.launcher11
-rwxr-xr-xlauncher/daemon.wrapper26
-rwxr-xr-xsnap/hooks/configure13
-rw-r--r--snapcraft.yaml34
4 files changed, 84 insertions, 0 deletions
diff --git a/launcher/chromium.launcher b/launcher/chromium.launcher
index cd3efd7..dbd70ca 100755
--- a/launcher/chromium.launcher
+++ b/launcher/chromium.launcher
@@ -128,6 +128,17 @@ esac
# Refer to https://bugs.archlinux.org/task/76268.
CHROMIUM_FLAGS="$CHROMIUM_FLAGS --disable-features=TFLiteLanguageDetectionEnabled"
+# Check if the user wants to actually run chromium as a daemon
+daemon="$(snapctl get daemon)"
+if [ "$daemon" = "true" ]; then
+ # If chromium is running as a daemon, assume we're running as a kiosk.
+ CHROMIUM_FLAGS="$CHROMIUM_FLAGS --kiosk --no-sandbox --disable-dev-shm-usage"
+ # If we're running as a kiosk, we are using Frame, so use Wayland.
+ CHROMIUM_FLAGS="$CHROMIUM_FLAGS --enable-features=UseOzonePlatform --ozone-platform=wayland"
+ # If we're running as a kiosk, we are loading a specific URL.
+ set -- "$@" "$(snapctl get url)"
+fi
+
if [ $WANT_TEMP_PROFILE -eq 0 ] ; then
exec "$SNAP/usr/lib/chromium-browser/chrome" --password-store=$PASSWORD_STORE $CHROMIUM_FLAGS "$@"
else
diff --git a/launcher/daemon.wrapper b/launcher/daemon.wrapper
new file mode 100755
index 0000000..0e4a2a3
--- /dev/null
+++ b/launcher/daemon.wrapper
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+set -e
+
+real_xdg_runtime_dir=$(dirname "${XDG_RUNTIME_DIR}")
+real_wayland=${real_xdg_runtime_dir}/${WAYLAND_DISPLAY:-wayland-0}
+
+# Permissions applying to the deepest directory is fine
+#shellcheck disable=2174
+mkdir -p "$XDG_RUNTIME_DIR" -m 700
+
+ln -sf "${real_wayland}" "$XDG_RUNTIME_DIR"
+ln -sf "${real_wayland}.lock" "$XDG_RUNTIME_DIR"
+
+unset DISPLAY
+
+# Chromium creates a file with a unique name which indicates whether or not the
+# requested profile is in-use by some other chromium process. Chromium is
+# supposed to clean up after itself, but sometimes this lock file persists.
+# Because we are running Chromium as a kiosk, it is safe to manually remove this
+# file - the profile should not be in use.
+if [ -e "$SNAP_USER_COMMON/chromium/SingletonLock" ]; then
+ unlink "$SNAP_USER_COMMON/chromium/SingletonLock"
+fi
+
+exec "$@"
diff --git a/snap/hooks/configure b/snap/hooks/configure
new file mode 100755
index 0000000..1255869
--- /dev/null
+++ b/snap/hooks/configure
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+set -ex
+
+daemon="$(snapctl get daemon)"
+
+if [ "$daemon" = "true" ]; then
+ if snapctl services "$SNAP_INSTANCE_NAME.daemon" | grep -q inactive; then
+ snapctl start --enable "$SNAP_INSTANCE_NAME.daemon" 2>&1 || true
+ fi
+else
+ snapctl stop --disable "$SNAP_INSTANCE_NAME.daemon" 2>&1 || true
+fi
diff --git a/snapcraft.yaml b/snapcraft.yaml
index 5490515..c23d587 100644
--- a/snapcraft.yaml
+++ b/snapcraft.yaml
@@ -75,6 +75,40 @@ apps:
- upower-observe
slots:
- mpris
+ daemon:
+ extensions: [gnome]
+ daemon: simple
+ command: bin/chromium.launcher
+ command-chain:
+ - bin/daemon.wrapper
+ - snap/command-chain/desktop-launch
+ restart-delay: 3s
+ install-mode: disable
+ environment:
+ CHROME_CONFIG_HOME: $SNAP_USER_COMMON
+ PIPEWIRE_CONFIG_NAME: $SNAP/usr/share/pipewire/pipewire.conf
+ PIPEWIRE_MODULE_DIR: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pipewire-0.3
+ SPA_PLUGIN_DIR: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/spa-0.2
+ plugs:
+ - audio-playback
+ - audio-record
+ - bluez # for Web Bluetooth (https://launchpad.net/bugs/1887201)
+ - camera
+ - cups
+ - home
+ - joystick
+ - mount-observe
+ - network
+ - network-manager
+ - password-manager-service
+ - pulseaudio # remove once snapd 2.41 is available everywhere
+ - raw-usb # for WebUSB (https://launchpad.net/bugs/1780678)
+ - removable-media
+ - screen-inhibit-control
+ - system-packages-doc
+ - u2f-devices
+ - unity7 # required for xdg-open to work
+ - upower-observe
plugs:
# This is not used or needed for anything other than to trigger automatic