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

Add Flatpak configs #126

Merged
merged 3 commits into from
Dec 29, 2022
Merged
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
28 changes: 28 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM mcr.microsoft.com/devcontainers/base:ubuntu-20.04


# ------------------------ Prepare docker environment ------------------------ #

RUN apt-get update

# Install general utilities
RUN apt-get -y install tree

# Install Flutter dependencies
RUN apt-get -y install curl file git unzip xz-utils zip clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev
# Install app-specific dependencies
RUN apt-get -y install keybinder-3.0 appindicator3-0.1 libappindicator3-1 libappindicator3-dev

# Install Flutter
RUN git clone https://github.com/flutter/flutter.git /home/vscode/flutter
RUN git config --global --add safe.directory /home/vscode/flutter
ENV PATH="$PATH:/home/vscode/flutter/bin"
RUN flutter upgrade
RUN chown -R vscode:vscode /home/vscode/flutter

# Prepare environment for building Flatpak
RUN apt-get install -y flatpak flatpak-builder
RUN flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
RUN flatpak install -y org.freedesktop.Sdk/x86_64/21.08
RUN flatpak install -y org.freedesktop.Platform/x86_64/21.08
RUN flatpak install -y flathub org.freedesktop.appstream-glib
32 changes: 32 additions & 0 deletions .devcontainer/build-flatpak-in-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash


# When run from the vscode dev container this will build a .flatpak of the app.


set -x


projectName=Nyrna
projectId=codes.merritt.Nyrna

archiveName=$projectName-Linux-Portable.tar.gz

# ----------------------------- Build Flutter app ---------------------------- #

flutter pub get
flutter build linux

