feat(flatpak): install packages from a Flatpak file

Dragging a .flatpakref, .flatpakrepo or .flatpak onto the window, or
opening it with the file manager, has to reach flatpak without the user
going through a search. The provider now owns its formats: it claims the
files it handles and builds the matching command, and the core routes the
request to whichever provider recognises it, so a new provider can claim
its own formats the same way.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
BlackAngelTV committed 2026-09-27 19:39:39 +02:00
1 parent d44dbc3ccf
commit 1e751c7205
9 files changed
+381 -5

No files matched your search

+69
View File
@@ -85,6 +85,71 @@ static void testParseUpdatesOutput_emptyInput() {
assert(FlatpakManager::parseUpdatesOutput("").empty());
}
// ---- Installing from a file (drag & drop, "Ouvrir avec PacManager") ----
static void testClassifyFile_recognisesTheThreeFlatpakFormats() {
using FileKind = FlatpakManager::FileKind;
assert(FlatpakManager::classifyFile("/home/jane/Téléchargements/org.gnome.Dictionary.flatpakref")
== FileKind::Ref);
assert(FlatpakManager::classifyFile("flathub.flatpakrepo") == FileKind::Repo);
assert(FlatpakManager::classifyFile("/tmp/app.flatpak") == FileKind::Bundle);
// A bundle's extension starts like a ref one's, so it must not be read as
// a .flatpakref by accident.
assert(FlatpakManager::classifyFile("/tmp/Org.App.flatpak") != FileKind::Ref);
// Case and an URL query string do not change the format.
assert(FlatpakManager::classifyFile("https://flathub.org/repo/appstream/x.FLATPAKREF")
== FileKind::Ref);
assert(FlatpakManager::classifyFile("https://example.org/app.flatpakref?v=2")
== FileKind::Ref);
// Anything else is not ours: a pacman package, a directory named after the
// format, or a plain document.
assert(FlatpakManager::classifyFile("/tmp/firefox.pkg.tar.zst") == FileKind::None);
assert(FlatpakManager::classifyFile("/tmp/flatpak") == FileKind::None);
assert(FlatpakManager::classifyFile("") == FileKind::None);
}
static void testRepoName_comesFromTheFileName() {
assert(FlatpakManager::repoNamespace("flathub.flatpakrepo") == "flathub");
assert(FlatpakManager::repoNamespace("/tmp/My-Repo.FlatpakRepo") == "my-repo");
// A nameless path still has to register a remote under some name.
assert(!FlatpakManager::repoNamespace("").empty());
}
static void testInstallFileCommand_buildsTheFlatpakCalls() {
using FileKind = FlatpakManager::FileKind;
// A ref file or bundle is handed to `flatpak install`, non-interactively so
// a dropped file cannot open a prompt nobody is looking at.
const std::string ref = FlatpakManager::installFileCommand(
FileKind::Ref, "/tmp/org.gnome.Dictionary.flatpakref");
assert(ref.find("flatpak install") == 0);
assert(ref.find("--noninteractive") != std::string::npos);
assert(ref.find("--assumeyes") != std::string::npos);
assert(ref.find("/tmp/org.gnome.Dictionary.flatpakref") != std::string::npos);
assert(ref.find("--user") == std::string::npos);
// The per-user retry (polkit refused, no admin rights) adds --user.
const std::string userRef = FlatpakManager::installFileCommand(
FileKind::Ref, "/tmp/org.gnome.Dictionary.flatpakref", /*userScope=*/true);
assert(userRef.find("--user") != std::string::npos);
// A .flatpakrepo registers the remote under the file's name instead.
const std::string repo = FlatpakManager::installFileCommand(
FileKind::Repo, "/tmp/flathub.flatpakrepo", /*userScope=*/true);
assert(repo.find("flatpak remote-add") == 0);
assert(repo.find("--if-not-exists") != std::string::npos);
assert(repo.find("flathub ") != std::string::npos);
assert(repo.find("/tmp/flathub.flatpakrepo") != std::string::npos);
// A path with spaces stays a single argument.
const std::string quoted = FlatpakManager::installFileCommand(
FileKind::Bundle, "/tmp/mon paquet.flatpak");
assert(quoted.find("'/tmp/mon paquet.flatpak'") != std::string::npos);
}
int main() {
testParseSearchOutput_parsesAlignedRows();
testParseSearchOutput_keepsMultiWordDescriptions();
@@ -97,6 +162,10 @@ int main() {
testParseUpdatesOutput_parsesRows();
testParseUpdatesOutput_emptyInput();
testClassifyFile_recognisesTheThreeFlatpakFormats();
testRepoName_comesFromTheFileName();
testInstallFileCommand_buildsTheFlatpakCalls();
std::cout << "All flatpak-manager tests passed." << std::endl;
return 0;
}