Skip to content

Commit

Permalink
Add option to install snapd and snap software center for snaps #135
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean28518 committed Mar 7, 2024
1 parent 4b353cd commit e839c56
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/content/basic_entries.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:linux_assistant/enums/desktops.dart';
import 'package:linux_assistant/enums/distros.dart';
import 'package:linux_assistant/enums/softwareManagers.dart';
import 'package:linux_assistant/layouts/mint_y.dart';
import 'package:linux_assistant/main.dart';
import 'package:linux_assistant/models/action_entry.dart';
Expand Down Expand Up @@ -163,5 +164,19 @@ List<ActionEntry> getBasicEntries(BuildContext context) {
iconWidget: Icon(Icons.bug_report, size: 48, color: MintY.currentColor),
keywords: ["fix", "package", "manager", "apt", "dpkg", "rpm", "zypper"],
),
ActionEntry(
name: AppLocalizations.of(context)!.setupSnap,
description: AppLocalizations.of(context)!.setupSnapDescription,
action: "setup_snap",
iconWidget: Icon(
Icons.apps,
size: 48,
color: MintY.currentColor,
),
disableEntryIf: () {
return Linux.currentenvironment.installedSoftwareManagers
.contains(SOFTWARE_MANAGERS.SNAP);
},
),
];
}
2 changes: 2 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
"fixPackageManager": "Paketverwaltung reparieren",
"fixPackageManagerDescription": "Updates oder Installationen können nicht mehr durchgeführt werden? Versuche die automatische Reparatur der Paketverwaltung.",
"executeInTerminal": "In Terminal ausführen",
"setupSnap": "Snap einrichten",
"setupSnapDescription": "Installiere Snap und den Snap-Store, um viele weitere Anwendungen zu installieren.\nDanach ist ein Neustart des Rechners empfohlen.",
"@helloWorld": {
"placeholders": {},
"description": "",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
"fixPackageManager": "Repair package management",
"fixPackageManagerDescription": "Updates or installations can no longer be carried out? Try the automatic repair of the package management.",
"executeInTerminal": "Execute in terminal",
"setupSnap": "Set up Snap",
"setupSnapDescription": "Install Snap and the Snap Store to install many more applications.\nAfterwards a restart of the computer is recommended.",
"@helloWorld": {
"placeholders": {},
"description": "The conventional newborn programmer greeting",
Expand Down
4 changes: 4 additions & 0 deletions lib/services/action_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -374,5 +374,9 @@ class ActionHandler {
Linux.openCommandInTerminal(command);
callback();
}

if (actionEntry.action.startsWith("setup_snap")) {
Linux.setupSnapAndSnapStore(context);
}
}
}
48 changes: 48 additions & 0 deletions lib/services/linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2339,4 +2339,52 @@ class Linux {
}
}
}

static void setupSnapAndSnapStore(context) {
if (currentenvironment.distribution == DISTROS.LINUX_MINT) {
commandQueue.add(LinuxCommand(
userId: 0,
command: "rm /etc/apt/preferences.d/nosnap.pref",
));
commandQueue.add(LinuxCommand(
userId: 0,
command: "/usr/bin/apt-get update",
));
}

if (currentenvironment.installedSoftwareManagers
.contains(SOFTWARE_MANAGERS.APT)) {
commandQueue.add(LinuxCommand(
userId: 0,
command: "/usr/bin/apt-get install -y snapd",
environment: {"DEBIAN_FRONTEND": "noninteractive"},
));
}
if (currentenvironment.installedSoftwareManagers
.contains(SOFTWARE_MANAGERS.DNF)) {
commandQueue.add(LinuxCommand(
userId: 0,
command: "/usr/bin/dnf install -y snapd",
));
}
if (currentenvironment.installedSoftwareManagers
.contains(SOFTWARE_MANAGERS.ZYPPER)) {
commandQueue.add(LinuxCommand(
userId: 0,
command: "/usr/bin/zypper install -y snapd",
));
}

commandQueue.add(LinuxCommand(
userId: 0,
command: "/usr/bin/snap install snap-store",
));

Navigator.of(context).push(MaterialPageRoute(
builder: (context) => RunCommandQueue(
title: AppLocalizations.of(context)!.setupSnap,
message: AppLocalizations.of(context)!.setupSnapDescription,
route: MainSearchLoader()),
));
}
}

0 comments on commit e839c56

Please sign in to comment.