SimpleCloudNotifier/flutter/lib/state/globals.dart

67 lines
1.9 KiB
Dart
Raw Permalink Normal View History

2024-05-25 18:09:39 +02:00
import 'dart:io';
2024-05-31 15:22:27 +02:00
import 'package:device_info_plus/device_info_plus.dart';
2024-05-25 18:09:39 +02:00
import 'package:package_info_plus/package_info_plus.dart';
2024-05-26 18:34:42 +02:00
import 'package:shared_preferences/shared_preferences.dart';
2024-05-25 18:09:39 +02:00
class Globals {
static final Globals _singleton = Globals._internal();
factory Globals() {
return _singleton;
}
Globals._internal();
String appName = '';
String packageName = '';
String version = '';
String buildNumber = '';
String platform = '';
String hostname = '';
2024-05-31 15:22:27 +02:00
String clientType = '';
String deviceModel = '';
2024-05-25 18:09:39 +02:00
2024-05-26 18:34:42 +02:00
late SharedPreferences sharedPrefs;
2024-05-25 21:36:05 +02:00
Future<void> init() async {
2024-05-25 18:09:39 +02:00
PackageInfo packageInfo = await PackageInfo.fromPlatform();
this.appName = packageInfo.appName;
this.packageName = packageInfo.packageName;
this.version = packageInfo.version;
this.buildNumber = packageInfo.buildNumber;
this.platform = Platform.operatingSystem;
this.hostname = Platform.localHostname;
2024-05-26 18:34:42 +02:00
2024-05-31 15:22:27 +02:00
if (Platform.isAndroid) {
this.clientType = 'ANDROID';
this.deviceModel = (await DeviceInfoPlugin().androidInfo).model;
} else if (Platform.isIOS) {
this.clientType = 'IOS';
this.deviceModel = (await DeviceInfoPlugin().iosInfo).model;
} else if (Platform.isLinux) {
this.clientType = 'LINUX';
this.deviceModel = (await DeviceInfoPlugin().linuxInfo).prettyName;
} else if (Platform.isWindows) {
this.clientType = 'WINDOWS';
this.deviceModel = (await DeviceInfoPlugin().windowsInfo).productName;
} else if (Platform.isMacOS) {
this.clientType = 'MACOS';
this.deviceModel = (await DeviceInfoPlugin().macOsInfo).model;
} else {
this.clientType = '?';
}
2024-05-26 18:34:42 +02:00
this.sharedPrefs = await SharedPreferences.getInstance();
2024-05-25 18:09:39 +02:00
}
String? getPrefFCMToken() {
return sharedPrefs.getString("fcm.token");
}
Future<bool> setPrefFCMToken(String value) {
return sharedPrefs.setString("fcm.token", value);
}
2024-05-25 18:09:39 +02:00
}