Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/platform_linux/lib/src/linux_desktop.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:meta/meta.dart';
import 'package:platform/platform.dart';

/// Detects the Linux desktop environment.
Expand Down Expand Up @@ -44,6 +45,16 @@ extension PlatformLinuxDesktop on Platform {
/// [Xfce](https://xfce.org/)
bool get isXfce => _isDesktop('xfce');

/// Overrides the detected desktop environment for testing.
///
/// The values must be in lowercase.
@visibleForTesting
set xdgDesktopOverride(List<String>? names) {
final cacheId = identityHashCode(this);
_xdgCurrentDesktopCacheId = cacheId;
_xdgCurrentDesktopCache = names;
}

bool _isDesktop(String name) {
return _getXdgCurrentDesktop(this)?.contains(name) ?? false;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/platform_linux/lib/src/linux_distro.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:meta/meta.dart';
import 'package:platform/platform.dart';

/// Detects the Linux distro.
Expand Down Expand Up @@ -34,6 +35,14 @@ extension PlatformLinuxDistro on Platform {
/// [Ubuntu](https://ubuntu.com/)
bool get isUbuntu => _isDistro('ubuntu');

/// Overrides the detected distro for testing.
@visibleForTesting
set distroOverride(String? id) {
final cacheId = identityHashCode(this);
_osReleaseCacheId = cacheId;
_osReleaseCache = {'ID': id};
}

bool _isDistro(String id) {
final os = _getOsRelease(this);
return os?['ID'] == id ||
Expand Down
1 change: 1 addition & 0 deletions packages/platform_linux/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ environment:

dependencies:
platform: ^3.1.0
meta: ^1.17.0

dev_dependencies:
mockito: ^5.4.4
Expand Down
18 changes: 18 additions & 0 deletions packages/platform_linux/test/linux_desktop_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,22 @@ void main() {
);
expect(platform.isXfce, isTrue);
});

test('Override', () {
final platform = FakePlatform(
environment: {
'XDG_CURRENT_DESKTOP': 'KDE',
},
);
platform.xdgDesktopOverride = ['budgie', 'gnome'];
expect({
'kde': platform.isKDE,
'budgie': platform.isBudgie,
'gnome': platform.isGNOME,
}, {
'kde': isFalse,
'budgie': isTrue,
'gnome': isTrue,
});
});
}
29 changes: 29 additions & 0 deletions packages/platform_linux/test/linux_distro_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,35 @@ BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=lunar
LOGO=ubuntu-logo
'''),
}).call,
);
});

test('Override', () {
IOOverrides.runZoned(
() {
final platform = FakePlatform();
platform.distroOverride = 'opensuse';
expect(
{'manjaro': platform.isManjaro, 'opensuse': platform.isOpenSUSE},
{'manjaro': isFalse, 'opensuse': isTrue},
);
},
createFile: MockTextFiles({
'/etc/os-release': MockTextFile('''
NAME="Manjaro Linux"
PRETTY_NAME="Manjaro Linux"
ID=manjaro
ID_LIKE=arch
BUILD_ID=rolling
ANSI_COLOR="32;1;24;144;200"
HOME_URL="https://manjaro.org/"
DOCUMENTATION_URL="https://wiki.manjaro.org/"
SUPPORT_URL="https://forum.manjaro.org/"
BUG_REPORT_URL="https://docs.manjaro.org/reporting-bugs/"
PRIVACY_POLICY_URL="https://manjaro.org/privacy-policy/"
LOGO=manjarolinux
'''),
}).call,
);
Expand Down
Loading