Skip to content

Commit

Permalink
feat(snap): add support for snap autostart option (#4237)
Browse files Browse the repository at this point in the history
Add support for `autostart` snap option. This allows snaps to define
that they should be launched upon login.
  • Loading branch information
tom-james-watson authored and develar committed Sep 23, 2019
1 parent a9a4c53 commit 9a5b950
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -4325,6 +4325,10 @@
"useTemplateApp": {
"description": "Whether to use template snap. Defaults to `true` if `stagePackages` not specified.",
"type": "boolean"
},
"autoStart": {
"description": "Whether or not the snap should automatically start on login.",
"type": "boolean"
}
},
"type": "object"
Expand Down Expand Up @@ -5831,4 +5835,4 @@
}
},
"type": "object"
}
}
8 changes: 7 additions & 1 deletion packages/app-builder-lib/src/options/SnapOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions {
* Whether to use template snap. Defaults to `true` if `stagePackages` not specified.
*/
readonly useTemplateApp?: boolean

/**
* Whether or not the snap should automatically start on login.
* @default false
*/
readonly autoStart?: boolean
}

export interface PlugDescriptor {
[key: string]: {[key: string]: any} | null
}
}
7 changes: 6 additions & 1 deletion packages/app-builder-lib/src/targets/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export default class SnapTarget extends Target {
},
})

if (options.autoStart) {
appDescriptor.autostart = `${snap.name}.desktop`
}

if (options.confinement === "classic") {
delete appDescriptor.plugs
delete snap.plugs
Expand Down Expand Up @@ -191,6 +195,7 @@ export default class SnapTarget extends Target {
return
}

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

const hooksDir = await packager.getResource(options.hooks, "snap-hooks")
Expand Down Expand Up @@ -276,4 +281,4 @@ function getDefaultStagePackages() {
// libxss1 - was "error while loading shared libraries: libXss.so.1" on Xubuntu 16.04
// noinspection SpellCheckingInspection
return ["libnspr4", "libnss3", "libxss1", "libappindicator3-1", "libsecret-1-0"]
}
}
69 changes: 69 additions & 0 deletions test/out/linux/__snapshots__/snapTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,75 @@ Object {
}
`;

exports[`auto start 1`] = `
Object {
"apps": Object {
"sep": Object {
"autostart": "sep.desktop",
"command": "command.sh",
"environment": Object {
"DISABLE_WAYLAND": "1",
"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",
"PATH": "$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH",
"SNAP_DESKTOP_RUNTIME": "$SNAP/gnome-platform",
"TMPDIR": "$XDG_RUNTIME_DIR",
},
"plugs": Array [
"desktop",
"desktop-legacy",
"home",
"x11",
"wayland",
"unity7",
"browser-support",
"network",
"gsettings",
"pulseaudio",
"opengl",
],
},
},
"architectures": Array [
"amd64",
],
"base": "core18",
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"name": "sep",
"plugs": Object {
"gnome-3-28-1804": Object {
"default-provider": "gnome-3-28-1804",
"interface": "content",
"target": "$SNAP/gnome-platform",
},
"gtk-3-themes": Object {
"default-provider": "gtk-common-themes",
"interface": "content",
"target": "$SNAP/data-dir/themes",
},
"icon-themes": Object {
"default-provider": "gtk-common-themes",
"interface": "content",
"target": "$SNAP/data-dir/icons",
},
"sound-themes": Object {
"default-provider": "gtk-common-themes",
"interface": "content",
"target": "$SNAP/data-dir/sounds",
},
},
"summary": "Sep",
"version": "1.1.0",
}
`;

exports[`auto start 2`] = `
Object {
"linux": Array [],
}
`;

exports[`buildPackages 1`] = `
Object {
"apps": Object {
Expand Down
18 changes: 18 additions & 0 deletions test/src/linux/snapTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,21 @@ test.ifDevOrLinuxCi("no desktop plugs", app({
return true
},
}))

test.ifAll.ifDevOrLinuxCi("auto start", app({
targets: snapTarget,
config: {
extraMetadata: {
name: "sep",
},
productName: "Sep",
snap: {
autoStart: true
}
},
effectiveOptionComputed: async ({ snap, args }) => {
expect(snap).toMatchSnapshot()
expect(snap.apps.sep.autostart).toEqual("sep.desktop")
return true
},
}))

0 comments on commit 9a5b950

Please sign in to comment.