2023-03-15 23:29:07 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-03-11 00:09:03 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-10-22 22:15:34 +02:00
|
|
|
import 'package:immich_mobile/shared/models/server_info/server_disk_info.model.dart';
|
2022-03-11 00:09:03 +02:00
|
|
|
|
2023-10-22 22:15:34 +02:00
|
|
|
import 'package:immich_mobile/shared/models/server_info/server_info.model.dart';
|
2022-03-11 00:09:03 +02:00
|
|
|
import 'package:immich_mobile/shared/services/server_info.service.dart';
|
2023-10-22 22:15:34 +02:00
|
|
|
import 'package:immich_mobile/shared/models/server_info/server_config.model.dart';
|
|
|
|
import 'package:immich_mobile/shared/models/server_info/server_features.model.dart';
|
|
|
|
import 'package:immich_mobile/shared/models/server_info/server_version.model.dart';
|
2022-03-22 08:22:04 +02:00
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
2022-03-11 00:09:03 +02:00
|
|
|
|
2023-10-22 22:15:34 +02:00
|
|
|
class ServerInfoNotifier extends StateNotifier<ServerInfo> {
|
2022-06-25 20:46:51 +02:00
|
|
|
ServerInfoNotifier(this._serverInfoService)
|
2022-03-11 00:09:03 +02:00
|
|
|
: super(
|
2023-10-22 22:15:34 +02:00
|
|
|
ServerInfo(
|
|
|
|
serverVersion: const ServerVersion(
|
2022-07-13 14:23:48 +02:00
|
|
|
major: 0,
|
|
|
|
minor: 0,
|
2023-10-22 22:15:34 +02:00
|
|
|
patch: 0,
|
2022-07-13 14:23:48 +02:00
|
|
|
),
|
2023-10-22 22:15:34 +02:00
|
|
|
serverFeatures: const ServerFeatures(
|
2023-09-28 05:26:48 +02:00
|
|
|
map: true,
|
2023-10-06 09:01:14 +02:00
|
|
|
trash: true,
|
2023-09-28 05:26:48 +02:00
|
|
|
),
|
2023-10-22 22:15:34 +02:00
|
|
|
serverConfig: const ServerConfig(
|
2023-10-06 09:01:14 +02:00
|
|
|
trashDays: 30,
|
2023-10-22 22:15:34 +02:00
|
|
|
),
|
|
|
|
serverDiskInfo: const ServerDiskInfo(
|
|
|
|
diskAvailable: "0",
|
|
|
|
diskSize: "0",
|
|
|
|
diskUse: "0",
|
|
|
|
diskUsagePercentage: 0,
|
2023-09-28 05:26:48 +02:00
|
|
|
),
|
2022-03-22 08:22:04 +02:00
|
|
|
isVersionMismatch: false,
|
|
|
|
versionMismatchErrorMessage: "",
|
2022-03-11 00:09:03 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2022-06-25 20:46:51 +02:00
|
|
|
final ServerInfoService _serverInfoService;
|
2022-03-11 00:09:03 +02:00
|
|
|
|
2023-09-28 05:26:48 +02:00
|
|
|
getServerInfo() {
|
|
|
|
getServerVersion();
|
|
|
|
getServerFeatures();
|
|
|
|
getServerConfig();
|
|
|
|
}
|
|
|
|
|
2022-03-22 08:22:04 +02:00
|
|
|
getServerVersion() async {
|
2023-10-22 22:15:34 +02:00
|
|
|
final serverVersion = await _serverInfoService.getServerVersion();
|
2022-03-22 08:22:04 +02:00
|
|
|
|
|
|
|
if (serverVersion == null) {
|
|
|
|
state = state.copyWith(
|
|
|
|
isVersionMismatch: true,
|
2023-03-15 23:29:07 +02:00
|
|
|
versionMismatchErrorMessage: "common_server_error".tr(),
|
2022-03-22 08:22:04 +02:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
state = state.copyWith(serverVersion: serverVersion);
|
|
|
|
|
2022-06-23 06:14:14 +02:00
|
|
|
var packageInfo = await PackageInfo.fromPlatform();
|
2022-03-22 08:22:04 +02:00
|
|
|
|
|
|
|
Map<String, int> appVersion = _getDetailVersion(packageInfo.version);
|
|
|
|
|
|
|
|
if (appVersion["major"]! > serverVersion.major) {
|
|
|
|
state = state.copyWith(
|
|
|
|
isVersionMismatch: true,
|
|
|
|
versionMismatchErrorMessage:
|
2023-11-04 03:20:42 +02:00
|
|
|
"Server is out of date. Please update to the latest major version.",
|
2022-03-22 08:22:04 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appVersion["minor"]! > serverVersion.minor) {
|
|
|
|
state = state.copyWith(
|
|
|
|
isVersionMismatch: true,
|
|
|
|
versionMismatchErrorMessage:
|
2023-11-04 03:20:42 +02:00
|
|
|
"Server is out of date. Consider updating to the latest minor version.",
|
2022-03-22 08:22:04 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-23 06:14:14 +02:00
|
|
|
state = state.copyWith(
|
2022-07-13 14:23:48 +02:00
|
|
|
isVersionMismatch: false,
|
|
|
|
versionMismatchErrorMessage: "",
|
|
|
|
);
|
2022-03-22 08:22:04 +02:00
|
|
|
}
|
|
|
|
|
2023-09-28 05:26:48 +02:00
|
|
|
getServerFeatures() async {
|
2023-10-22 22:15:34 +02:00
|
|
|
final serverFeatures = await _serverInfoService.getServerFeatures();
|
2023-09-28 05:26:48 +02:00
|
|
|
if (serverFeatures == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
state = state.copyWith(serverFeatures: serverFeatures);
|
|
|
|
}
|
|
|
|
|
|
|
|
getServerConfig() async {
|
2023-10-22 22:15:34 +02:00
|
|
|
final serverConfig = await _serverInfoService.getServerConfig();
|
2023-09-28 05:26:48 +02:00
|
|
|
if (serverConfig == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
state = state.copyWith(serverConfig: serverConfig);
|
|
|
|
}
|
|
|
|
|
2022-03-22 08:22:04 +02:00
|
|
|
Map<String, int> _getDetailVersion(String version) {
|
|
|
|
List<String> detail = version.split(".");
|
|
|
|
|
|
|
|
var major = detail[0];
|
|
|
|
var minor = detail[1];
|
|
|
|
var patch = detail[2];
|
|
|
|
|
|
|
|
return {
|
|
|
|
"major": int.parse(major),
|
|
|
|
"minor": int.parse(minor),
|
2023-06-18 06:10:57 +02:00
|
|
|
"patch": int.parse(patch.replaceAll("-DEBUG", "")),
|
2022-03-22 08:22:04 +02:00
|
|
|
};
|
|
|
|
}
|
2022-03-11 00:09:03 +02:00
|
|
|
}
|
|
|
|
|
2022-06-23 06:14:14 +02:00
|
|
|
final serverInfoProvider =
|
2023-10-22 22:15:34 +02:00
|
|
|
StateNotifierProvider<ServerInfoNotifier, ServerInfo>((ref) {
|
2022-06-25 20:46:51 +02:00
|
|
|
return ServerInfoNotifier(ref.watch(serverInfoServiceProvider));
|
2022-03-11 00:09:03 +02:00
|
|
|
});
|