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

AppImage package support #68

Merged
merged 4 commits into from
Jun 5, 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
7 changes: 7 additions & 0 deletions examples/hello_world/distribute_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ releases:
build_args:
dart-define:
APP_ENV: dev
- name: release-dev-appimage
package:
platform: linux
target: appimage
build_args:
dart-define:
APP_ENV: dev
17 changes: 17 additions & 0 deletions examples/hello_world/linux/packaging/appimage/make_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
appId: org.leanflutter.examples.hello_world
# icon filename without extension
# icon: logo

script:
- echo 'Running a Script'

include: []
exclude: []
# its true by default
default_excludes: true

files:
include: []
exclude: []
# its true by default
default_excludes: true
10 changes: 10 additions & 0 deletions packages/app_package_maker_appimage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build outputs.
build/

# Omit committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
3 changes: 3 additions & 0 deletions packages/app_package_maker_appimage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

- Initial version.
21 changes: 21 additions & 0 deletions packages/app_package_maker_appimage/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Kingkor Roy Tirtho <krtirtho@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions packages/app_package_maker_appimage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# app_package_maker_appimage

KRTirtho marked this conversation as resolved.
Show resolved Hide resolved
Create an AppImage for your flutter linux application.

[![pub version][pub-image]][pub-url]

[pub-image]: https://img.shields.io/pub/v/app_package_maker_appimage.svg
[pub-url]: https://pub.dev/packages/app_package_maker_appimage

---

