2023-07-20 20:06:17 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
|
|
|
/// SelfPrivacy wrapper for Platform information provider.
|
|
|
|
class PlatformAdapter {
|
|
|
|
/// Persistent storage directory for data files.
|
2023-07-20 20:14:17 +00:00
|
|
|
static String? get storagePath {
|
|
|
|
String? path;
|
2023-07-20 20:06:17 +00:00
|
|
|
if (Platform.isLinux) {
|
|
|
|
// https://wiki.archlinux.org/title/XDG_Base_Directory
|
2023-07-20 20:14:17 +00:00
|
|
|
path = Platform.environment['XDG_DATA_HOME'];
|
|
|
|
if (path == null) {
|
2023-07-20 20:06:17 +00:00
|
|
|
final String home = Platform.environment['HOME'] ?? '.';
|
2023-07-20 20:14:17 +00:00
|
|
|
path = '$home/.local/share';
|
2023-07-20 20:06:17 +00:00
|
|
|
}
|
|
|
|
path += '/selfprivacy';
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Running operation environment.
|
|
|
|
static Future<String> get deviceName async {
|
|
|
|
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
|
|
|
if (kIsWeb) {
|
|
|
|
return deviceInfo.webBrowserInfo.then(
|
|
|
|
(final WebBrowserInfo value) =>
|
|
|
|
'${value.browserName} ${value.platform}',
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
return deviceInfo.androidInfo.then(
|
|
|
|
(final AndroidDeviceInfo value) =>
|
|
|
|
'${value.model} ${value.version.release}',
|
|
|
|
);
|
|
|
|
} else if (Platform.isIOS) {
|
|
|
|
return deviceInfo.iosInfo.then(
|
|
|
|
(final IosDeviceInfo value) =>
|
|
|
|
'${value.utsname.machine} ${value.systemName} ${value.systemVersion}',
|
|
|
|
);
|
|
|
|
} else if (Platform.isLinux) {
|
|
|
|
return deviceInfo.linuxInfo
|
|
|
|
.then((final LinuxDeviceInfo value) => value.prettyName);
|
|
|
|
} else if (Platform.isMacOS) {
|
|
|
|
return deviceInfo.macOsInfo.then(
|
|
|
|
(final MacOsDeviceInfo value) =>
|
|
|
|
'${value.hostName} ${value.computerName}',
|
|
|
|
);
|
|
|
|
} else if (Platform.isWindows) {
|
|
|
|
return deviceInfo.windowsInfo
|
|
|
|
.then((final WindowsDeviceInfo value) => value.computerName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'Unidentified';
|
|
|
|
}
|
|
|
|
}
|