Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial set of changes required for publishing to Flathub #293

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions build/flatpak/element.desktop.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build directory is (confusingly) for electron-builder's config, so we should keep things unrelated to electron builder somewhere else. Probably just a top-level flatpak directory?

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;
2 changes: 2 additions & 0 deletions build/flatpak/element.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
env TMPDIR="$XDG_RUNTIME_DIR/app/${FLATPAK_ID}" /app/element/element-desktop --no-sandbox "$@"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the --no-sandbox is due to not being able to run as root? I'm afraid this isn't an option: electron needs this to isolate contexts so this is really important for security.

40 changes: 40 additions & 0 deletions build/flatpak/metainfo.xml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>${FLATPAK_ID}</id>
<name>${FLATPAK_APPNAME}</name>
<project_license>Apache-2.0</project_license>
<developer_name>New Vector Ltd</developer_name>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably wants to be 'Element' (ie. the same as the author in package.json)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<developer_name>New Vector Ltd</developer_name>
<developer_name>Element</developer_name>

<summary>Create, share, communicate, chat and call securely, and bridge to other apps</summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably find some copy for this: I would guess the "Secure and independent communication, connected via Matrix" from the homepage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<summary>Create, share, communicate, chat and call securely, and bridge to other apps</summary>
<summary>Secure and independent communication, connected via Matrix</summary>

<metadata_license>CC0-1.0</metadata_license>
<url type="homepage">https://element.io/</url>
<url type="help">https://element.io/help</url>
<url type="translate">https://translate.element.io/</url>
<description>
<p>More than group chat: communication</p>
<ul>
<li>Communicate with your team and out of network colleagues more efficiently: use dedicated rooms which persist information from their creation and forever.</li>
<li>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.</li>
<li>Cut through the noise by creating notifications that are customised by you and for you.</li>
<li>Grab the attention of your colleague by calling out their name and don’t miss a thing with keyword alerts.</li>
<li>Deploy bots for fun or practical use with our integrations store.</li>
</ul>
</description>
<screenshots>
<screenshot>
<caption>Element logged-in frontend</caption>
<image type="source">https://user-images.githubusercontent.com/2221064/137519256-655fe0f9-55f0-44a4-b681-83711654fff0.png</image>
</screenshot>
</screenshots>
<releases>
<release version="${FLATPAK_VERSION}" date="${FLATPAK_DATE}"/>
</releases>
<content_rating type="oars-1.1">
<content_attribute id="social-chat">intense</content_attribute>
<content_attribute id="social-audio">intense</content_attribute>
<content_attribute id="social-contacts">intense</content_attribute>
</content_rating>
<provides>
<id>im.riot.Riot</id>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we stuck with this from historical precedent?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, kind of, keep in mind that this entry basically says "I provide the same capabilities as the app with the identifier im.riot.Riot" it's not the identifier of this app.

</provides>
<launchable type="desktop-id">${FLATPAK_ID}.desktop</launchable>
</component>
14 changes: 10 additions & 4 deletions dockerbuild/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM buildpack-deps:xenial-curl
FROM buildpack-deps:bionic-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 && \
Expand All @@ -17,7 +16,13 @@ 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 -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 && \
pip3 install aiohttp tenacity PyGObject && \
apt-get purge -y --auto-remove && rm -rf /var/lib/apt/lists/
Comment on lines +19 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there not a preexisting docker image for building flatpaks? Looks like the steps are separate, so it doesn't need to be the same docker image that runs electron build.


WORKDIR /project

Expand All @@ -36,7 +41,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 \
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -104,7 +105,7 @@
"webapp.asar"
],
"linux": {
"target": "deb",
"target": ["deb", "dir"],
"category": "Network;InstantMessaging;Chat",
"maintainer": "[email protected]",
"desktop": {
Expand Down
59 changes: 59 additions & 0 deletions scripts/build-flatpak.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

set -eu

: "${FLATPAK_ID:=io.element.ElementNightly}"
: "${FLATPAK_APPNAME:=Element Nightly}"
: "${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

[[ -d dist/flatpak ]] && rm -rf dist/flatpak
install -d dist/flatpak/
install -d dist/flatpak/build/files

cd dist/flatpak

cat <<EOF > 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 -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
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: zypak-wrapper

flatpak build-finish build \
--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 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