diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index 28905a35282..c6a6f4c584f 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -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" @@ -5831,4 +5835,4 @@ } }, "type": "object" -} \ No newline at end of file +} diff --git a/packages/app-builder-lib/src/options/SnapOptions.ts b/packages/app-builder-lib/src/options/SnapOptions.ts index d751d9f796d..9c49f241e72 100644 --- a/packages/app-builder-lib/src/options/SnapOptions.ts +++ b/packages/app-builder-lib/src/options/SnapOptions.ts @@ -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 -} \ No newline at end of file +} diff --git a/packages/app-builder-lib/src/targets/snap.ts b/packages/app-builder-lib/src/targets/snap.ts index e8b679e6738..f2f62d8a056 100644 --- a/packages/app-builder-lib/src/targets/snap.ts +++ b/packages/app-builder-lib/src/targets/snap.ts @@ -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 @@ -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") @@ -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"] -} \ No newline at end of file +} diff --git a/test/out/linux/__snapshots__/snapTest.js.snap b/test/out/linux/__snapshots__/snapTest.js.snap index 56c7d8b4ddd..12422b51870 100644 --- a/test/out/linux/__snapshots__/snapTest.js.snap +++ b/test/out/linux/__snapshots__/snapTest.js.snap @@ -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 { diff --git a/test/src/linux/snapTest.ts b/test/src/linux/snapTest.ts index b2a7a46f37d..fe0f57310fe 100644 --- a/test/src/linux/snapTest.ts +++ b/test/src/linux/snapTest.ts @@ -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 + }, +}))