Skip to content

Commit

Permalink
Rework flatpak installation because of dead flathub v1 api
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean 28518 committed Dec 18, 2024
1 parent 241f85f commit 108b5a6
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 81 deletions.
7 changes: 7 additions & 0 deletions lib/layouts/main_screen/main_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@ class _MainSearchState extends State<MainSearch> {
heavyEntries.addAll(snaps);
}

if (Linux.currentenvironment.installedSoftwareManagers
.contains(SOFTWARE_MANAGERS.FLATPAK)) {
List<ActionEntry> flatpaks =
await Linux.getInstallableFlatpakPackagesForKeyword(keyword);
heavyEntries.addAll(flatpaks);
}

if (Linux.currentenvironment.installedSoftwareManagers
.contains(SOFTWARE_MANAGERS.PACMAN)) {
List<ActionEntry> pacmanEntries =
Expand Down
102 changes: 57 additions & 45 deletions lib/services/linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,16 @@ class Linux {
if ((softwareManager == null ||
softwareManager == SOFTWARE_MANAGERS.FLATPAK) &&
isFlatpakInstalled) {
commandQueue.add(
LinuxCommand(
userId: currentenvironment.currentUserId,
command:
"${getExecutablePathOfSoftwareManager(SOFTWARE_MANAGERS.FLATPAK)} remove $appCode -y --noninteractive",
),
);
commandQueue.add(LinuxCommand(
userId: currentenvironment.currentUserId,
command:
"${getExecutablePathOfSoftwareManager(SOFTWARE_MANAGERS.FLATPAK)} remove $appCode -y --noninteractive",
));
commandQueue.add(LinuxCommand(
userId: 0,
command:
"${getExecutablePathOfSoftwareManager(SOFTWARE_MANAGERS.FLATPAK)} uninstall $appCode -y --noninteractive --system",
));
}
}

Expand Down Expand Up @@ -1484,6 +1487,53 @@ class Linux {
return results;
}

static Future<List<ActionEntry>> getInstallableFlatpakPackagesForKeyword(
String keyword) async {
if (keyword.length <= 3) {
return [];
}
String output = await runCommandWithCustomArguments(
getExecutablePathOfSoftwareManager(SOFTWARE_MANAGERS.FLATPAK),
["search", keyword, "--columns=application,name,description"]);
output = output.trim();
List<String> lines = output.split("\n");

if (output.contains("No matches found")) {
return [];
}

print(output);
print(lines.length);

if (lines.length > 100) {
return [];
}

List<ActionEntry> results = [];
for (String line in lines) {
List<String> lineParts = line.split("\t");
if (lineParts.length < 3) {
continue;
}
String appID = lineParts[0].trim();
String appName = lineParts[1].trim();
String appDescription = lineParts[2].trim();
results.add(ActionEntry(
iconWidget: Icon(
Icons.archive,
size: 48,
color: MintY.currentColor,
),
name: "Install $appName (Flatpak)",
description: appDescription,
action: "flatpak-install:$appID",
priority: -20,
));
}

return results;
}

/// Only returns results if keyword is longer than 3 and there are under 100 results.
static Future<List<ActionEntry>> getInstallableZypperPackagesForKeyword(
String keyword) async {
Expand Down Expand Up @@ -2179,44 +2229,6 @@ class Linux {
Linux.runCommand("/sbin/shutdown $minutes");
}

static Future<List<ActionEntry>> getAvailableFlatpaks(
BuildContext context) async {
String homeDir = Linux.getHomeDirectory();

List<ActionEntry> returnValue = [];
try {
String installedFlatpaks = await Linux.runCommandWithCustomArguments(
"/usr/bin/flatpak", ["list", "--app", "--columns=application"]);

File flathubIndexFile =
File("$homeDir.config/linux-assistant/flathub_index.json");
List<dynamic> responseMap =
json.decode(flathubIndexFile.readAsStringSync());
for (Map<String, dynamic> app in responseMap) {
if (!installedFlatpaks
.contains(app["flatpakAppId"].toString().trim())) {
ActionEntry entry = ActionEntry(
name: AppLocalizations.of(context)!
.installX("${app["name"]} (Flatpak)"),
description: app["summary"],
action: "flatpak-install:${app["flatpakAppId"]}",
priority: -19.0,
iconWidget: Icon(
Icons.archive_rounded,
size: 48,
color: MintY.currentColor,
),
excludeFromSearchProposal: true,
);
returnValue.add(entry);
}
}
} catch (e) {
print(e.toString());
}
return returnValue;
}

static Future<String> getUsername() async {
final int id = currentenvironment.currentUserId;
return (await runCommand("id -nu $id")).trim();
Expand Down
7 changes: 0 additions & 7 deletions lib/services/main_search_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ class _MainSearchLoaderState extends State<MainSearchLoader> {
_onTimeoutOfSearchLoadingModule("browserBookmarks")));
}

// Flatpak Index Installations
if (configHandler.getValueUnsafe("search_filter_install_software", true)) {
print("Loading flatpaks");
futures.add(Linux.getAvailableFlatpaks(context).timeout(timeoutDuration,
onTimeout: () => _onTimeoutOfSearchLoadingModule("flatpaks")));
}

// Deinstallation Entries.
if (configHandler.getValueUnsafe(
"search_filter_uninstall_software", true)) {
Expand Down
78 changes: 51 additions & 27 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.19.0"
crypto:
dependency: "direct main"
description:
Expand Down Expand Up @@ -77,10 +77,10 @@ packages:
dependency: "direct main"
description:
name: fl_chart
sha256: "749b3342ea3e95cbf61a0fec31a62606e837377b8b6d0caa7367a7ef80f38b7d"
sha256: "5a74434cc83bf64346efb562f1a06eefaf1bcb530dc3d96a104f631a1eff8d79"
url: "https://pub.dev"
source: hosted
version: "0.55.2"
version: "0.65.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -161,10 +161,34 @@ packages:
dependency: "direct main"
description:
name: intl
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
url: "https://pub.dev"
source: hosted
version: "0.18.1"
version: "0.19.0"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06"
url: "https://pub.dev"
source: hosted
version: "10.0.7"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379"
url: "https://pub.dev"
source: hosted
version: "3.0.8"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
lints:
dependency: transitive
description:
Expand All @@ -185,34 +209,34 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.15.0"
path:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
path_parsing:
dependency: transitive
description:
Expand Down Expand Up @@ -241,7 +265,7 @@ packages:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
version: "0.0.0"
source_span:
dependency: transitive
description:
Expand All @@ -254,10 +278,10 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
url: "https://pub.dev"
source: hosted
version: "1.11.1"
version: "1.12.0"
stream_channel:
dependency: transitive
description:
Expand All @@ -270,10 +294,10 @@ packages:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.3.0"
term_glyph:
dependency: transitive
description:
Expand All @@ -286,10 +310,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
url: "https://pub.dev"
source: hosted
version: "0.6.1"
version: "0.7.3"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -338,14 +362,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
vm_service:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
name: vm_service
sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b
url: "https://pub.dev"
source: hosted
version: "0.3.0"
version: "14.3.0"
window_manager:
dependency: "direct main"
description:
Expand All @@ -363,5 +387,5 @@ packages:
source: hosted
version: "6.3.0"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.7.0-0"
dart: ">=3.4.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ dependencies:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: ^0.18.0
intl: ^0.19.0


# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
fl_chart: ^0.55.0
fl_chart: ^0.65.0
flutter_svg_provider: ^1.0.3
hotkey_manager: ^0.1.7
window_manager: ^0.3.1
Expand Down

0 comments on commit 108b5a6

Please sign in to comment.