2022-03-11 00:09:03 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
|
2022-03-22 08:22:04 +02:00
|
|
|
import 'package:immich_mobile/shared/models/server_info_state.model.dart';
|
2022-03-11 00:09:03 +02:00
|
|
|
import 'package:immich_mobile/shared/services/server_info.service.dart';
|
2022-07-13 14:23:48 +02:00
|
|
|
import 'package:openapi/api.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
|
|
|
|
|
|
|
class ServerInfoNotifier extends StateNotifier<ServerInfoState> {
|
2022-06-25 20:46:51 +02:00
|
|
|
ServerInfoNotifier(this._serverInfoService)
|
2022-03-11 00:09:03 +02:00
|
|
|
: super(
|
|
|
|
ServerInfoState(
|
2022-07-13 14:23:48 +02:00
|
|
|
serverVersion: ServerVersionReponseDto(
|
|
|
|
major: 0,
|
|
|
|
patch_: 0,
|
|
|
|
minor: 0,
|
|
|
|
build: 0,
|
|
|
|
),
|
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
|
|
|
|
2022-03-22 08:22:04 +02:00
|
|
|
getServerVersion() async {
|
2022-07-13 14:23:48 +02:00
|
|
|
ServerVersionReponseDto? serverVersion =
|
|
|
|
await _serverInfoService.getServerVersion();
|
2022-03-22 08:22:04 +02:00
|
|
|
|
|
|
|
if (serverVersion == null) {
|
|
|
|
state = state.copyWith(
|
|
|
|
isVersionMismatch: true,
|
|
|
|
versionMismatchErrorMessage:
|
|
|
|
"Server is out of date. Some functionalities might not working correctly. Download and rebuild server",
|
|
|
|
);
|
|
|
|
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:
|
|
|
|
"Server is out of date in major version. Some functionalities might not work correctly. Download and rebuild server",
|
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appVersion["minor"]! > serverVersion.minor) {
|
|
|
|
state = state.copyWith(
|
|
|
|
isVersionMismatch: true,
|
|
|
|
versionMismatchErrorMessage:
|
|
|
|
"Server is out of date in minor version. Some functionalities might not work correctly. Consider download and rebuild server",
|
|
|
|
);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
|
|
|
"patch": int.parse(patch),
|
|
|
|
};
|
|
|
|
}
|
2022-03-11 00:09:03 +02:00
|
|
|
}
|
|
|
|
|
2022-06-23 06:14:14 +02:00
|
|
|
final serverInfoProvider =
|
|
|
|
StateNotifierProvider<ServerInfoNotifier, ServerInfoState>((ref) {
|
2022-06-25 20:46:51 +02:00
|
|
|
return ServerInfoNotifier(ref.watch(serverInfoServiceProvider));
|
2022-03-11 00:09:03 +02:00
|
|
|
});
|