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';
|
2023-09-07 21:25:13 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2023-07-20 20:06:17 +00:00
|
|
|
|
|
|
|
/// 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;
|
|
|
|
}
|
|
|
|
|
2023-07-20 20:19:29 +00:00
|
|
|
/// Running operating environment.
|
2023-07-20 20:06:17 +00:00
|
|
|
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';
|
|
|
|
}
|
2023-09-07 21:25:13 +00:00
|
|
|
|
|
|
|
static void setClipboard(final String clipboardData) {
|
|
|
|
Clipboard.setData(ClipboardData(text: clipboardData));
|
|
|
|
}
|
2023-07-20 20:06:17 +00:00
|
|
|
}
|