Skip to content

Commit 9a5b950

Browse files
tom-james-watsondevelar
authored andcommitted
feat(snap): add support for snap autostart option (#4237)
Add support for `autostart` snap option. This allows snaps to define that they should be launched upon login.
1 parent a9a4c53 commit 9a5b950

File tree

5 files changed

+105
-3
lines changed

5 files changed

+105
-3
lines changed

packages/app-builder-lib/scheme.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4325,6 +4325,10 @@
43254325
"useTemplateApp": {
43264326
"description": "Whether to use template snap. Defaults to `true` if `stagePackages` not specified.",
43274327
"type": "boolean"
4328+
},
4329+
"autoStart": {
4330+
"description": "Whether or not the snap should automatically start on login.",
4331+
"type": "boolean"
43284332
}
43294333
},
43304334
"type": "object"
@@ -5831,4 +5835,4 @@
58315835
}
58325836
},
58335837
"type": "object"
5834-
}
5838+
}

packages/app-builder-lib/src/options/SnapOptions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,14 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions {
8181
* Whether to use template snap. Defaults to `true` if `stagePackages` not specified.
8282
*/
8383
readonly useTemplateApp?: boolean
84+
85+
/**
86+
* Whether or not the snap should automatically start on login.
87+
* @default false
88+
*/
89+
readonly autoStart?: boolean
8490
}
8591

8692
export interface PlugDescriptor {
8793
[key: string]: {[key: string]: any} | null
88-
}
94+
}

packages/app-builder-lib/src/targets/snap.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ export default class SnapTarget extends Target {
8888
},
8989
})
9090

91+
if (options.autoStart) {
92+
appDescriptor.autostart = `${snap.name}.desktop`
93+
}
94+
9195
if (options.confinement === "classic") {
9296
delete appDescriptor.plugs
9397
delete snap.plugs
@@ -191,6 +195,7 @@ export default class SnapTarget extends Target {
191195
return
192196
}
193197

198+
console.log(JSON.stringify(snap, null, 2))
194199
await outputFile(path.join(snapMetaDir, this.isUseTemplateApp ? "snap.yaml" : "snapcraft.yaml"), serializeToYaml(snap))
195200

196201
const hooksDir = await packager.getResource(options.hooks, "snap-hooks")
@@ -276,4 +281,4 @@ function getDefaultStagePackages() {
276281
// libxss1 - was "error while loading shared libraries: libXss.so.1" on Xubuntu 16.04
277282
// noinspection SpellCheckingInspection
278283
return ["libnspr4", "libnss3", "libxss1", "libappindicator3-1", "libsecret-1-0"]
279-
}
284+
}

test/out/linux/__snapshots__/snapTest.js.snap

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,75 @@ Object {
1111
}
1212
`;
1313

14+
exports[`auto start 1`] = `
15+
Object {
16+
"apps": Object {
17+
"sep": Object {
18+
"autostart": "sep.desktop",
19+
"command": "command.sh",
20+
"environment": Object {
21+
"DISABLE_WAYLAND": "1",
22+
"LD_LIBRARY_PATH": "$SNAP_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu",
23+
"PATH": "$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH",
24+
"SNAP_DESKTOP_RUNTIME": "$SNAP/gnome-platform",
25+
"TMPDIR": "$XDG_RUNTIME_DIR",
26+
},
27+
"plugs": Array [
28+
"desktop",
29+
"desktop-legacy",
30+
"home",
31+
"x11",
32+
"wayland",
33+
"unity7",
34+
"browser-support",
35+
"network",
36+
"gsettings",
37+
"pulseaudio",
38+
"opengl",
39+
],
40+
},
41+
},
42+
"architectures": Array [
43+
"amd64",
44+
],
45+
"base": "core18",
46+
"confinement": "strict",
47+
"description": "Test Application (test quite “ #378)",
48+
"grade": "stable",
49+
"name": "sep",
50+
"plugs": Object {
51+
"gnome-3-28-1804": Object {
52+
"default-provider": "gnome-3-28-1804",
53+
"interface": "content",
54+
"target": "$SNAP/gnome-platform",
55+
},
56+
"gtk-3-themes": Object {
57+
"default-provider": "gtk-common-themes",
58+
"interface": "content",
59+
"target": "$SNAP/data-dir/themes",
60+
},
61+
"icon-themes": Object {
62+
"default-provider": "gtk-common-themes",
63+
"interface": "content",
64+
"target": "$SNAP/data-dir/icons",
65+
},
66+
"sound-themes": Object {
67+
"default-provider": "gtk-common-themes",
68+
"interface": "content",
69+
"target": "$SNAP/data-dir/sounds",
70+
},
71+
},
72+
"summary": "Sep",
73+
"version": "1.1.0",
74+
}
75+
`;
76+
77+
exports[`auto start 2`] = `
78+
Object {
79+
"linux": Array [],
80+
}
81+
`;
82+
1483
exports[`buildPackages 1`] = `
1584
Object {
1685
"apps": Object {

test/src/linux/snapTest.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,21 @@ test.ifDevOrLinuxCi("no desktop plugs", app({
185185
return true
186186
},
187187
}))
188+
189+
test.ifAll.ifDevOrLinuxCi("auto start", app({
190+
targets: snapTarget,
191+
config: {
192+
extraMetadata: {
193+
name: "sep",
194+
},
195+
productName: "Sep",
196+
snap: {
197+
autoStart: true
198+
}
199+
},
200+
effectiveOptionComputed: async ({ snap, args }) => {
201+
expect(snap).toMatchSnapshot()
202+
expect(snap.apps.sep.autostart).toEqual("sep.desktop")
203+
return true
204+
},
205+
}))

0 commit comments

Comments
 (0)