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

Revamp the linUX #224

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';

import 'package:flutter_app_packager/src/api/app_package_maker.dart';
import 'package:flutter_app_packager/src/makers/appimage/make_appimage_config.dart';
import 'package:image/image.dart' as img;
import 'package:path/path.dart' as path;
import 'package:shell_executor/shell_executor.dart';

Expand Down Expand Up @@ -116,38 +117,28 @@ class AppPackageMakerAppImage extends AppPackageMaker {
),
);

final icon256x256 = path.join(
makeConfig.packagingDirectory.path,
'${makeConfig.appName}.AppDir/usr/share/icons/hicolor/256x256/apps',
);
final icon128x128 = path.join(
makeConfig.packagingDirectory.path,
'${makeConfig.appName}.AppDir/usr/share/icons/hicolor/128x128/apps',
);
for (final size in [128, 256, 512]) {
final iconDir = path.join(
makeConfig.packagingDirectory.path,
'${makeConfig.appName}.AppDir/usr/share/icons/hicolor/${size}x$size/apps',
);
final mkdirProcessRes = await $('mkdir', [
'-p',
iconDir,
]);

await $('mkdir', [
'-p',
icon128x128,
icon256x256,
]).then((value) {
if (value.exitCode != 0) {
throw MakeError(value.stderr as String);
}
});
if (mkdirProcessRes.exitCode != 0) throw MakeError();

await iconFile.copy(
path.join(
icon128x128,
'${makeConfig.appName}${path.extension(makeConfig.icon)}',
),
);

await iconFile.copy(
path.join(
icon256x256,
'${makeConfig.appName}${path.extension(makeConfig.icon)}',
),
);
final icon = img.copyResize(
img.decodeImage(iconFile.readAsBytesSync())!,
width: size,
height: size,
interpolation: img.Interpolation.average,
);
final newIconFile =
File(path.join(iconDir, '${makeConfig.appBinaryName}.png'));
await newIconFile.writeAsBytes(img.encodePng(icon));
}

