Skip to content

Commit

Permalink
Merge pull request #112 from tdiam/tdiam/handle-toplevel-icon
Browse files Browse the repository at this point in the history
Handle AppImages with icon only in root directory
  • Loading branch information
prateekmedia authored Oct 23, 2023
2 parents 58a027b + bf62823 commit 42b3811
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
40 changes: 39 additions & 1 deletion lib/src/features/home/data/appimage_tools_repository.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'dart:ui';

import 'package:appimagepool/src/features/home/data/local_path_provider.dart';
import 'package:appimagepool/src/constants/constants.dart';
Expand Down Expand Up @@ -62,6 +63,8 @@ class AppimageToolsRepository {
String desktopfilename =
'aip_' + p.basenameWithoutExtension(newPath) + ".desktop";

String? iconName;

// Copy desktop file
try {
var desktopFile = Directory(squashDir)
Expand All @@ -83,7 +86,7 @@ class AppimageToolsRepository {
.split(' ')[0]
.trim();

String iconName = (await Process.run(
iconName = (await Process.run(
"grep",
[
"^Icon=",
Expand Down Expand Up @@ -139,6 +142,41 @@ class AppimageToolsRepository {
["-r", "./usr/share/icons", localShareDir],
workingDirectory: squashDir,
));
} else if (iconName != null) {
// No icons in {squashDir}/usr/share/icons, search in top-level folder
try {
var icon = Directory(squashDir)
.listSync()
.firstWhere((element) =>
p.basenameWithoutExtension(element.path) == iconName
&& ['.png', '.svg'].contains(p.extension(element.path))
);

if (icon is File) {
if (!icon.resolveSymbolicLinksSync().startsWith(squashDir + "/")) {
throw FileSystemException(
'Symlink for icon points out of the AppDir boundary'
);
}

String sizeName;
String iconExt = p.extension(icon.path);
if (iconExt == '.png') {
var iconData = await decodeImageFromList(icon.readAsBytesSync());
int iconSize = iconData.height;
sizeName = "${iconSize}x${iconSize}";
} else {
sizeName = "scalable";
}

var iconFilename = "aip_${iconName}_${checksum}${iconExt}";
icon.moveResolvedFile(
localShareDir + "/icons/hicolor/${sizeName}/apps/${iconFilename}"
);
}
} catch (e) {
debugPrint("$e");
}
}

Directory(tempDir).delete(recursive: true);
Expand Down
5 changes: 5 additions & 0 deletions lib/src/utils/extensions/file_move.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ extension FileMoveExt on FileSystemEntity {
return newFile;
}
}

Future moveResolvedFile(String newPath) async {
final resolvedFile = File(toFile.resolveSymbolicLinksSync());
return await resolvedFile.moveFile(newPath);
}
}

0 comments on commit 42b3811

Please sign in to comment.