Skip to content

Commit

Permalink
feat: handle images with no usr/share/icons directory to use the icon…
Browse files Browse the repository at this point in the history
… in the top-level folder
  • Loading branch information
tdiam committed Oct 21, 2023
1 parent 43b4a7b commit ea2d873
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions 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,11 +63,14 @@ class AppimageToolsRepository {
String desktopfilename =
'aip_' + p.basenameWithoutExtension(newPath) + ".desktop";

String? desktopBasename;

// Copy desktop file
try {
var desktopFile = Directory(squashDir)
.listSync()
.firstWhere((element) => p.extension(element.path) == ".desktop");
desktopBasename = p.basenameWithoutExtension(desktopFile.path);
await desktopFile
.moveFile(_localPathService.applicationsDir + desktopfilename);
String execPath = (await Process.run(
Expand Down Expand Up @@ -139,6 +143,33 @@ class AppimageToolsRepository {
["-r", "./usr/share/icons", localShareDir],
workingDirectory: squashDir,
));
} else if (desktopBasename != 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) == desktopBasename
&& ['.png', '.svg', '.xpm'].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'
);
}

var iconData = await decodeImageFromList(icon.readAsBytesSync());
int iconSize = iconData.height;
var iconFilename = "aip_${desktopBasename}_$checksum" + p.extension(icon.path);
icon.moveResolvedFile(
localShareDir + "/icons/hicolor/${iconSize}x${iconSize}/apps/${iconFilename}"
);
}
} catch (e) {
debugPrint("$e");
}
}

Directory(tempDir).delete(recursive: true);
Expand Down

0 comments on commit ea2d873

Please sign in to comment.