From eb39349abbc06ad2cac8d8a47e825112ea6ad961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Wed, 29 Dec 2021 10:46:38 +0100 Subject: [PATCH 01/14] Install yarn with npm The `curl -L https://yarnpkg.com/latest.tar.gz` command fails on SSL validation. --- dockerbuild/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dockerbuild/Dockerfile b/dockerbuild/Dockerfile index 3e9566f59d..20ff5dbe54 100644 --- a/dockerbuild/Dockerfile +++ b/dockerbuild/Dockerfile @@ -2,7 +2,6 @@ FROM buildpack-deps:xenial-curl ENV DEBIAN_FRONTEND noninteractive -RUN curl -L https://yarnpkg.com/latest.tar.gz | tar xvz && mv yarn-* /yarn && ln -s /yarn/bin/yarn /usr/bin/yarn RUN apt-get -qq update && apt-get -qq dist-upgrade && \ # add repo for git-lfs curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash && \ @@ -36,7 +35,8 @@ ENV NODE_VERSION 14.17.0 RUN curl -L https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz | tar xz -C /usr/local --strip-components=1 && \ unlink /usr/local/CHANGELOG.md && unlink /usr/local/LICENSE && unlink /usr/local/README.md && \ # https://github.com/npm/npm/issues/4531 - npm config set unsafe-perm true + npm config set unsafe-perm true && \ + npm install --global yarn ENV RUSTUP_HOME=/usr/local/rustup \ CARGO_HOME=/usr/local/cargo \ From f8dd16a6ae58c6bdb161f3c12e6fcc650137d878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Wed, 29 Dec 2021 10:47:19 +0100 Subject: [PATCH 02/14] Install tools and dependencies required for Flatpak build Ubuntu 16.04 doesn't ship Flatpak in default repositories, so we need to install it from the project's PPA. Additionally, it ships too old Python for a tool used to create and upload Flathub builds to work, so we need another PPA to install Python 3.6. --- dockerbuild/Dockerfile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dockerbuild/Dockerfile b/dockerbuild/Dockerfile index 20ff5dbe54..1c18e3b32b 100644 --- a/dockerbuild/Dockerfile +++ b/dockerbuild/Dockerfile @@ -16,7 +16,19 @@ RUN apt-get -qq update && apt-get -qq dist-upgrade && \ libsqlcipher-dev && \ # git-lfs git lfs install && \ - apt-get purge -y --auto-remove && rm -rf /var/lib/apt/lists/* + # used by flathub client \ + apt-get install -y software-properties-common && \ + add-apt-repository ppa:flatpak/stable && \ + add-apt-repository ppa:deadsnakes/ppa && \ + apt-get -qq update && \ + apt-get -qq install -y --no-install-recommends flatpak ostree && \ + apt-get -qq install -y python3.6 python3.6-dev libgirepository1.0-dev gir1.2-ostree-1.0 libcairo2-dev && \ + curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \ + python3.6 get-pip.py && \ + curl -sSL https://raw.githubusercontent.com/flatpak/flat-manager/master/flat-manager-client -o /usr/local/bin/flat-manager-client && \ + chmod +x /usr/local/bin/flat-manager-client && \ + /usr/local/bin/pip install aiohttp tenacity PyGObject && \ + apt-get purge -y --auto-remove && rm -rf /var/lib/apt/lists/ WORKDIR /project From 183cae31e02f3a527fb3941d3d4e19b5badea936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Wed, 29 Dec 2021 12:11:15 +0100 Subject: [PATCH 03/14] Add directory to electron-builder's Linux target types It is easier to create a flatpak package from "raw" files than having to additionally extract a deb file. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 29a67e0005..3fa29fb008 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ "webapp.asar" ], "linux": { - "target": "deb", + "target": ["deb", "dir"], "category": "Network;InstantMessaging;Chat", "maintainer": "support@element.io", "desktop": { From f0fddda3c36ab3b8497950e92eecefe815813397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Wed, 29 Dec 2021 15:39:19 +0100 Subject: [PATCH 04/14] Add template freedesktop metadata/launcher files --- build/flatpak/element.desktop.in | 9 +++++++ build/flatpak/metainfo.xml.in | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 build/flatpak/element.desktop.in create mode 100644 build/flatpak/metainfo.xml.in diff --git a/build/flatpak/element.desktop.in b/build/flatpak/element.desktop.in new file mode 100644 index 0000000000..04c8024558 --- /dev/null +++ b/build/flatpak/element.desktop.in @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Application +Name=${FLATPAK_APPNAME} +Icon=${FLATPAK_ID} +Exec=element %U +Categories=Network;InstantMessaging;Chat;VideoConference; +MimeType=x-scheme-handler/element; +StartupWMClass=element +Keywords=Matrix;matrix.org;chat;irc;communications;talk;riot;vector; diff --git a/build/flatpak/metainfo.xml.in b/build/flatpak/metainfo.xml.in new file mode 100644 index 0000000000..be1172ba0b --- /dev/null +++ b/build/flatpak/metainfo.xml.in @@ -0,0 +1,40 @@ + + + ${FLATPAK_ID} + ${FLATPAK_APPNAME} + Apache-2.0 + New Vector Ltd + Create, share, communicate, chat and call securely, and bridge to other apps + CC0-1.0 + https://element.io/ + https://element.io/help + https://translate.element.io/ + +

