-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/snap: user session application autostart v3 (#4942)
Add support for `snap userd --autostart`. The command is expected to be run as part of user session startup and is responsible for starting snap applications that have placed a proper `*.desktop` file in `$SNAP_USER_DATA/.config/autostart`. The desktop file is matched against `autostart` declaration in snap's YAML. For details see https://forum.snapcraft.io/t/development-sprint-march-5th-2018/4345/2 Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
- Loading branch information
Showing
18 changed files
with
654 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ all install clean: | |
$(MAKE) -C systemd $@ | ||
$(MAKE) -C dbus $@ | ||
$(MAKE) -C env $@ | ||
$(MAKE) -C desktop $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# Copyright (C) 2018 Canonical Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 3 as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
BINDIR = /usr/bin | ||
SYSCONFXDGAUTOSTARTDIR = /etc/xdg/autostart | ||
|
||
SOURCES = snap-userd-autostart.desktop.in | ||
DESKTOP_FILES = $(SOURCES:.in=) | ||
|
||
.PHONY: all | ||
all: $(DESKTOP_FILES) | ||
|
||
.PHONY: install | ||
install: $(DESKTOP_FILES) | ||
# NOTE: old (e.g. 14.04) GNU coreutils doesn't -D with -t | ||
install -d -m 0755 $(DESTDIR)/$(SYSCONFXDGAUTOSTARTDIR) | ||
install -m 0644 -t $(DESTDIR)/$(SYSCONFXDGAUTOSTARTDIR) $^ | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f $(DESKTOP_FILES) | ||
|
||
%: %.in | ||
cat $< | \ | ||
sed s:@bindir@:$(BINDIR):g | \ | ||
cat > $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[Desktop Entry] | ||
Name=Snap user application autostart helper | ||
Comment=Helper program for launching snap applications that are configured to start automatically. | ||
Exec=@bindir@/snap userd --autostart | ||
Type=Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/sh | ||
|
||
dump_autostart() { | ||
dfpath="$SNAP_USER_DATA/.config/autostart/foo.desktop" | ||
|
||
test -e "$dfpath" && return | ||
|
||
echo "generating autostart file $dfpath" | ||
|
||
mkdir -p $SNAP_USER_DATA/.config/autostart | ||
cat <<EOF > $dfpath | ||
[Desktop Entry] | ||
Name=foo autostart | ||
Exec=/foo/bar/baz/bin/foobar --autostart a b c | ||
EOF | ||
} | ||
|
||
case "$1" in | ||
--autostart) | ||
echo "autostarting with args '$@'" | tee $SNAP_USER_DATA/foo-autostarted | ||
;; | ||
*) | ||
echo "regular run with args '$@'" | ||
dump_autostart | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: test-snapd-xdg-autostart | ||
version: 1.0 | ||
apps: | ||
foo: | ||
command: bin/foobar | ||
autostart: foo.desktop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
summary: Check that snap userd can autostart user session applications | ||
|
||
execute: | | ||
echo "When the snap is installed" | ||
. $TESTSLIB/snaps.sh | ||
install_local test-snapd-xdg-autostart | ||
# run the app directly, it will dump a *.desktop file | ||
snap run test-snapd-xdg-autostart.foo | ||
echo "And snap application autostart file exists" | ||
test -e ~/snap/test-snapd-xdg-autostart/current/.config/autostart/foo.desktop | ||
echo "Applications can be automatically started by snap userd --autostart" | ||
test ! -e ~/snap/test-xdg-snap-autostart/current/foo-autostarted | ||
snap userd --autostart > autostart.log 2>&1 | ||
# when app is autostarted it dumps a file at $SNAP_USER_DATA/foo-autostarted, | ||
# applications are forked by userd, but userd does not wait for them | ||
for i in `seq 20`; do | ||
test -e ~/snap/test-snapd-xdg-autostart/current/foo-autostarted && break | ||
sleep 1 | ||
done | ||
test -e ~/snap/test-snapd-xdg-autostart/current/foo-autostarted | ||
restore: | | ||
rm -f ~/snap/test-snapd-xdg-autostart/current/foo-autostarted | ||
rm -f ~/snap/test-snapd-xdg-autostart/current/.config/autostart/foo.desktop |
Oops, something went wrong.