2023-03-15 14:29:07 -07:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-03-10 15:09:03 -07:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-04-30 19:36:40 -07:00
|
|
|
import 'package:immich_mobile/models/server_info/server_disk_info.model.dart';
|
2022-03-10 15:09:03 -07:00
|
|
|
|
2024-04-30 19:36:40 -07:00
|
|
|
import 'package:immich_mobile/models/server_info/server_info.model.dart';
|
2024-05-02 13:59:14 -07:00
|
|
|
import 'package:immich_mobile/services/server_info.service.dart';
|
2024-04-30 19:36:40 -07:00
|
|
|
import 'package:immich_mobile/models/server_info/server_config.model.dart';
|
|
|
|
import 'package:immich_mobile/models/server_info/server_features.model.dart';
|
|
|
|
import 'package:immich_mobile/models/server_info/server_version.model.dart';
|
2024-04-23 14:09:10 -07:00
|
|
|
import 'package:logging/logging.dart';
|
2022-03-21 23:22:04 -07:00
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
2022-03-10 15:09:03 -07:00
|
|
|
|
2023-10-22 13:15:34 -07:00
|
|
|
class ServerInfoNotifier extends StateNotifier<ServerInfo> {
|
2022-06-25 11:46:51 -07:00
|
|
|
ServerInfoNotifier(this._serverInfoService)
|
2022-03-10 15:09:03 -07:00
|
|
|
: super(
|
2023-10-22 13:15:34 -07:00
|
|
|
ServerInfo(
|
|
|
|
serverVersion: const ServerVersion(
|
2022-07-13 05:23:48 -07:00
|
|
|
major: 0,
|
|
|
|
minor: 0,
|
2023-10-22 13:15:34 -07:00
|
|
|
patch: 0,
|
2022-07-13 05:23:48 -07:00
|
|
|
),
|
2023-11-17 14:46:18 -07:00
|
|
|
latestVersion: const ServerVersion(
|
|
|
|
major: 0,
|
|
|
|
minor: 0,
|
|
|
|
patch: 0,
|
|
|
|
),
|
2023-10-22 13:15:34 -07:00
|
|
|
serverFeatures: const ServerFeatures(
|
2023-09-27 20:26:48 -07:00
|
|
|
map: true,
|
2023-10-06 00:01:14 -07:00
|
|
|
trash: true,
|
2024-01-04 13:44:40 -07:00
|
|
|
oauthEnabled: false,
|
|
|
|
passwordLogin: true,
|
2023-09-27 20:26:48 -07:00
|
|
|
),
|
2023-10-22 13:15:34 -07:00
|
|
|
serverConfig: const ServerConfig(
|
2023-10-06 00:01:14 -07:00
|
|
|
trashDays: 30,
|
2024-01-04 13:44:40 -07:00
|
|
|
oauthButtonText: '',
|
2024-01-03 19:54:48 -07:00
|
|
|
externalDomain: '',
|
2024-09-23 13:30:23 -07:00
|
|
|
mapLightStyleUrl:
|
|
|
|
'https://tiles.immich.cloud/v1/style/light.json',
|
|
|
|
mapDarkStyleUrl: 'https://tiles.immich.cloud/v1/style/dark.json',
|
2023-10-22 13:15:34 -07:00
|
|
|
),
|
|
|
|
serverDiskInfo: const ServerDiskInfo(
|
|
|
|
diskAvailable: "0",
|
|
|
|
diskSize: "0",
|
|
|
|
diskUse: "0",
|
|
|
|
diskUsagePercentage: 0,
|
2023-09-27 20:26:48 -07:00
|
|
|
),
|
2022-03-21 23:22:04 -07:00
|
|
|
isVersionMismatch: false,
|
2023-11-17 14:46:18 -07:00
|
|
|
isNewReleaseAvailable: false,
|
2022-03-21 23:22:04 -07:00
|
|
|
versionMismatchErrorMessage: "",
|
2022-03-10 15:09:03 -07:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2022-06-25 11:46:51 -07:00
|
|
|
final ServerInfoService _serverInfoService;
|
2024-04-23 14:09:10 -07:00
|
|
|
final _log = Logger("ServerInfoNotifier");
|
2022-03-10 15:09:03 -07:00
|
|
|
|
2024-01-04 13:44:40 -07:00
|
|
|
Future<void> getServerInfo() async {
|
|
|
|
await getServerVersion();
|
|
|
|
await getServerFeatures();
|
|
|
|
await getServerConfig();
|
2023-09-27 20:26:48 -07:00
|
|
|
}
|
|
|
|
|
2022-03-21 23:22:04 -07:00
|
|
|
getServerVersion() async {
|
2024-04-23 14:09:10 -07:00
|
|
|
try {
|
|
|
|
final serverVersion = await _serverInfoService.getServerVersion();
|
2022-03-21 23:22:04 -07:00
|
|
|
|
2024-04-23 14:09:10 -07:00
|
|
|
if (serverVersion == null) {
|
|
|
|
state = state.copyWith(
|
|
|
|
isVersionMismatch: true,
|
|
|
|
versionMismatchErrorMessage: "common_server_error".tr(),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await _checkServerVersionMismatch(serverVersion);
|
|
|
|
} catch (e, stackTrace) {
|
|
|
|
_log.severe("Failed to get server version", e, stackTrace);
|
2022-03-21 23:22:04 -07:00
|
|
|
state = state.copyWith(
|
|
|
|
isVersionMismatch: true,
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2023-11-17 14:46:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
_checkServerVersionMismatch(ServerVersion serverVersion) async {
|
2022-03-21 23:22:04 -07:00
|
|
|
state = state.copyWith(serverVersion: serverVersion);
|
|
|
|
|
2022-06-22 21:14:14 -07:00
|
|
|
var packageInfo = await PackageInfo.fromPlatform();
|
2022-03-21 23:22:04 -07:00
|
|
|
|
|
|
|
Map<String, int> appVersion = _getDetailVersion(packageInfo.version);
|
|
|
|
|
|
|
|
if (appVersion["major"]! > serverVersion.major) {
|
|
|
|
state = state.copyWith(
|
|
|
|
isVersionMismatch: true,
|
2024-01-03 19:54:48 -07:00
|
|
|
versionMismatchErrorMessage:
|
|
|
|
"profile_drawer_server_out_of_date_major".tr(),
|
2022-03-21 23:22:04 -07:00
|
|
|
);
|
2023-11-17 14:46:18 -07:00
|
|
|
return;
|
|
|
|
}
|
2022-03-21 23:22:04 -07:00
|
|
|
|
2023-11-17 14:46:18 -07:00
|
|
|
if (appVersion["major"]! < serverVersion.major) {
|
|
|
|
state = state.copyWith(
|
|
|
|
isVersionMismatch: true,
|
2024-01-03 19:54:48 -07:00
|
|
|
versionMismatchErrorMessage:
|
|
|
|
"profile_drawer_client_out_of_date_major".tr(),
|
2023-11-17 14:46:18 -07:00
|
|
|
);
|
2022-03-21 23:22:04 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appVersion["minor"]! > serverVersion.minor) {
|
|
|
|
state = state.copyWith(
|
|
|
|
isVersionMismatch: true,
|
2024-01-03 19:54:48 -07:00
|
|
|
versionMismatchErrorMessage:
|
|
|
|
"profile_drawer_server_out_of_date_minor".tr(),
|
2022-03-21 23:22:04 -07:00
|
|
|
);
|
2023-11-17 14:46:18 -07:00
|
|
|
return;
|
|
|
|
}
|
2022-03-21 23:22:04 -07:00
|
|
|
|
2023-11-17 14:46:18 -07:00
|
|
|
if (appVersion["minor"]! < serverVersion.minor) {
|
|
|
|
state = state.copyWith(
|
|
|
|
isVersionMismatch: true,
|
2024-01-03 19:54:48 -07:00
|
|
|
versionMismatchErrorMessage:
|
|
|
|
"profile_drawer_client_out_of_date_minor".tr(),
|
2023-11-17 14:46:18 -07:00
|
|
|
);
|
2022-03-21 23:22:04 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-22 21:14:14 -07:00
|
|
|
state = state.copyWith(
|
2022-07-13 05:23:48 -07:00
|
|
|
isVersionMismatch: false,
|
|
|
|
versionMismatchErrorMessage: "",
|
|
|
|
);
|
2022-03-21 23:22:04 -07:00
|
|
|
}
|
|
|
|
|
2023-11-17 14:46:18 -07:00
|
|
|
handleNewRelease(
|
|
|
|
ServerVersion serverVersion,
|
|
|
|
ServerVersion latestVersion,
|
|
|
|
) {
|
|
|
|
// Update local server version
|
|
|
|
_checkServerVersionMismatch(serverVersion);
|
|
|
|
|
|
|
|
final majorEqual = latestVersion.major == serverVersion.major;
|
|
|
|
final minorEqual = majorEqual && latestVersion.minor == serverVersion.minor;
|
|
|
|
final newVersionAvailable = latestVersion.major > serverVersion.major ||
|
|
|
|
(majorEqual && latestVersion.minor > serverVersion.minor) ||
|
|
|
|
(minorEqual && latestVersion.patch > serverVersion.patch);
|
|
|
|
|
|
|
|
state = state.copyWith(
|
|
|
|
latestVersion: latestVersion,
|
|
|
|
isNewReleaseAvailable: newVersionAvailable,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-27 20:26:48 -07:00
|
|
|
getServerFeatures() async {
|
2023-10-22 13:15:34 -07:00
|
|
|
final serverFeatures = await _serverInfoService.getServerFeatures();
|
2023-09-27 20:26:48 -07:00
|
|
|
if (serverFeatures == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
state = state.copyWith(serverFeatures: serverFeatures);
|
|
|
|
}
|
|
|
|
|
|
|
|
getServerConfig() async {
|
2023-10-22 13:15:34 -07:00
|
|
|
final serverConfig = await _serverInfoService.getServerConfig();
|
2023-09-27 20:26:48 -07:00
|
|
|
if (serverConfig == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
state = state.copyWith(serverConfig: serverConfig);
|
|
|
|
}
|
|
|
|
|
2022-03-21 23:22:04 -07: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-17 21:10:57 -07:00
|
|
|
"patch": int.parse(patch.replaceAll("-DEBUG", "")),
|
2022-03-21 23:22:04 -07:00
|
|
|
};
|
|
|
|
}
|
2022-03-10 15:09:03 -07:00
|
|
|
}
|
|
|
|
|
2022-06-22 21:14:14 -07:00
|
|
|
final serverInfoProvider =
|
2023-10-22 13:15:34 -07:00
|
|
|
StateNotifierProvider<ServerInfoNotifier, ServerInfo>((ref) {
|
2023-11-17 14:46:18 -07:00
|
|
|
return ServerInfoNotifier(ref.read(serverInfoServiceProvider));
|
2022-03-10 15:09:03 -07:00
|
|
|
});
|