More than group chat: communication

+
    +
  • Communicate with your team and out of network colleagues more efficiently: use dedicated rooms which persist information from their creation and forever.
  • +
  • Forget group emails: join or create rooms per topic, per team, per event… Decide the level of transparency you want to provide across the organisation or project.
  • +
  • Cut through the noise by creating notifications that are customised by you and for you.
  • +
  • Grab the attention of your colleague by calling out their name and don’t miss a thing with keyword alerts.
  • +
  • Deploy bots for fun or practical use with our integrations store.
  • +
+
+ + + Element logged-in frontend + https://user-images.githubusercontent.com/2221064/137519256-655fe0f9-55f0-44a4-b681-83711654fff0.png + + + + + + + intense + intense + intense + + + im.riot.Riot + + ${FLATPAK_ID}.desktop +
From 05e1daceb1c906b59dfb75ec6618f74486531667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Wed, 29 Dec 2021 15:40:26 +0100 Subject: [PATCH 05/14] Add bare-bones script for Flatpak build --- package.json | 3 ++- scripts/build-flatpak.sh | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 scripts/build-flatpak.sh diff --git a/package.json b/package.json index 3fa29fb008..630fa260cc 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ "docker:install": "scripts/in-docker.sh yarn install", "debrepo": "scripts/mkrepo.sh", "clean": "rimraf webapp.asar dist packages deploys lib", - "hak": "ts-node scripts/hak/index.ts" + "hak": "ts-node scripts/hak/index.ts", + "flatpak": "yarn build && scripts/in-docker.sh scripts/build-flatpak.sh" }, "dependencies": { "auto-launch": "^5.0.5", diff --git a/scripts/build-flatpak.sh b/scripts/build-flatpak.sh new file mode 100644 index 0000000000..48d3c5f2b1 --- /dev/null +++ b/scripts/build-flatpak.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -eu + +: "${FLATPAK_ID:=io.element.Element}" +: "${FLATPAK_APPNAME:='Element Nightly'}" +: "${FLATPAK_VERSION:="0.0.0-nightly"}" +: "${FLATPAK_DATE:="$(date +%Y%m%d%H%M%S)"}" +: "${FLATPAK_BRANCH:=nightly}" + +install -d dist/flatpak/ +install -d dist/flatpak/build/files + +cd dist/flatpak + +cat < build/metadata +[Application] +name=${FLATPAK_ID} +runtime=org.freedesktop.Platform/x86_64/21.08 +sdk=org.freedesktop.Sdk/x86_64/21.08 +EOF + +cp -r ../linux-unpacked build/files/element +install -Dm644 ../../build/icons/512x512.png build/files/share/icons/hicolor/512x512/${FLATPAK_ID}.png + +install -d build/files/share/applications +envsubst < ../../build/flatpak/element.desktop.in > build/files/share/applications/${FLATPAK_ID}.desktop + +install -d build/files/share/metainfo +envsubst < ../../build/flatpak/metainfo.xml.in > build/files/share/metainfo/${FLATPAK_ID}.metainfo.xml + +# TODO: baseapp with deps +# TODO: appstream-compose +# TODO: mirror screenshots +# TODO: zypak-wrapper + +flatpak build-finish build \ + --command=bash + +flatpak build-export --disable-sandbox repo build "$FLATPAK_BRANCH" +flatpak build-update-repo --generate-static-deltas repo +flatpak build-bundle repo ../element.flatpak $FLATPAK_ID From 0479d951db43509dfceff9d6e062616fd51e0102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Thu, 30 Dec 2021 09:24:24 +0100 Subject: [PATCH 06/14] Variables need to be exported for envsubst --- scripts/build-flatpak.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/build-flatpak.sh b/scripts/build-flatpak.sh index 48d3c5f2b1..b91750f364 100644 --- a/scripts/build-flatpak.sh +++ b/scripts/build-flatpak.sh @@ -2,12 +2,14 @@ set -eu -: "${FLATPAK_ID:=io.element.Element}" +: "${FLATPAK_ID:=io.element.ElementNightly}" : "${FLATPAK_APPNAME:='Element Nightly'}" -: "${FLATPAK_VERSION:="0.0.0-nightly"}" -: "${FLATPAK_DATE:="$(date +%Y%m%d%H%M%S)"}" +: "${FLATPAK_VERSION:="0.0.0-nightly$(date +%Y%m%d)"}" +: "${FLATPAK_DATE:="$(date +%Y-%m-%d)"}" : "${FLATPAK_BRANCH:=nightly}" +export FLATPAK_ID FLATPAK_APPNAME FLATPAK_VERSION FLATPAK_DATE FLATPAK_BRANCH + install -d dist/flatpak/ install -d dist/flatpak/build/files From 6703f6b6d0ecc0e0281aaac2c244e20b4b644cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Thu, 30 Dec 2021 09:24:40 +0100 Subject: [PATCH 07/14] Remove dist/flatpak if it exists --- scripts/build-flatpak.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/build-flatpak.sh b/scripts/build-flatpak.sh index b91750f364..7db7c3e90d 100644 --- a/scripts/build-flatpak.sh +++ b/scripts/build-flatpak.sh @@ -10,6 +10,7 @@ set -eu export FLATPAK_ID FLATPAK_APPNAME FLATPAK_VERSION FLATPAK_DATE FLATPAK_BRANCH +[[ -d dist/flatpak ]] && rm -rf dist/flatpak install -d dist/flatpak/ install -d dist/flatpak/build/files From 7885b86965f122fa2f7d936e3d1212e54cd8728b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Thu, 30 Dec 2021 09:25:41 +0100 Subject: [PATCH 08/14] Add launcher script to ensure only single instance is running --- build/flatpak/element.sh | 2 ++ scripts/build-flatpak.sh | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 build/flatpak/element.sh diff --git a/build/flatpak/element.sh b/build/flatpak/element.sh new file mode 100644 index 0000000000..6f516e5d00 --- /dev/null +++ b/build/flatpak/element.sh @@ -0,0 +1,2 @@ +#!/bin/bash +env TMPDIR="$XDG_RUNTIME_DIR/app/${FLATPAK_ID}" /app/Element/element-desktop --no-sandbox "$@" diff --git a/scripts/build-flatpak.sh b/scripts/build-flatpak.sh index 7db7c3e90d..8432a661a4 100644 --- a/scripts/build-flatpak.sh +++ b/scripts/build-flatpak.sh @@ -24,12 +24,10 @@ sdk=org.freedesktop.Sdk/x86_64/21.08 EOF cp -r ../linux-unpacked build/files/element -install -Dm644 ../../build/icons/512x512.png build/files/share/icons/hicolor/512x512/${FLATPAK_ID}.png - -install -d build/files/share/applications +install -d build/files/share/applications build/files/share/metainfo +install -Dm755 ../../build/flatpak/element.sh build/files/bin/element +install -Dm644 ../../build/icons/512x512.png build/files/share/icons/hicolor/512x512/apps/${FLATPAK_ID}.png envsubst < ../../build/flatpak/element.desktop.in > build/files/share/applications/${FLATPAK_ID}.desktop - -install -d build/files/share/metainfo envsubst < ../../build/flatpak/metainfo.xml.in > build/files/share/metainfo/${FLATPAK_ID}.metainfo.xml # TODO: baseapp with deps From b18fb711b45dfba5870846ba47c5d1cd059924b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Thu, 30 Dec 2021 09:26:30 +0100 Subject: [PATCH 09/14] Create app-info and mirror screenshots --- scripts/build-flatpak.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/build-flatpak.sh b/scripts/build-flatpak.sh index 8432a661a4..05bfa0e21b 100644 --- a/scripts/build-flatpak.sh +++ b/scripts/build-flatpak.sh @@ -30,9 +30,12 @@ install -Dm644 ../../build/icons/512x512.png build/files/share/icons/hicolor/512 envsubst < ../../build/flatpak/element.desktop.in > build/files/share/applications/${FLATPAK_ID}.desktop envsubst < ../../build/flatpak/metainfo.xml.in > build/files/share/metainfo/${FLATPAK_ID}.metainfo.xml +appstream-compose --prefix=build/files --origin=flatpak --basename=${FLATPAK_ID} ${FLATPAK_ID} +appstream-util mirror-screenshots build/files/share/app-info/xmls/${FLATPAK_ID}.xml.gz \ + "https://dl.flathub.org/repo/screenshots/${FLATPAK_ID}-${FLATPAK_BRANCH}" \ + build/screenshots "build/screeshots/${FLATPAK_ID}-${FLATPAK_BRANCH}" + # TODO: baseapp with deps -# TODO: appstream-compose -# TODO: mirror screenshots # TODO: zypak-wrapper flatpak build-finish build \ From 149d470258a620b7726e66405745ebf8825ce1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Thu, 30 Dec 2021 09:26:49 +0100 Subject: [PATCH 10/14] Land actual permissions required by Element to work --- scripts/build-flatpak.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/build-flatpak.sh b/scripts/build-flatpak.sh index 05bfa0e21b..831e2ae47e 100644 --- a/scripts/build-flatpak.sh +++ b/scripts/build-flatpak.sh @@ -39,7 +39,19 @@ appstream-util mirror-screenshots build/files/share/app-info/xmls/${FLATPAK_ID}. # TODO: zypak-wrapper flatpak build-finish build \ - --command=bash + --socket=x11 \ + --share=ipc \ + --socket=pulseaudio \ + --device=all \ + --share=network \ + --filesystem=xdg-download \ + --talk-name=org.freedesktop.Notifications \ + --talk-name=org.kde.StatusNotifierWatcher \ + --talk-name=org.freedesktop.ScreenSaver \ + --own-name='org.kde.*' \ + --talk-name=org.freedesktop.portal.Fcitx \ + --filesystem=xdg-run/keyring \ + --command=element flatpak build-export --disable-sandbox repo build "$FLATPAK_BRANCH" flatpak build-update-repo --generate-static-deltas repo From 702f8e76417b00e6cd1743d52c05420c681e2995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Thu, 30 Dec 2021 09:27:15 +0100 Subject: [PATCH 11/14] Fix single-file bundle generation --- scripts/build-flatpak.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/build-flatpak.sh b/scripts/build-flatpak.sh index 831e2ae47e..8cbcc18e53 100644 --- a/scripts/build-flatpak.sh +++ b/scripts/build-flatpak.sh @@ -53,6 +53,7 @@ flatpak build-finish build \ --filesystem=xdg-run/keyring \ --command=element -flatpak build-export --disable-sandbox repo build "$FLATPAK_BRANCH" +flatpak build-export --disable-sandbox repo build $FLATPAK_BRANCH flatpak build-update-repo --generate-static-deltas repo -flatpak build-bundle repo ../element.flatpak $FLATPAK_ID +flatpak build-bundle --runtime-repo=https://dl.flathub.org/repo/flathub.flatpakrepo \ + repo ../element.flatpak $FLATPAK_ID $FLATPAK_BRANCH From 6be315d40bb3fc5b61381e10bef0c46a0e67a083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Thu, 30 Dec 2021 10:02:00 +0100 Subject: [PATCH 12/14] Remove single quotes from the default FLATPAK_APPNAME value --- scripts/build-flatpak.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build-flatpak.sh b/scripts/build-flatpak.sh index 8cbcc18e53..4b0b53bf60 100644 --- a/scripts/build-flatpak.sh +++ b/scripts/build-flatpak.sh @@ -3,7 +3,7 @@ set -eu : "${FLATPAK_ID:=io.element.ElementNightly}" -: "${FLATPAK_APPNAME:='Element Nightly'}" +: "${FLATPAK_APPNAME:=Element Nightly}" : "${FLATPAK_VERSION:="0.0.0-nightly$(date +%Y%m%d)"}" : "${FLATPAK_DATE:="$(date +%Y-%m-%d)"}" : "${FLATPAK_BRANCH:=nightly}" From 2e76778354fa2f234a095e05127eeae189d0b8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Thu, 30 Dec 2021 11:34:01 +0100 Subject: [PATCH 13/14] Upgrade to buildpack-deps:bionic-curl appstream-util shipped with Xenial is so old it doesn't support specific URL types and PNG icons, rendering it useless. --- dockerbuild/Dockerfile | 14 ++++---------- scripts/build-flatpak.sh | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) mode change 100644 => 100755 scripts/build-flatpak.sh diff --git a/dockerbuild/Dockerfile b/dockerbuild/Dockerfile index 1c18e3b32b..23f0127c2b 100644 --- a/dockerbuild/Dockerfile +++ b/dockerbuild/Dockerfile @@ -1,4 +1,4 @@ -FROM buildpack-deps:xenial-curl +FROM buildpack-deps:bionic-curl ENV DEBIAN_FRONTEND noninteractive @@ -17,17 +17,11 @@ RUN apt-get -qq update && apt-get -qq dist-upgrade && \ # git-lfs git lfs install && \ # used by flathub client \ - apt-get install -y software-properties-common && \ - add-apt-repository ppa:flatpak/stable && \ - add-apt-repository ppa:deadsnakes/ppa && \ - apt-get -qq update && \ - apt-get -qq install -y --no-install-recommends flatpak ostree && \ - apt-get -qq install -y python3.6 python3.6-dev libgirepository1.0-dev gir1.2-ostree-1.0 libcairo2-dev && \ - curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \ - python3.6 get-pip.py && \ + apt-get -qq install -y --no-install-recommends flatpak ostree gettext appstream-util curl && \ + apt-get -qq install -y python3 python3-dev python3-pip libgirepository1.0-dev gir1.2-ostree-1.0 libcairo2-dev && \ curl -sSL https://raw.githubusercontent.com/flatpak/flat-manager/master/flat-manager-client -o /usr/local/bin/flat-manager-client && \ chmod +x /usr/local/bin/flat-manager-client && \ - /usr/local/bin/pip install aiohttp tenacity PyGObject && \ + pip3 install aiohttp tenacity PyGObject && \ apt-get purge -y --auto-remove && rm -rf /var/lib/apt/lists/ WORKDIR /project diff --git a/scripts/build-flatpak.sh b/scripts/build-flatpak.sh old mode 100644 new mode 100755 index 4b0b53bf60..3448950f73 --- a/scripts/build-flatpak.sh +++ b/scripts/build-flatpak.sh @@ -53,7 +53,7 @@ flatpak build-finish build \ --filesystem=xdg-run/keyring \ --command=element -flatpak build-export --disable-sandbox repo build $FLATPAK_BRANCH +flatpak build-export repo build $FLATPAK_BRANCH flatpak build-update-repo --generate-static-deltas repo flatpak build-bundle --runtime-repo=https://dl.flathub.org/repo/flathub.flatpakrepo \ repo ../element.flatpak $FLATPAK_ID $FLATPAK_BRANCH From 5c6e13dff8412829059aa3f26895c74dd890ee0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Thu, 30 Dec 2021 11:40:35 +0100 Subject: [PATCH 14/14] Fix path to element-desktop executable in the wrapper script --- build/flatpak/element.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/flatpak/element.sh b/build/flatpak/element.sh index 6f516e5d00..7a60354edb 100644 --- a/build/flatpak/element.sh +++ b/build/flatpak/element.sh @@ -1,2 +1,2 @@ #!/bin/bash -env TMPDIR="$XDG_RUNTIME_DIR/app/${FLATPAK_ID}" /app/Element/element-desktop --no-sandbox "$@" +env TMPDIR="$XDG_RUNTIME_DIR/app/${FLATPAK_ID}" /app/element/element-desktop --no-sandbox "$@"