workspace=$PWD
cd build/linux/x64/release/bundle || exit
touch PORTABLE
tar -czaf $archiveName ./*
cp -r $archiveName "$workspace"/packaging/linux/flatpak/
cd "$workspace" || exit

# ------------------------------- Build Flatpak ------------------------------ #

cd packaging/linux/flatpak || exit

flatpak-builder --force-clean build-dir $projectId.yml --repo=repo
flatpak build-bundle repo $projectId.flatpak $projectId
35 changes: 35 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",

// "image": "mcr.microsoft.com/devcontainers/base:focal",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
"dockerfile": "Dockerfile"
},

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"

"privileged": true,

"remoteEnv": {
// Add Flutter to the PATH variable.
"PATH": "${containerEnv:PATH}:/home/vscode/flutter/bin"
}
}
2 changes: 1 addition & 1 deletion .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ jobs:
- name: Compress build for Linux
if: matrix.target == 'Linux'
run: |
tar czf ${{ env.project-name }}-${{ matrix.target }}-Portable.tar.gz *
tar aczf ${{ env.project-name }}-${{ matrix.target }}-Portable.tar.gz *
mv *.tar.gz ${{ github.workspace }}/output/
working-directory: ${{ matrix.build_path }}

Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/flatpak.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# name: Publish Flatpak

# on:
# # Enable manual run
# workflow_dispatch:
# # Build & deploy for published releases
# release:
# types:
# - published

# # ${{ secrets.FLATHUB_TOKEN }} is a Personal Access Token to grant push access.

# env:
# project-id: codes.merritt.bargain

# jobs:
# update-recipe:
# name: Update Flatpak recipe files
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v2
# with:
# path: code

# - name: Install dependencies
# run: |
# sudo apt-get update
# sudo apt-get install -y flatpak flatpak-builder
# sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
# sudo flatpak install -y org.freedesktop.Sdk/x86_64/21.08
# sudo flatpak install -y org.freedesktop.Platform/x86_64/21.08
# sudo flatpak install -y flathub org.freedesktop.appstream-glib

# - name: Setup Dart SDK
# uses: dart-lang/setup-dart@v1.3

# - name: Prepare for Flatpak build & update recipe files
# working-directory: ${{ github.workspace }}/code/packaging/linux/flatpak
# run: |
# bash prepare-flatpak-build.sh

# - name: Verify Flatpak builds successfully
# working-directory: ${{ github.workspace }}/code/packaging/linux/flatpak
# run: |
# cp ../${{ env.project-id }}.metainfo.xml .
# flatpak-builder --force-clean build-dir ${{ env.project-id }}.yml

# - name: Checkout flathub repository
# uses: actions/checkout@v2
# with:
# repository: flathub/${{ env.project-id }}
# path: flathub
# token: ${{ secrets.FLATHUB_TOKEN }}

# - name: Push updated recipe to Flathub
# working-directory: ${{ github.workspace }}
# env:
# GH_TOKEN: ${{ secrets.FLATHUB_TOKEN }}
# REPO_KEY: ${{ secrets.FLATHUB_TOKEN }}
# USERNAME: merrit
# run: |
# cd ${{ github.workspace }}/flathub
# cp -r ${{ github.workspace }}/code/packaging/linux/flatpak/${{ env.project-id }}.json .
# cp -r ${{ github.workspace }}/code/packaging/linux/flatpak/${{ env.project-id }}.metainfo.xml .
# git config --local user.name "Kristen McWilliam"
# git config --local user.email "9575627+Merrit@users.noreply.github.com"
# git checkout -b flathub_update
# git add -A
# git commit -m "Update flatpak for new release"
# git push -u origin flathub_update -f
# gh pr create --fill --head flathub_update
# # Disable auto-merge because they are disallowing it (╯°□°)╯︵ ┻━┻
# # gh pr merge --rebase --delete-branch
# # git push https://$USERNAME:$REPO_KEY@github.com/flathub/${{ env.project-id }}.git
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ appimage-builder-cache
packaging/linux/appimage/AppDir
packaging/linux/appimage/appimage-builder-cache
packaging/output/
.flatpak-builder
build-dir
shared-modules

# PKGBUILD extras
packaging/PKGBUILD/.SRCINFO
Expand Down
21 changes: 21 additions & 0 deletions assets/icon/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions lib/native_platform/src/linux/flatpak.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'dart:io';

import '../typedefs.dart';

/// Run commands from within a Flatpak environment, directly on the host.
RunFunction flatpakRun = (String executable, List<String> args) async {
return await Process.run(
'flatpak-spawn',
['--host', executable, ...args],
);
};

/// When in Flatpak using the built-in Process.killPid will try to act on the
/// dummy pids it sees inside the container, so we use the host run instead.
KillFunction flatpakKill = (
int pid, [
ProcessSignal signal = ProcessSignal.sigcont,
]) {
flatpakRun('kill', ['-${signal.toString()}', '$pid']);
return true;
};

/// True if the application is running inside a Flatpak container.
final bool runningInFlatpak = Platform.environment.containsKey('FLATPAK_ID');
4 changes: 3 additions & 1 deletion lib/native_platform/src/native_platform.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io' as io;

import 'linux/flatpak.dart';
import 'linux/linux.dart';
import 'win32/win32.dart';
import 'window.dart';
Expand All @@ -12,7 +13,8 @@ abstract class NativePlatform {
// Return correct subtype depending on the current operating system.
factory NativePlatform() {
if (io.Platform.isLinux) {
return Linux(io.Process.run);
final runFunction = (runningInFlatpak) ? flatpakRun : io.Process.run;
return Linux(runFunction);
} else {
return Win32();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io' as io;

import '../../linux/flatpak.dart';
import '../models/process.dart';
import 'src/linux_process_repository.dart';
import 'src/win32_process_repository.dart';
Expand All @@ -13,7 +14,11 @@ abstract class ProcessRepository {

static ProcessRepository init() {
if (io.Platform.isLinux) {
return const LinuxProcessRepository(io.Process.killPid, io.Process.run);
final runFunction = (runningInFlatpak) ? flatpakRun : io.Process.run;
final killFunction = (runningInFlatpak) //
? flatpakKill
: io.Process.killPid;
return LinuxProcessRepository(killFunction, runFunction);
} else {
return const Win32ProcessRepository(io.Process.run);
}
Expand Down
10 changes: 10 additions & 0 deletions packaging/linux/codes.merritt.Nyrna.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Desktop Entry]
Type=Application
Name=Nyrna
Comment=Suspend games and applications
Exec=nyrna
Icon=codes.merritt.Nyrna
Terminal=false
StartupNotify=false
Categories=Utility;
StartupWMClass=Nyrna
72 changes: 72 additions & 0 deletions packaging/linux/codes.merritt.Nyrna.metainfo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Generator for metainfo & .desktop files:
https://www.freedesktop.org/software/appstream/metainfocreator/#/
-->
<component type="desktop-application">
<id>codes.merritt.Nyrna</id>
<name>Nyrna</name>
<summary>Easily compare items when shopping</summary>
<developer_name>Merritt Codes</developer_name>
<url type="homepage">https://merritt.codes/bargain/</url>
<url type="donation">https://merritt.codes/support/</url>
<metadata_license>MIT</metadata_license>
<project_license>GPL-3.0-or-later</project_license>
<supports>
<control>pointing</control>
<control>keyboard</control>
<control>touch</control>
</supports>
<description>
<p>Save money: Unit Bargain Hunter helps you figure out and keep track of the best value for products.</p>
<p>Is that family-sized pack really a better value?</p>
<p>If a brand-name item is $14.99 for 500g and the no-name item beside it is $13.99 for 20 oz, which is the better deal?</p>
<p>Unit Bargain Hunter makes it easy to compare any number of items to find exactly how they stack up against each other.</p>
<ul>
<li>Compare unlimited items</li>
<li>Compare by weight, volume, or number of items</li>
<li>Saves your information between sessions</li>
<li>Available cross-platform: Linux, Windows, Web, Android</li>
<li>Open source</li>
</ul>
</description>
<launchable type="desktop-id">nyrna.desktop</launchable>
<!-- <launchable type="desktop-id">codes.merritt.Nyrna.desktop</launchable> -->
<screenshots>
<screenshot type="default">
<image>https://raw.githubusercontent.com/Merrit/unit_bargain_hunter/main/assets/images/promo/promo.png</image>
</screenshot>
<screenshot>
<image>https://raw.githubusercontent.com/Merrit/unit_bargain_hunter/main/assets/images/screenshots/linux-dark1.png</image>
</screenshot>
<screenshot>
<image>https://raw.githubusercontent.com/Merrit/unit_bargain_hunter/main/assets/images/screenshots/linux-dark2.png</image>
</screenshot>
<screenshot>
<image>https://raw.githubusercontent.com/Merrit/unit_bargain_hunter/main/assets/images/screenshots/linux-light1.png</image>
</screenshot>
<screenshot>
<image>https://raw.githubusercontent.com/Merrit/unit_bargain_hunter/main/assets/images/screenshots/linux-light2.png</image>
</screenshot>
</screenshots>
<content_rating type="oars-1.1"/>
<releases>
<release version="2.8.0" date="2022-12-19">
<description>
<p>## What's Changed</p>
<p>### New Features 🎉</p>
<p>* Minimizing/restoring the window automatically is now an option</p>
<p>* Setting in the GUI</p>
<p>* CLI flag to override settings: `--no-minimize`</p>
<p>### Fixes ✨</p>
<p>* Several misc changes that should improve performance</p>
<p>* Fix "sticky" windows on Linux not showing up</p>
<p>### Code Cleanup 🪥</p>
<p>* Large amounts of code cleanup</p>
<p>* Will improve reliability and confidence when making changes and doing maintenance</p>
<p>* Large ongoing refactoring</p>
<p>* Many added unit tests</p>
</description>
</release>
</releases>
</component>
7 changes: 7 additions & 0 deletions packaging/linux/flatpak/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
`prepare-flatpak-build.sh` will update the values in the yml and xml recipe
files for the latest published release.

`build-flatpak.sh` will use flatpak-builder to construct the flatpak if invoked
manually, however it is intended to be run by the Flathub bot when these updated
files are pushed to the repo at
https://github.com/flathub/codes.merritt.Nyrna
Loading