diff --git a/packages/electron-builder-lib/src/targets/snap.ts b/packages/electron-builder-lib/src/targets/snap.ts index 360f48076fb..88def407713 100644 --- a/packages/electron-builder-lib/src/targets/snap.ts +++ b/packages/electron-builder-lib/src/targets/snap.ts @@ -39,6 +39,7 @@ export default class SnapTarget extends Target { const plugs = normalizePlugConfiguration(options.plugs) const plugNames = this.replaceDefault(plugs == null ? null : Object.getOwnPropertyNames(plugs), defaultPlugs) + const desktopPart = this.packager.isElectron2 ? "desktop-gtk3" : "desktop-gtk2" const buildPackages = asArray(options.buildPackages) this.isUseTemplateApp = this.options.useTemplateApp !== false && arch === Arch.x64 && buildPackages.length === 0 @@ -75,7 +76,7 @@ export default class SnapTarget extends Target { app: { plugin: "nil", "stage-packages": this.replaceDefault(options.stagePackages, defaultStagePackages), - after: this.replaceDefault(options.after, [this.packager.isElectron2 ? "desktop-gtk3" : "desktop-gtk2"]), + after: this.replaceDefault(options.after, [desktopPart]), } }, } @@ -105,6 +106,31 @@ export default class SnapTarget extends Target { if (options.assumes != null) { snap.assumes = asArray(options.assumes) } + + if (snap.parts.app.after && snap.parts.app.after.indexOf(desktopPart) >= 0) { + const desktopPartOverride: any = { + install: `set -x +export XDG_DATA_DIRS=$SNAPCRAFT_PART_INSTALL/usr/share +update-mime-database $SNAPCRAFT_PART_INSTALL/usr/share/mime + +for dir in $SNAPCRAFT_PART_INSTALL/usr/share/icons/*/; do + if [ -f $dir/index.theme ]; then + if which gtk-update-icon-cache-3.0 &> /dev/null; then + gtk-update-icon-cache-3.0 -q $dir + elif which gtk-update-icon-cache &> /dev/null; then + gtk-update-icon-cache -q $dir + fi + fi +done` + } + + if (appDescriptor.plugs.indexOf("desktop") >= 0 || appDescriptor.plugs.indexOf("desktop-legacy") >= 0) { + desktopPartOverride.stage = ["-./usr/share/fonts/**"] + } + + snap.parts[desktopPart] = desktopPartOverride + } + return snap } @@ -187,4 +213,4 @@ function normalizePlugConfiguration(raw: Array | PlugDe } } return result -} \ 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 c49b926177b..26544353d0c 100644 --- a/test/out/linux/__snapshots__/snapTest.js.snap +++ b/test/out/linux/__snapshots__/snapTest.js.snap @@ -56,6 +56,24 @@ Object { "libxtst6", ], }, + "desktop-gtk2": Object { + "install": "set -x +export XDG_DATA_DIRS=$SNAPCRAFT_PART_INSTALL/usr/share +update-mime-database $SNAPCRAFT_PART_INSTALL/usr/share/mime + +for dir in $SNAPCRAFT_PART_INSTALL/usr/share/icons/*/; do + if [ -f $dir/index.theme ]; then + if which gtk-update-icon-cache-3.0 &> /dev/null; then + gtk-update-icon-cache-3.0 -q $dir + elif which gtk-update-icon-cache &> /dev/null; then + gtk-update-icon-cache -q $dir + fi + fi +done", + "stage": Array [ + "-./usr/share/fonts/**", + ], + }, }, "summary": "Sep", "version": "1.1.0", @@ -68,6 +86,69 @@ Object { } `; +exports[`custom after, no desktop 1`] = ` +Object { + "apps": Object { + "sep": Object { + "adapter": "none", + "command": "command.sh", + "environment": Object { + "LD_LIBRARY_PATH": "$SNAP_LIBRARY_PATH:$SNAP/usr/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu/pulseaudio:$SNAP/usr/lib/x86_64-linux-gnu/mesa-egl:$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", + "TMPDIR": "$XDG_RUNTIME_DIR", + }, + "plugs": Array [ + "desktop", + "desktop-legacy", + "home", + "x11", + "unity7", + "browser-support", + "network", + "gsettings", + "pulseaudio", + "opengl", + ], + }, + }, + "architectures": Array [ + "amd64", + ], + "confinement": "strict", + "description": "Test Application (test quite “ #378)", + "grade": "stable", + "icon": "snap/gui/icon.png", + "name": "sep", + "parts": Object { + "app": Object { + "after": Array [ + "bar", + ], + "plugin": "nil", + "stage-packages": Array [ + "libasound2", + "libgconf2-4", + "libnotify4", + "libnspr4", + "libnss3", + "libpcre3", + "libpulse0", + "libxss1", + "libxtst6", + ], + }, + }, + "summary": "Sep", + "version": "1.1.0", +} +`; + +exports[`custom after, no desktop 2`] = ` +Object { + "linux": Array [], +} +`; + exports[`custom env 1`] = ` Object { "apps": Object { @@ -162,6 +243,24 @@ Object { "libxtst6", ], }, + "desktop-gtk2": Object { + "install": "set -x +export XDG_DATA_DIRS=$SNAPCRAFT_PART_INSTALL/usr/share +update-mime-database $SNAPCRAFT_PART_INSTALL/usr/share/mime + +for dir in $SNAPCRAFT_PART_INSTALL/usr/share/icons/*/; do + if [ -f $dir/index.theme ]; then + if which gtk-update-icon-cache-3.0 &> /dev/null; then + gtk-update-icon-cache-3.0 -q $dir + elif which gtk-update-icon-cache &> /dev/null; then + gtk-update-icon-cache -q $dir + fi + fi +done", + "stage": Array [ + "-./usr/share/fonts/**", + ], + }, }, "summary": "Sep", "version": "1.1.0", @@ -227,6 +326,24 @@ Object { "custom", ], }, + "desktop-gtk2": Object { + "install": "set -x +export XDG_DATA_DIRS=$SNAPCRAFT_PART_INSTALL/usr/share +update-mime-database $SNAPCRAFT_PART_INSTALL/usr/share/mime + +for dir in $SNAPCRAFT_PART_INSTALL/usr/share/icons/*/; do + if [ -f $dir/index.theme ]; then + if which gtk-update-icon-cache-3.0 &> /dev/null; then + gtk-update-icon-cache-3.0 -q $dir + elif which gtk-update-icon-cache &> /dev/null; then + gtk-update-icon-cache -q $dir + fi + fi +done", + "stage": Array [ + "-./usr/share/fonts/**", + ], + }, }, "summary": "Sep", "version": "1.1.0", @@ -292,6 +409,24 @@ Object { "libxtst6", ], }, + "desktop-gtk2": Object { + "install": "set -x +export XDG_DATA_DIRS=$SNAPCRAFT_PART_INSTALL/usr/share +update-mime-database $SNAPCRAFT_PART_INSTALL/usr/share/mime + +for dir in $SNAPCRAFT_PART_INSTALL/usr/share/icons/*/; do + if [ -f $dir/index.theme ]; then + if which gtk-update-icon-cache-3.0 &> /dev/null; then + gtk-update-icon-cache-3.0 -q $dir + elif which gtk-update-icon-cache &> /dev/null; then + gtk-update-icon-cache -q $dir + fi + fi +done", + "stage": Array [ + "-./usr/share/fonts/**", + ], + }, }, "summary": "Sep", "version": "1.1.0", @@ -359,6 +494,24 @@ Object { "foo2", ], }, + "desktop-gtk2": Object { + "install": "set -x +export XDG_DATA_DIRS=$SNAPCRAFT_PART_INSTALL/usr/share +update-mime-database $SNAPCRAFT_PART_INSTALL/usr/share/mime + +for dir in $SNAPCRAFT_PART_INSTALL/usr/share/icons/*/; do + if [ -f $dir/index.theme ]; then + if which gtk-update-icon-cache-3.0 &> /dev/null; then + gtk-update-icon-cache-3.0 -q $dir + elif which gtk-update-icon-cache &> /dev/null; then + gtk-update-icon-cache -q $dir + fi + fi +done", + "stage": Array [ + "-./usr/share/fonts/**", + ], + }, }, "summary": "Sep", "version": "1.1.0", @@ -371,6 +524,40 @@ Object { } `; +exports[`no desktop plugs 1`] = ` +Object { + "apps": Object { + "sep": Object { + "command": "command.sh", + "environment": Object { + "LD_LIBRARY_PATH": "$SNAP_LIBRARY_PATH:$SNAP/usr/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu/pulseaudio:$SNAP/usr/lib/x86_64-linux-gnu/mesa-egl:$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", + "TMPDIR": "$XDG_RUNTIME_DIR", + }, + "plugs": Array [ + "foo", + "bar", + ], + }, + }, + "architectures": Array [ + "amd64", + ], + "confinement": "strict", + "description": "Test Application (test quite “ #378)", + "grade": "stable", + "name": "sep", + "summary": "Sep", + "version": "1.1.0", +} +`; + +exports[`no desktop plugs 2`] = ` +Object { + "linux": Array [], +} +`; + exports[`plugs option 1`] = ` Object { "apps": Object { @@ -414,6 +601,21 @@ Object { "libxtst6", ], }, + "desktop-gtk2": Object { + "install": "set -x +export XDG_DATA_DIRS=$SNAPCRAFT_PART_INSTALL/usr/share +update-mime-database $SNAPCRAFT_PART_INSTALL/usr/share/mime + +for dir in $SNAPCRAFT_PART_INSTALL/usr/share/icons/*/; do + if [ -f $dir/index.theme ]; then + if which gtk-update-icon-cache-3.0 &> /dev/null; then + gtk-update-icon-cache-3.0 -q $dir + elif which gtk-update-icon-cache &> /dev/null; then + gtk-update-icon-cache -q $dir + fi + fi +done", + }, }, "plugs": Object { "browser-sandbox": Object { @@ -475,6 +677,21 @@ Object { "libxtst6", ], }, + "desktop-gtk2": Object { + "install": "set -x +export XDG_DATA_DIRS=$SNAPCRAFT_PART_INSTALL/usr/share +update-mime-database $SNAPCRAFT_PART_INSTALL/usr/share/mime + +for dir in $SNAPCRAFT_PART_INSTALL/usr/share/icons/*/; do + if [ -f $dir/index.theme ]; then + if which gtk-update-icon-cache-3.0 &> /dev/null; then + gtk-update-icon-cache-3.0 -q $dir + elif which gtk-update-icon-cache &> /dev/null; then + gtk-update-icon-cache -q $dir + fi + fi +done", + }, }, "plugs": Object { "browser-sandbox": Object { diff --git a/test/src/linux/snapTest.ts b/test/src/linux/snapTest.ts index 6644b11e3c9..fad69885f06 100644 --- a/test/src/linux/snapTest.ts +++ b/test/src/linux/snapTest.ts @@ -166,3 +166,37 @@ test.ifDevOrLinuxCi("custom env", app({ return true }, })) + +test.ifDevOrLinuxCi("custom after, no desktop", app({ + targets: Platform.LINUX.createTarget("snap"), + config: { + extraMetadata: { + name: "sep", + }, + productName: "Sep", + snap: { + after: ["bar"], + } + }, + effectiveOptionComputed: async ({ snap }) => { + expect(snap).toMatchSnapshot() + return true + }, +})) + +test.ifDevOrLinuxCi("no desktop plugs", app({ + targets: Platform.LINUX.createTarget("snap"), + config: { + extraMetadata: { + name: "sep", + }, + productName: "Sep", + snap: { + plugs: ["foo", "bar"] + } + }, + effectiveOptionComputed: async ({ snap }) => { + expect(snap).toMatchSnapshot() + return true + }, +}))