Kherel 2 years ago
parent 97c6fa435d
commit 3c683bef63
  1. 11
      assets/translations/en.json
  2. 11
      assets/translations/ru.json
  3. 2
      lib/logic/api_maps/server.dart
  4. 17
      lib/logic/cubit/app_config/app_config_cubit.dart
  5. 76
      lib/logic/cubit/app_config/app_config_repository.dart
  6. 26
      lib/logic/cubit/app_config/app_config_state.dart
  7. 12
      lib/ui/pages/more/app_settings/app_setting.dart
  8. 2
      lib/ui/pages/more/more.dart

@ -21,18 +21,25 @@
"saving": "Saving..",
"nickname": "nickname",
"loading": "loading",
"later": "Настрою потом"
"later": "Настрою потом",
"reset": "Reset"
},
"more": {
"_comment": "'More' tab",
"configuration_wizard": "Setup wizard",
"settings": "Application settings",
"about_project": "About us",
"about_app": "About application",
"onboarding": "Onboarding",
"console": "Console",
"about_app_page": {
"text": "Тут любая служебная информация, v.{}"
},
"settings": {
"title": "Application settings",
"1": "Dark Theme",
"2": "Change your the app theme",
"3": "Reset app config",
"4": "Reset api keys and root user"
}
},
"onboarding": {

@ -21,18 +21,25 @@
"saving": "Сохранение..",
"nickname": "Никнейм",
"loading": "Загрузка",
"later": "Настрою потом"
"later": "Настрою потом",
"reset": "Reset"
},
"more": {
"_comment": "вкладка еще",
"configuration_wizard": "Мастер Подключения",
"settings": "Настройки приложения",
"about_project": "О проекте SelfPrivacy",
"about_app": "О приложении",
"onboarding": "Onboarding",
"console": "Console",
"about_app_page": {
"text": "Тут любая служебная информация, v.{}"
},
"settings": {
"title": "Настройки приложения",
"1": "Темная тема",
"2": "Сменить цветовую тему",
"3": "Сброс настроек",
"4": "Сбросить API ключи а так же root пользвателя"
}
},
"onboarding": {

@ -13,11 +13,9 @@ class ServerApi extends ApiMap {
Future<bool> isHttpServerWorking() async {
bool res;
print('start');
Response response;
try {
response = await loggedClient.get('/serviceStatus');
print(response);
res = response.statusCode == HttpStatus.ok;
} catch (e) {
res = false;

@ -50,15 +50,10 @@ class AppConfigCubit extends Cubit<AppConfigState> {
if (state.progress < 6 || state.isFullyInitilized) {
emit(state);
} else if (state.progress == 6) {
print('startServerIfDnsIsOkay');
startServerIfDnsIsOkay(state: state, isImmediate: true);
} else if (state.progress == 7) {
print('resetServerIfServerIsOkay');
resetServerIfServerIsOkay(state: state, isImmediate: true);
} else if (state.progress == 8) {
print('finishCheckIfServerIsOkay');
finishCheckIfServerIsOkay(state: state, isImmediate: true);
}
}
@ -83,6 +78,8 @@ class AppConfigCubit extends Cubit<AppConfigState> {
state.hetznerServer!,
);
repository.saveServerDetails(server);
repository.saveIsServerStarted(true);
emit(
state.copyWith(
isServerStarted: true,
@ -136,6 +133,9 @@ class AppConfigCubit extends Cubit<AppConfigState> {
state!.hetznerKey,
state.hetznerServer!,
);
repository.saveIsServerReseted(true);
repository.saveServerDetails(hetznerServerDetails);
emit(
state.copyWith(
isServerReseted: true,
@ -181,7 +181,12 @@ class AppConfigCubit extends Cubit<AppConfigState> {
);
if (isServerWorking) {
emit(state.copyWith(hasFinalChecked: true, isLoading: false));
repository.saveHasFinalChecked(true);
emit(state.copyWith(
hasFinalChecked: true,
isLoading: false,
));
} else {
finishCheckIfServerIsOkay();
}

@ -21,6 +21,10 @@ class AppConfigRepository {
Box box = Hive.box(BNames.appConfig);
AppConfigState load() {
// saveIsServerStarted(false);
// saveIsServerReseted(false);
// saveHasFinalChecked(false);
return AppConfigState(
hetznerKey: box.get(BNames.hetznerKey),
cloudFlareKey: box.get(BNames.cloudFlareKey),
@ -29,10 +33,10 @@ class AppConfigRepository {
rootUser: box.get(BNames.rootUser),
hetznerServer: box.get(BNames.hetznerServer),
isServerStarted: box.get(BNames.isServerStarted, defaultValue: false),
error: null,
isServerReseted: box.get(BNames.isServerReseted, defaultValue: false),
hasFinalChecked: box.get(BNames.hasFinalChecked, defaultValue: false),
error: null,
isLoading: box.get(BNames.isLoading, defaultValue: false),
isServerReseted: box.get(BNames.isServerReseted, defaultValue: false),
);
}
@ -40,26 +44,6 @@ class AppConfigRepository {
box.clear();
}
void saveHetznerKey(String key) {
box.put(BNames.hetznerKey, key);
}
void saveBackblazeKey(BackblazeCredential backblazeCredential) {
box.put(BNames.backblazeKey, backblazeCredential);
}
void saveCloudFlare(String key) {
box.put(BNames.cloudFlareKey, key);
}
void saveDomain(CloudFlareDomain cloudFlareDomain) {
box.put(BNames.cloudFlareDomain, cloudFlareDomain);
}
void saveRootUser(User rootUser) {
box.put(BNames.rootUser, rootUser);
}
Future<HetznerServerDetails> startServer(
String? hetznerKey,
HetznerServerDetails hetznerServer,
@ -67,17 +51,11 @@ class AppConfigRepository {
var hetznerApi = HetznerApi(hetznerKey);
var serverDetails = await hetznerApi.startServer(server: hetznerServer);
hetznerApi.close();
box.put(BNames.isServerStarted, true);
return serverDetails;
}
Future<void> saveServerDetails(HetznerServerDetails serverDetails) async {
await box.put(BNames.hetznerServer, serverDetails);
}
Future<bool> isDnsAddressesMatch(String? domainName, String? ip4) async {
print(domainName);
var addresses = <String>[
'$domainName',
'api.$domainName',
@ -111,8 +89,6 @@ class AppConfigRepository {
}
}
box.put(BNames.hasFinalChecked, true);
return true;
}
@ -133,8 +109,8 @@ class AppConfigRepository {
rootUser: rootUser,
domainName: domainName,
);
await box.put(BNames.hetznerServer, serverDetails);
hetznerApi.close();
saveServerDetails(serverDetails);
onSuccess(serverDetails);
} on DioError catch (e) {
if (e.response!.data['error']['code'] == 'uniqueness_error') {
@ -159,7 +135,7 @@ class AppConfigRepository {
);
hetznerApi.close();
await box.put(BNames.hetznerServer, serverDetails);
await saveServerDetails(serverDetails);
onSuccess(serverDetails);
},
),
@ -211,4 +187,40 @@ class AppConfigRepository {
var hetznerApi = HetznerApi(hetznerKey);
return await hetznerApi.restart(server: server);
}
Future<void> saveServerDetails(HetznerServerDetails serverDetails) async {
await box.put(BNames.hetznerServer, serverDetails);
}
Future<void> saveIsServerStarted(bool value) async {
await box.put(BNames.isServerStarted, value);
}
Future<void> saveHetznerKey(String key) async {
await box.put(BNames.hetznerKey, key);
}
Future<void> saveIsServerReseted(bool value) async {
await box.put(BNames.isServerReseted, value);
}
Future<void> saveBackblazeKey(BackblazeCredential backblazeCredential) async {
await box.put(BNames.backblazeKey, backblazeCredential);
}
Future<void> saveCloudFlare(String key) async {
await box.put(BNames.cloudFlareKey, key);
}
void saveDomain(CloudFlareDomain cloudFlareDomain) async {
await box.put(BNames.cloudFlareDomain, cloudFlareDomain);
}
void saveRootUser(User rootUser) async {
await box.put(BNames.rootUser, rootUser);
}
void saveHasFinalChecked(bool value) async {
await box.put(BNames.hasFinalChecked, value);
}
}

@ -80,17 +80,21 @@ class AppConfigState extends Equatable {
bool get isFullyInitilized => _fulfilementList.every((el) => el!);
int get progress => _fulfilementList.where((el) => el!).length;
List<bool?> get _fulfilementList => [
isHetznerFilled,
isCloudFlareFilled,
isBackblazeFilled,
isDomainFilled,
isUserFilled,
isServerCreated,
isServerStarted,
isServerReseted,
hasFinalChecked,
];
List<bool?> get _fulfilementList {
var res = [
isHetznerFilled,
isCloudFlareFilled,
isBackblazeFilled,
isDomainFilled,
isUserFilled,
isServerCreated,
isServerStarted,
isServerReseted,
hasFinalChecked,
];
print('progress: $res');
return res;
}
}
class InitialAppConfigState extends AppConfigState {

@ -28,7 +28,7 @@ class _AppSettingsPageState extends State<AppSettingsPage> {
return Scaffold(
appBar: PreferredSize(
child:
BrandHeader(title: 'more.settings'.tr(), hasBackButton: true),
BrandHeader(title: 'more.settings.title'.tr(), hasBackButton: true),
preferredSize: Size.fromHeight(52),
),
body: ListView(
@ -47,8 +47,8 @@ class _AppSettingsPageState extends State<AppSettingsPage> {
children: [
Flexible(
child: _TextColumn(
title: 'Dark Theme',
value: 'Change your the app theme',
title: 'more.settings.1'.tr(),
value: 'more.settings.2'.tr(),
),
),
SizedBox(width: 5),
@ -75,8 +75,8 @@ class _AppSettingsPageState extends State<AppSettingsPage> {
children: [
Flexible(
child: _TextColumn(
title: 'Reset app config',
value: 'Reset api keys and root user',
title: 'more.settings.3'.tr(),
value: 'more.settings.4'.tr(),
),
),
SizedBox(width: 5),
@ -85,7 +85,7 @@ class _AppSettingsPageState extends State<AppSettingsPage> {
primary: BrandColors.red1,
),
child: Text(
'Reset',
'basis.reset'.tr(),
style: TextStyle(
color: BrandColors.white,
fontWeight: NamedFontWeight.demiBold,

@ -39,7 +39,7 @@ class MorePage extends StatelessWidget {
goTo: InitializingPage(),
),
_NavItem(
title: 'more.settings'.tr(),
title: 'more.settings.title'.tr(),
iconData: BrandIcons.settings,
goTo: AppSettingsPage(),
),

Loading…
Cancel
Save