-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from KRTirtho/main
AppImage package support
- Loading branch information
Showing
14 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
examples/hello_world/linux/packaging/appimage/make_config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.0.1 | ||
|
||
- Initial version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# app_package_maker_appimage | ||
|
||
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 |
3 changes: 3 additions & 0 deletions
3
packages/app_package_maker_appimage/lib/app_package_maker_appimage.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
86 changes: 86 additions & 0 deletions
86
packages/app_package_maker_appimage/lib/src/app_package_maker_appimage.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
188
packages/app_package_maker_appimage/lib/src/make_appimage_config.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.