Part of [flutter_distributor](https://github.com/leanflutter/flutter_distributor), See also https://distributor.leanflutter.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library app_package_maker_appimage;

export 'src/app_package_maker_appimage.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import 'dart:convert';
import 'dart:io';
import 'package:app_package_maker/app_package_maker.dart';
import 'make_appimage_config.dart';
import 'package:path/path.dart' as path;

class AppPackageMakerAppImage extends AppPackageMaker {
String get name => 'appimage';
String get platform => 'linux';
String get packageFormat => 'appimage';

bool get isSupportedOnCurrentPlatform => Platform.isLinux;

@override
Future<MakeConfig> loadMakeConfig(
Directory outputDirectory,
Map<String, dynamic>? makeArguments,
) async {
MakeConfig baseMakeConfig = await super.loadMakeConfig(
outputDirectory,
makeArguments,
);
final map = loadMakeConfigYaml('linux/packaging/appimage/make_config.yaml');
return MakeAppImageConfig.fromJson(map).copyWith(baseMakeConfig);
}

@override
Future<MakeResult> make(
Directory appDirectory, {
required Directory outputDirectory,
Map<String, dynamic>? makeArguments,
void Function(List<int> data)? onProcessStdOut,
void Function(List<int> data)? onProcessStdErr,
}) async {
MakeAppImageConfig makeConfig = await loadMakeConfig(
outputDirectory,
makeArguments,
) as MakeAppImageConfig;

final configFile = File("AppImageBuilder.yml");
final outputFile =
File("${makeConfig.appName}-${makeConfig.appVersion}-x86_64.AppImage");
final appDir = Directory("AppDir");
final buildDir = Directory("appimage-build");

if (!configFile.existsSync()) configFile.createSync();
// removing already used AppDir & appimage-build directories
configFile.writeAsStringSync(jsonEncode(makeConfig.toJson()));

final process = await Process.start('appimage-builder', [
"--recipe",
configFile.path,
]);

process.stdout.listen(onProcessStdOut);
process.stderr.listen(onProcessStdErr);

int exitCode = await process.exitCode;
if (exitCode != 0) {
throw MakeError();
}

// delete the config file & cleaning stuff
await configFile.delete();
await appDir.delete(recursive: true);
await buildDir.delete(recursive: true);

final outputVersionedDir = Directory(
path.join(outputDirectory.path, makeConfig.appVersion.toString()),
);

if (!outputVersionedDir.existsSync())
outputVersionedDir.createSync(recursive: true);

// move the output file to outputDirectory
await outputFile.rename(
path.join(
outputDirectory.path,
makeConfig.appVersion.toString(),
"${makeConfig.appName}-${makeConfig.appVersion}-$platform.AppImage",
),
);

return MakeResult(makeConfig);
}
}
188 changes: 188 additions & 0 deletions packages/app_package_maker_appimage/lib/src/make_appimage_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import 'package:app_package_maker/app_package_maker.dart';
import 'package:path/path.dart' as path;

/// this how the config should look like
/// appId: lol.itsanapp.question
// # relative path to icon
/// icon: assets/logo.png
// # this is the default script command
/// script:
/// - rm -rf build/AppDir || true
/// - cp -r build/linux/x64/release/bundle AppDir
/// - mkdir -p build/AppDir/usr/share/icons/hicolor/64x64/apps/
/// - cp assets/spotube-logo.png build/AppDir/usr/share/icons/hicolor/64x64/apps/
// # name of [apt] packages that should be included
/// include:
/// - libkeybinder-3.0-0
/// exclude:
// # by default following dependencies will be excluded
/// - libx11-6
/// - libgtk-3-0
/// - libglib2.0-0
/// - libc6
// # toggle for excluding those flutter system dependencies by default
// # @default (true)
/// default_excludes: true
/// files:
// # file include/exclude
/// include: []
// # by default these will be excluded
/// exclude:
/// - usr/share/man
/// - usr/share/doc/*/README.*
/// - usr/share/doc/*/changelog.*
/// - usr/share/doc/*/NEWS.*
/// - usr/share/doc/*/TODO.*
// # toggle for excluding those directories by default
// # @default (true)
/// default_excludes: true

const defaultScript = [
"rm -rf AppDir || true",
"cp -r build/linux/x64/release/bundle AppDir",
"mkdir -p AppDir/usr/share/icons/hicolor/64x64/apps/",
];

const defaultExclude = const [
"libx11-6",
"libgtk-3-0",
"libglib2.0-0",
"libc6",
];

const defaultExcludeFiles = const [
"usr/share/man",
"usr/share/doc/*/README.*",
"usr/share/doc/*/changelog.*",
"usr/share/doc/*/NEWS.*",
];

class MakeAppImageConfig extends MakeConfig {
String appId;
String? icon;
List<String> _script;
List<String> include;
List<String> _exclude;
bool default_excludes;
List<String> include_files;
List<String> _exclude_files;
bool default_excludes_files;

List<String> get script => [
...defaultScript,
if (icon != null) "cp $icon AppDir/usr/share/icons/hicolor/",
..._script
];
List<String> get exclude => [
...(default_excludes ? defaultExclude : []),
..._exclude,
];
List<String> get exclude_files => [
...(default_excludes_files ? defaultExcludeFiles : []),
..._exclude_files,
];

MakeAppImageConfig({
List<String> script = const [],
List<String> exclude = const [],
List<String> exclude_files = const [],
required this.appId,
required this.include,
required this.include_files,
this.icon,
this.default_excludes = true,
this.default_excludes_files = true,
}) : _script = script,
_exclude = exclude,
_exclude_files = exclude_files;

factory MakeAppImageConfig.fromJson(Map<String, dynamic> map) {
return MakeAppImageConfig(
appId: map['appId'],
icon: map['icon'],
script: List.castFrom<dynamic, String>(map['script'] ?? []),
include: List.castFrom<dynamic, String>(map['include'] ?? []),
exclude: List.castFrom<dynamic, String>(map['exclude'] ?? []),
default_excludes: map['default_excludes'] ?? true,
include_files:
List.castFrom<dynamic, String>(map['files']?['include'] ?? []),
exclude_files:
List.castFrom<dynamic, String>(map['files']?['exclude'] ?? []),
default_excludes_files: map['files']?['default_excludes'] ?? false,
);
}

Map<String, dynamic> toJson() {
return {
"version": 1,
"script": script,
"AppDir": {
"path": "AppDir",
"app_info": {
"id": appId,
if (icon != null) "icon": path.basenameWithoutExtension(icon!),
"name": appName,
"version": appVersion.toString(),
"exec": appName,
"exec_args": "\$@",
},
"apt": {
"arch": "amd64",
"allow_unauthenticated": true,
"sources": [
{
"sourceline":
"deb http://archive.ubuntu.com/ubuntu/ hirsute main restricted"
},
{
"sourceline":
"deb http://archive.ubuntu.com/ubuntu/ hirsute-updates main restricted"
},
{
"sourceline":
"deb http://archive.ubuntu.com/ubuntu/ hirsute universe"
},
{
"sourceline":
"deb http://archive.ubuntu.com/ubuntu/ hirsute-updates universe"
},
{
"sourceline":
"deb http://archive.ubuntu.com/ubuntu/ hirsute multiverse"
},
{
"sourceline":
"deb http://archive.ubuntu.com/ubuntu/ hirsute-updates multiverse"
},
{
"sourceline":
"deb http://archive.ubuntu.com/ubuntu/ hirsute-backports main restricted universe multiverse"
},
{
"sourceline":
"deb http://security.ubuntu.com/ubuntu hirsute-security main restricted"
},
{
"sourceline":
"deb http://security.ubuntu.com/ubuntu hirsute-security universe"
},
{
"sourceline":
"deb http://security.ubuntu.com/ubuntu hirsute-security multiverse"
},
],
"include": include,
"exclude": exclude,
},
"files": {
"include": include_files,
"exclude": exclude_files,
},
},
"AppImage": {
"arch": "x86_64",
"update-information": "guess",
}
}..removeWhere((key, value) => value == null);
}
}
10 changes: 10 additions & 0 deletions packages/app_package_maker_appimage/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: app_package_maker_appimage
description: A starting point for Dart libraries or applications.
version: 0.0.1

environment:
sdk: ">=2.12.0 <3.0.0"

dependencies:
app_package_maker: ^0.2.1
path: ^1.8.1
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import 'package:app_package_maker_exe/app_package_maker_exe.dart';
import 'package:app_package_maker_ipa/app_package_maker_ipa.dart';
import 'package:app_package_maker_msix/app_package_maker_msix.dart';
import 'package:app_package_maker_zip/app_package_maker_zip.dart';
import 'package:app_package_maker_appimage/app_package_maker_appimage.dart';

class FlutterAppPackager {
final List<AppPackageMaker> _makers = [
AppPackageMakerAab(),
AppPackageMakerApk(),
AppPackageMakerAppImage(),
AppPackageMakerDeb(),
AppPackageMakerDmg(),
AppPackageMakerExe(),
Expand Down
7 changes: 7 additions & 0 deletions packages/flutter_app_packager/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ packages:
relative: true
source: path
version: "0.2.1"
app_package_maker_appimage:
dependency: "direct main"
description:
path: "../app_package_maker_appimage"
relative: true
source: path
version: "0.0.1"
app_package_maker_deb:
dependency: "direct main"
description:
Expand Down
Loading