fix: Systemd shows nothing (#850)

This commit is contained in:
shamnad-sherief
2025-08-13 17:49:28 +05:30
committed by GitHub
parent 6f9aa2ece9
commit e4a9875620

View File

@@ -44,8 +44,14 @@ final class SystemdProvider {
} }
} }
final parsedUserUnits = await _parseUnitObj(userUnits, SystemdUnitScope.user); final parsedUserUnits = await _parseUnitObj(
final parsedSystemUnits = await _parseUnitObj(systemUnits, SystemdUnitScope.system); userUnits,
SystemdUnitScope.user,
);
final parsedSystemUnits = await _parseUnitObj(
systemUnits,
SystemdUnitScope.system,
);
this.units.value = [...parsedUserUnits, ...parsedSystemUnits]; this.units.value = [...parsedUserUnits, ...parsedSystemUnits];
} catch (e, s) { } catch (e, s) {
Loggers.app.warning('Parse systemd', e, s); Loggers.app.warning('Parse systemd', e, s);
@@ -54,8 +60,13 @@ final class SystemdProvider {
isBusy.value = false; isBusy.value = false;
} }
Future<List<SystemdUnit>> _parseUnitObj(List<String> unitNames, SystemdUnitScope scope) async { Future<List<SystemdUnit>> _parseUnitObj(
final unitNames_ = unitNames.map((e) => e.trim().split('/').last.split('.').first).toList(); List<String> unitNames,
SystemdUnitScope scope,
) async {
final unitNames_ = unitNames
.map((e) => e.trim().split('/').last.split('.').first)
.toList();
final script = final script =
''' '''
for unit in ${unitNames_.join(' ')}; do for unit in ${unitNames_.join(' ')}; do
@@ -103,7 +114,13 @@ done
} }
parsedUnits.add( parsedUnits.add(
SystemdUnit(name: name, type: unitType, scope: scope, state: unitState, description: description), SystemdUnit(
name: name,
type: unitType,
scope: scope,
state: unitState,
description: description,
),
); );
} }
@@ -121,36 +138,23 @@ done
return parsedUnits; return parsedUnits;
} }
late final _getUnitsCmd = late final _getUnitsCmd = '''
''' types="service socket mount timer"
get_files() {
unit_type=\$1
base_dir=\$2
# If base_dir is not a directory, return get_files() {
if [ ! -d "\$base_dir" ]; then unit_type=\$1
return base_dir=\$2
fi [ -d "\$base_dir" ] || return
find "\$base_dir" -type f -name "*.\$unit_type" -print
}
find "\$base_dir" -type f -name "*.\$unit_type" -print | sort for type in \$types; do
} get_files \$type /etc/systemd/system
get_files \$type /lib/systemd/system
get_type_files() { get_files \$type /usr/lib/systemd/system
unit_type=\$1 get_files \$type ~/.config/systemd/user
base_dir="" done | sort
''';
${_isRoot ? """
get_files \$unit_type /etc/systemd/system
get_files \$unit_type ~/.config/systemd/user""" : """
get_files \$unit_type ~/.config/systemd/user"""}
}
types="service socket mount timer"
for type in \$types; do
get_type_files \$type
done
''';
} }
String _getIniVal(String line) { String _getIniVal(String line) {