Skip to content

Commit

Permalink
Add option on debian to fix sources.list file #157
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean28518 committed Apr 14, 2024
1 parent e69e45a commit d55e806
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 11 deletions.
11 changes: 11 additions & 0 deletions lib/content/basic_entries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,16 @@ List<ActionEntry> getBasicEntries(BuildContext context) {
color: MintY.currentColor,
),
),
ActionEntry(
name: AppLocalizations.of(context)!.disableCdromSource,
description: AppLocalizations.of(context)!.disableCdromSourceDescription,
iconWidget: Icon(Icons.album, size: 48, color: MintY.currentColor),
disableEntryIf: () {
return !Linux.isCdromSourceEnabledInDebian();
},
handlerFunction: (VoidCallback callback, BuildContext context) {
Linux.disableCdromSourceInDebian(context);
},
),
];
}
2 changes: 2 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@
"yayInstalled": "Es wurde Yay gefunden. Yay ist ein AUR-Helper, der Dir das Installieren von AUR-Paketen erleichtert. Das AUR ist ein Community-Repository, in dem viele Pakete von der Community gepflegt werden und eventuell schädlich sein könnten.",
"openSoftwareCenter": "Öffne Software-Center",
"openSoftwareCenterDescription": "Öffne das Software-Center, um weitere Anwendungen/Apps zu installieren.",
"disableCdromSource": "Deaktiviere CD-ROM-Quelle",
"disableCdromSourceDescription": "Ein Relikt der Debian-Installation. Deaktiviere die CDROM-Quelle, um Fehlermeldungen zu vermeiden.",
"@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 @@ -348,6 +348,8 @@
"yayInstalled": "Yay was found. Yay is an AUR helper that makes it easier for you to install AUR packages. The AUR is a community repository where many packages are maintained by the community and could be potentially harmful.",
"openSoftwareCenter": "Open Software Center",
"openSoftwareCenterDescription": "Open the Software Center to install additional applications/apps.",
"disableCdromSource": "Disable CD-ROM source",
"disableCdromSourceDescription": "A relic of the Debian installation. Disable the CDROM source to avoid error messages.",
"@helloWorld": {
"placeholders": {},
"description": "The conventional newborn programmer greeting",
Expand Down
29 changes: 18 additions & 11 deletions lib/models/action_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@ class ActionEntry {
/// If true, this entry will not be shown in the search bar at the start screen randomly.
final bool excludeFromSearchProposal;

ActionEntry(
{required this.name,
required this.description,
required this.action,
this.iconURI = "",
this.priority = 0,
this.keywords = const [],
this.iconWidget,
this.tmpPriority = 0,
this.disableEntryIf,
this.excludeFromSearchProposal = false});
/// Handler Function which takes a string.
/// This function is called when the action String is empty by the action_handler.
/// VoidCallback is usally used to get back to start screen and to minimize the window.
late Function(VoidCallback, BuildContext)? handlerFunction;

ActionEntry({
required this.name,
required this.description,
this.action = "",
this.handlerFunction,
this.iconURI = "",
this.priority = 0,
this.keywords = const [],
this.iconWidget,
this.tmpPriority = 0,
this.disableEntryIf,
this.excludeFromSearchProposal = false,
});

@override
String toString() {
Expand Down
7 changes: 7 additions & 0 deletions lib/services/action_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class ActionHandler {
/// The callback is usually the clear function.
static Future<void> handleActionEntry(ActionEntry actionEntry,
VoidCallback callback, BuildContext context) async {
if (actionEntry.action.isEmpty) {
if (actionEntry.handlerFunction != null) {
actionEntry.handlerFunction!(callback, context);
}
return;
}

print(actionEntry.action);

// Save opened for intelligent search
Expand Down
33 changes: 33 additions & 0 deletions lib/services/linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2730,4 +2730,37 @@ class Linux {
runCommand("/usr/bin/gnome-software");
}
}

static bool isCdromSourceEnabledInDebian() {
if (![DISTROS.DEBIAN, DISTROS.MXLINUX, DISTROS.LMDE]
.contains(currentenvironment.distribution)) {
return false;
}
if (File("/etc/apt/sources.list").existsSync()) {
String fileString = File("/etc/apt/sources.list").readAsStringSync();
for (String line in fileString.split("\n")) {
if (line.contains("cdrom") && !line.trim().startsWith("#")) {
return true;
}
}
}
return false;
}

static void disableCdromSourceInDebian(context) {
if ([DISTROS.DEBIAN, DISTROS.MXLINUX, DISTROS.LMDE]
.contains(currentenvironment.distribution)) {
commandQueue.add(LinuxCommand(
userId: 0,
command: "/usr/bin/sed -i '/cdrom/d' /etc/apt/sources.list",
));
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => RunCommandQueue(
title: AppLocalizations.of(context)!.disableCdromSource,
message:
AppLocalizations.of(context)!.disableCdromSourceDescription,
route: MainSearchLoader()),
));
}
}
}

0 comments on commit d55e806

Please sign in to comment.