if (makeConfig.metainfo != null) {
final metainfoDir = path.join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AppImageAction {

class MakeAppImageConfig extends MakeConfig {
MakeAppImageConfig({
this.packageName,
required this.displayName,
required this.icon,
this.keywords = const [],
Expand All @@ -45,6 +46,7 @@ class MakeAppImageConfig extends MakeConfig {
});
factory MakeAppImageConfig.fromJson(Map<String, dynamic> map) {
return MakeAppImageConfig(
packageName: map['package_name'] as String?,
displayName: map['display_name'] as String,
icon: map['icon'] as String,
metainfo: map['metainfo'] as String?,
Expand All @@ -66,13 +68,17 @@ class MakeAppImageConfig extends MakeConfig {
);
}

@override
String get appName => packageName ?? super.appName;

final String icon;
final String? metainfo;
final List<String> keywords;
final List<String> categories;
final List<AppImageAction> actions;
final bool startupNotify;
final String genericName;
final String? packageName;
final String displayName;
final List<String> include;
List<String>? supportedMimeType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';

import 'package:flutter_app_packager/src/api/app_package_maker.dart';
import 'package:flutter_app_packager/src/makers/deb/make_deb_config.dart';
import 'package:image/image.dart' as img;
import 'package:path/path.dart' as path;
import 'package:shell_executor/shell_executor.dart';

Expand Down Expand Up @@ -46,18 +47,11 @@ class AppPackageMakerDeb extends AppPackageMaker {
/// /usr/share/applications
/// /usr/share/icons/hicolor/128x128/apps
/// /usr/share/icons/hicolor/256x256/apps
/// /usr/share/icons/hicolor/512x512/apps

final debianDir = path.join(packagingDirectory.path, 'DEBIAN');
final applicationsDir =
path.join(packagingDirectory.path, 'usr/share/applications');
final icon128Dir = path.join(
packagingDirectory.path,
'usr/share/icons/hicolor/128x128/apps',
);
final icon256Dir = path.join(
packagingDirectory.path,
'usr/share/icons/hicolor/256x256/apps',
);
final metainfoDir =
path.join(packagingDirectory.path, 'usr/share/metainfo');
final mkdirProcessResult = await $('mkdir', [
Expand All @@ -66,7 +60,6 @@ class AppPackageMakerDeb extends AppPackageMaker {
path.join(packagingDirectory.path, 'usr/share', makeConfig.appBinaryName),
applicationsDir,
if (makeConfig.metainfo != null) metainfoDir,
if (makeConfig.icon != null) ...[icon128Dir, icon256Dir],
]);

if (mkdirProcessResult.exitCode != 0) throw MakeError();
Expand All @@ -77,18 +70,28 @@ class AppPackageMakerDeb extends AppPackageMaker {
throw MakeError("provided icon ${makeConfig.icon} path wasn't found");
}

await iconFile.copy(
path.join(
icon128Dir,
makeConfig.appBinaryName + path.extension(makeConfig.icon!),
),
);
await iconFile.copy(
path.join(
icon256Dir,
makeConfig.appBinaryName + path.extension(makeConfig.icon!),
),
);
for (final size in [128, 256, 512]) {
final iconDir = path.join(
packagingDirectory.path,
'usr/share/icons/hicolor/${size}x$size/apps',
);
final mkdirProcessRes = await $('mkdir', [
'-p',
iconDir,
]);

if (mkdirProcessRes.exitCode != 0) throw MakeError();

final icon = img.copyResize(
img.decodeImage(iconFile.readAsBytesSync())!,
width: size,
height: size,
interpolation: img.Interpolation.average,
);
final newIconFile =
File(path.join(iconDir, '${makeConfig.appBinaryName}.png'));
await newIconFile.writeAsBytes(img.encodePng(icon));
}
}
if (makeConfig.metainfo != null) {
final metainfoPath =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter_app_packager/src/api/app_package_maker.dart';
# the name used to display in the OS. Specifically desktop
# entry name
display_name: Hola Amigos
include_build_number: true

# package name for debian/apt repository
# the name should be all lowercase with -+.
Expand Down Expand Up @@ -126,6 +127,7 @@ class MakeDebConfig extends MakeLinuxPackageConfig {
required this.installedSize,
required this.maintainer,
this.startupNotify = true,
this.includeBuildNumber = true,
this.essential = false,
List<String>? postinstallScripts,
List<String>? postuninstallScripts,
Expand Down Expand Up @@ -155,6 +157,7 @@ class MakeDebConfig extends MakeLinuxPackageConfig {

factory MakeDebConfig.fromJson(Map<String, dynamic> map) {
return MakeDebConfig(
includeBuildNumber: map['include_build_number'] as bool? ?? true,
displayName: map['display_name'],
packageName: map['package_name'],
maintainer:
Expand Down Expand Up @@ -224,6 +227,7 @@ class MakeDebConfig extends MakeLinuxPackageConfig {
);
}

bool includeBuildNumber;
String displayName;
String packageName;
String maintainer;
Expand Down Expand Up @@ -271,7 +275,7 @@ class MakeDebConfig extends MakeLinuxPackageConfig {
'CONTROL': {
'Maintainer': maintainer,
'Package': packageName,
'Version': appVersion.toString(),
'Version': includeBuildNumber ? appVersion.toString() : appBuildName,
'Section': section,
'Priority': priority,
'Architecture': _getArchitecture(),
Expand All @@ -295,7 +299,6 @@ class MakeDebConfig extends MakeLinuxPackageConfig {
}..removeWhere((key, value) => value == null),
'DESKTOP': {
'Type': 'Application',
'Version': appVersion.toString(),
'Name': displayName,
'GenericName': genericName,
'Icon': appBinaryName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:path/path.dart' as p;

class MakeExeConfig extends MakeConfig {
MakeExeConfig({
this.packageName,
this.scriptTemplate,
required this.appId,
this.executableName,
Expand All @@ -27,6 +28,7 @@ class MakeExeConfig extends MakeConfig {
MakeExeConfig makeExeConfig = MakeExeConfig(
scriptTemplate: json['script_template'],
appId: json['app_id'] ?? json['appId'],
packageName: json['package_name'],
executableName: json['executable_name'],
displayName: json['display_name'],
publisherName: json['publisher_name'] ?? json['appPublisher'],
Expand All @@ -41,6 +43,10 @@ class MakeExeConfig extends MakeConfig {
return makeExeConfig;
}

@override
String get appName => packageName ?? super.appName;

String? packageName;
String? scriptTemplate;
final String appId;
String? executableName;
Expand Down Expand Up @@ -76,6 +82,7 @@ class MakeExeConfig extends MakeConfig {
'app_id': appId,
'app_name': appName,
'app_version': appVersion.toString(),
'package_name': packageName,
'executable_name': executableName,
'display_name': displayName,
'publisher_name': publisherName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';

import 'package:flutter_app_packager/src/api/app_package_maker.dart';
import 'package:flutter_app_packager/src/makers/pacman/make_pacman_config.dart';
import 'package:image/image.dart' as img;
import 'package:path/path.dart' as path;
import 'package:shell_executor/shell_executor.dart';

Expand Down Expand Up @@ -48,22 +49,14 @@ class AppPackageMakerPacman extends AppPackageMaker {

final applicationsDir =
path.join(packagingDirectory.path, 'usr/share/applications');
final icon128Dir = path.join(
packagingDirectory.path,
'usr/share/icons/hicolor/128x128/apps',
);
final icon256Dir = path.join(
packagingDirectory.path,
'usr/share/icons/hicolor/256x256/apps',
);

final metainfoDir =
path.join(packagingDirectory.path, 'usr/share/metainfo');
final mkdirProcessResult = await $('mkdir', [
'-p',
path.join(packagingDirectory.path, 'usr/share', makeConfig.appBinaryName),
applicationsDir,
if (makeConfig.metainfo != null) metainfoDir,
if (makeConfig.icon != null) ...[icon128Dir, icon256Dir],
]);

if (mkdirProcessResult.exitCode != 0) throw MakeError();
Expand All @@ -74,18 +67,28 @@ class AppPackageMakerPacman extends AppPackageMaker {
throw MakeError("provided icon ${makeConfig.icon} path wasn't found");
}

await iconFile.copy(
path.join(
icon128Dir,
makeConfig.appBinaryName + path.extension(makeConfig.icon!),
),
);
await iconFile.copy(
path.join(
icon256Dir,
makeConfig.appBinaryName + path.extension(makeConfig.icon!),
),
);
for (final size in [128, 256, 512]) {
final iconDir = path.join(
packagingDirectory.path,
'usr/share/icons/hicolor/${size}x$size/apps',
);
final mkdirProcessRes = await $('mkdir', [
'-p',
iconDir,
]);

if (mkdirProcessRes.exitCode != 0) throw MakeError();

final icon = img.copyResize(
img.decodeImage(iconFile.readAsBytesSync())!,
width: size,
height: size,
interpolation: img.Interpolation.average,
);
final newIconFile =
File(path.join(iconDir, '${makeConfig.appBinaryName}.png'));
await newIconFile.writeAsBytes(img.encodePng(icon));
}
}
if (makeConfig.metainfo != null) {
final metainfoPath =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class MakePacmanConfig extends MakeLinuxPackageConfig {
factory MakePacmanConfig.fromJson(Map<String, dynamic> map) {
return MakePacmanConfig(
displayName: map['display_name'],
packageName: map['package_name'], //
packageName: map['package_name'],
packageRelease: int.tryParse(map['package_release'] ?? '1') ?? 1,
maintainer:
"${map['maintainer']['name']} <${map['maintainer']['email']}>",
Expand Down Expand Up @@ -246,7 +246,6 @@ class MakePacmanConfig extends MakeLinuxPackageConfig {
}..removeWhere((key, value) => value == null),
'DESKTOP': {
'Type': 'Application',
'Version': appVersion.toString(),
'Name': displayName,
'GenericName': genericName,
'Icon': appBinaryName,
Expand Down
Loading
Loading