before change api_client

fdroid
Kherel 2 years ago
parent 7d12b85f89
commit 20cca91e00
  1. 6
      lib/config/get_it_config.dart
  2. 4
      lib/logic/api_maps/api_map.dart
  3. 2
      lib/logic/api_maps/backblaze.dart
  4. 2
      lib/logic/api_maps/cloudflare.dart
  5. 2
      lib/logic/api_maps/hetzner.dart
  6. 2
      lib/logic/api_maps/server.dart
  7. 2
      lib/logic/cubit/app_config/app_config_cubit.dart
  8. 37
      lib/logic/cubit/app_config/app_config_repository.dart
  9. 63
      lib/logic/get_it/api_config.dart
  10. 3
      lib/main.dart
  11. 19
      lib/ui/pages/services/services.dart

@ -1,4 +1,5 @@
import 'package:get_it/get_it.dart';
import 'package:selfprivacy/logic/get_it/api_config.dart';
import 'package:selfprivacy/logic/get_it/console.dart';
import 'package:selfprivacy/logic/get_it/navigation.dart';
import 'package:selfprivacy/logic/get_it/timer.dart';
@ -9,9 +10,12 @@ export 'package:selfprivacy/logic/get_it/timer.dart';
final getIt = GetIt.instance;
void getItSetup() {
Future<void> getItSetup() async {
getIt.registerSingleton<NavigationService>(NavigationService());
getIt.registerSingleton<ConsoleModel>(ConsoleModel());
getIt.registerSingleton<TimerModel>(TimerModel());
getIt.registerSingleton<ApiConfigModel>(ApiConfigModel()..init());
await getIt.allReady();
}

@ -7,8 +7,8 @@ import 'package:selfprivacy/config/get_it_config.dart';
import 'package:selfprivacy/logic/get_it/console.dart';
import 'package:selfprivacy/logic/models/message.dart';
abstract class ApiMap {
ApiMap() {
abstract class ApiMapOld {
ApiMapOld() {
var client = Dio()..interceptors.add(ConsoleInterceptor());
(client.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
(HttpClient client) {

@ -2,7 +2,7 @@ import 'dart:io';
import 'package:dio/dio.dart';
import 'package:selfprivacy/logic/api_maps/api_map.dart';
class BackblazeApi extends ApiMap {
class BackblazeApi extends ApiMapOld {
BackblazeApi([String? token]) {
if (token != null) {
loggedClient.options = BaseOptions(

@ -4,7 +4,7 @@ import 'package:selfprivacy/logic/api_maps/api_map.dart';
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
import 'package:selfprivacy/logic/models/dns_records.dart';
class CloudflareApi extends ApiMap {
class CloudflareApi extends ApiMapOld {
CloudflareApi([String? token]) {
if (token != null) {
loggedClient.options =

@ -7,7 +7,7 @@ import 'package:selfprivacy/logic/models/server_details.dart';
import 'package:selfprivacy/logic/models/user.dart';
import 'package:selfprivacy/utils/password_generator2.dart';
class HetznerApi extends ApiMap {
class HetznerApi extends ApiMapOld {
HetznerApi([String? token]) {
if (token != null) {
loggedClient.options = BaseOptions(

@ -4,7 +4,7 @@ import 'package:dio/dio.dart';
import 'api_map.dart';
class ServerApi extends ApiMap {
class ServerApi extends ApiMapOld {
ServerApi(String? domainName) {
loggedClient.options = BaseOptions(
baseUrl: 'https://api.$domainName',

@ -219,7 +219,7 @@ class AppConfigCubit extends Cubit<AppConfigState> {
}
void setCloudflareKey(String cloudFlareKey) {
repository.saveCloudFlare(cloudFlareKey);
repository.saveCloudFlareKey(cloudFlareKey);
emit(state.copyWith(cloudFlareKey: cloudFlareKey));
}

@ -4,6 +4,7 @@ import 'package:selfprivacy/config/hive_config.dart';
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
import 'package:selfprivacy/logic/api_maps/server.dart';
import 'package:selfprivacy/logic/get_it/api_config.dart';
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
import 'package:selfprivacy/logic/models/server_details.dart';
@ -22,12 +23,12 @@ class AppConfigRepository {
AppConfigState load() {
return AppConfigState(
hetznerKey: box.get(BNames.hetznerKey),
cloudFlareKey: box.get(BNames.cloudFlareKey),
cloudFlareDomain: box.get(BNames.cloudFlareDomain),
backblazeCredential: box.get(BNames.backblazeKey),
hetznerKey: getIt<ApiConfigModel>().hetznerKey,
cloudFlareKey: getIt<ApiConfigModel>().cloudFlareKey,
cloudFlareDomain: getIt<ApiConfigModel>().cloudFlareDomain,
backblazeCredential: getIt<ApiConfigModel>().backblazeCredential,
hetznerServer: getIt<ApiConfigModel>().hetznerServer,
rootUser: box.get(BNames.rootUser),
hetznerServer: box.get(BNames.hetznerServer),
isServerStarted: box.get(BNames.isServerStarted, defaultValue: false),
isServerReseted: box.get(BNames.isServerReseted, defaultValue: false),
hasFinalChecked: box.get(BNames.hasFinalChecked, defaultValue: false),
@ -185,31 +186,31 @@ class AppConfigRepository {
}
Future<void> saveServerDetails(HetznerServerDetails serverDetails) async {
await box.put(BNames.hetznerServer, serverDetails);
await getIt<ApiConfigModel>().storeServerDetails(serverDetails);
}
Future<void> saveIsServerStarted(bool value) async {
await box.put(BNames.isServerStarted, value);
Future<void> saveHetznerKey(String key) async {
await getIt<ApiConfigModel>().storeHetznerKey(key);
}
Future<void> saveHetznerKey(String key) async {
await box.put(BNames.hetznerKey, key);
Future<void> saveBackblazeKey(BackblazeCredential backblazeCredential) async {
await getIt<ApiConfigModel>().storeBackblazeCredential(backblazeCredential);
}
Future<void> saveIsServerReseted(bool value) async {
await box.put(BNames.isServerReseted, value);
Future<void> saveCloudFlareKey(String key) async {
await getIt<ApiConfigModel>().storeCloudFlareKey(key);
}
Future<void> saveBackblazeKey(BackblazeCredential backblazeCredential) async {
await box.put(BNames.backblazeKey, backblazeCredential);
Future<void> saveDomain(CloudFlareDomain cloudFlareDomain) async {
await getIt<ApiConfigModel>().storeCloudFlareDomain(cloudFlareDomain);
}
Future<void> saveCloudFlare(String key) async {
await box.put(BNames.cloudFlareKey, key);
Future<void> saveIsServerStarted(bool value) async {
await box.put(BNames.isServerStarted, value);
}
void saveDomain(CloudFlareDomain cloudFlareDomain) async {
await box.put(BNames.cloudFlareDomain, cloudFlareDomain);
Future<void> saveIsServerReseted(bool value) async {
await box.put(BNames.isServerReseted, value);
}
void saveRootUser(User rootUser) async {

@ -0,0 +1,63 @@
import 'package:hive/hive.dart';
import 'package:selfprivacy/config/hive_config.dart';
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
import 'package:selfprivacy/logic/models/cloudflare_domain.dart';
import 'package:selfprivacy/logic/models/server_details.dart';
class ApiConfigModel {
Box _box = Hive.box(BNames.appConfig);
HetznerServerDetails? get hetznerServer => _hetznerServer;
String? get hetznerKey => _hetznerKey;
String? get cloudFlareKey => _cloudFlareKey;
BackblazeCredential? get backblazeCredential => _backblazeCredential;
CloudFlareDomain? get cloudFlareDomain => _cloudFlareDomain;
String? _hetznerKey;
String? _cloudFlareKey;
HetznerServerDetails? _hetznerServer;
BackblazeCredential? _backblazeCredential;
CloudFlareDomain? _cloudFlareDomain;
Future<void> storeHetznerKey(String value) async {
await _box.put(BNames.hetznerKey, value);
_hetznerKey = value;
}
Future<void> storeCloudFlareKey(String value) async {
await _box.put(BNames.cloudFlareKey, value);
_cloudFlareKey = value;
}
Future<void> storeBackblazeCredential(BackblazeCredential value) async {
await _box.put(BNames.backblazeKey, value);
_backblazeCredential = value;
}
Future<void> storeCloudFlareDomain(CloudFlareDomain value) async {
await _box.put(BNames.cloudFlareDomain, value);
_cloudFlareDomain = value;
}
Future<void> storeServerDetails(HetznerServerDetails value) async {
await _box.put(BNames.hetznerServer, value);
_hetznerServer = value;
}
clear() {
_hetznerKey = null;
_cloudFlareKey = null;
_backblazeCredential = null;
_cloudFlareDomain = null;
_hetznerServer = null;
}
void init() {
_hetznerKey = _box.get(BNames.hetznerKey);
_cloudFlareKey = _box.get(BNames.cloudFlareKey);
_backblazeCredential = _box.get(BNames.backblazeKey);
_cloudFlareDomain = _box.get(BNames.cloudFlareDomain);
_hetznerServer = _box.get(BNames.hetznerServer);
}
}

@ -15,12 +15,11 @@ import 'config/get_it_config.dart';
import 'config/localization.dart';
import 'logic/cubit/app_settings/app_settings_cubit.dart';
void main() async {
await HiveConfig.init();
Bloc.observer = SimpleBlocObserver();
Wakelock.enable();
getItSetup();
await getItSetup();
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();

@ -378,6 +378,21 @@ class _ServiceDetails extends StatelessWidget {
);
}
void _launchURL(url) async =>
await canLaunch(url) ? await launch(url) : throw 'Could not launch $url';
void _launchURL(url) async {
var _possible = await canLaunch(url);
if (_possible) {
try {
await launch(
url,
forceSafariVC: true,
enableJavaScript: true,
);
} catch (e) {
print(e);
}
} else {
throw 'Could not launch $url';
}
}
}

Loading…
Cancel
Save