add adaptive_scaffold

This commit is contained in:
shenlong-tanwen
2024-05-24 09:42:02 +05:30
parent fb6253d2d1
commit 1631df70e9
295 changed files with 2540 additions and 44480 deletions
@@ -1,22 +1,22 @@
import 'package:immich_mobile/domain/models/app_setting.model.dart';
import 'package:immich_mobile/domain/store_manager.dart';
class AppSettingsService {
class AppSettingService {
final StoreManager store;
const AppSettingsService(this.store);
const AppSettingService(this.store);
T getSetting<T>(AppSettings<T> setting) {
T getSetting<T>(AppSetting<T> setting) {
return store.get(setting.storeKey, setting.defaultValue);
}
void setSetting<T>(AppSettings<T> setting, T value) {
store.put(setting.storeKey, value);
Future<bool> setSetting<T>(AppSetting<T> setting, T value) async {
return await store.put(setting.storeKey, value);
}
Stream<T> watchSetting<T>(AppSettings<T> setting) {
Stream<T> watchSetting<T>(AppSetting<T> setting) {
return store
.watch<T>(setting.storeKey)
.watch(setting.storeKey)
.map((value) => value ?? setting.defaultValue);
}
}
@@ -0,0 +1,55 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:immich_mobile/utils/mixins/log_context.mixin.dart';
import 'package:openapi/openapi.dart';
class LoginService with LogContext {
const LoginService();
Future<bool> isEndpointAvailable(Uri uri, {Dio? dio}) async {
String baseUrl = uri.toString();
if (!baseUrl.endsWith('/api')) {
baseUrl += '/api';
}
final serverAPI =
Openapi(dio: dio, basePathOverride: baseUrl, interceptors: [])
.getServerInfoApi();
try {
await serverAPI.pingServer(validateStatus: (status) => status == 200);
} catch (e) {
log.severe("Exception occured while validating endpoint", e);
return false;
}
return true;
}
Future<String> resolveEndpoint(Uri uri, {Dio? dio}) async {
final d = dio ?? Dio();
String baseUrl = uri.toString();
try {
// Check for well-known endpoint
final res = await d.get(
"$baseUrl/.well-known/immich",
options: Options(
headers: {"Accept": "application/json"},
validateStatus: (status) => status == 200,
),
);
final data = jsonDecode(res.data);
final endpoint = data['api']['endpoint'].toString();
// Full URL is relative to base
return endpoint.startsWith('/') ? "$baseUrl$endpoint" : endpoint;
} catch (e) {
log.fine("Could not locate /.well-known/immich at $baseUrl", e);
}
// No well-known, return the baseUrl
return baseUrl;
}
}
@@ -0,0 +1,38 @@
import 'package:immich_mobile/domain/models/server-info/server_config.model.dart';
import 'package:immich_mobile/domain/models/server-info/server_features.model.dart';
import 'package:immich_mobile/utils/mixins/log_context.mixin.dart';
import 'package:openapi/openapi.dart';
class ServerInfoService with LogContext {
final Openapi _api;
ServerInfoApi get _serverInfo => _api.getServerInfoApi();
ServerInfoService(this._api);
Future<ServerFeatures?> getServerFeatures() async {
try {
final response = await _serverInfo.getServerFeatures();
final dto = response.data;
if (dto != null) {
return ServerFeatures.fromDto(dto);
}
} catch (e, s) {
log.severe("Error while fetching server features", e, s);
}
return null;
}
Future<ServerConfig?> getServerConfig() async {
try {
final response = await _serverInfo.getServerConfig();
final dto = response.data;
if (dto != null) {
return ServerConfig.fromDto(dto);
}
} catch (e, s) {
log.severe("Error while fetching server config", e, s);
}
return null;
}
}