Skip to content

Commit

Permalink
Merge branch 'trunk' into fix-stop-close-socketconnector
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierChanth authored Nov 27, 2024
2 parents 2d30ca0 + fc6a9c9 commit 0a098d6
Show file tree
Hide file tree
Showing 19 changed files with 888 additions and 709 deletions.
36 changes: 16 additions & 20 deletions packages/c/sshnpd/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

#define FILENAME_BUFFER_SIZE 500
Expand Down Expand Up @@ -77,32 +78,27 @@ static bool is_child_process = false;

// Signal handling
static volatile sig_atomic_t should_run = 1;
// static void exit_handler(int sig) {
// atlogger_log("exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received signal: %d\n");
// if (should_run == 1) {
// atlogger_log("exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received SIGINT, attempting a safe exit\n");
// should_run = 0;
// } else if (should_run == 0) {
// atlogger_log("exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received SIGINT again, exiting forcefully\n");
// exit(1);
// }
// }
// static void child_exit_handler(int sig) {
// atlogger_log("child_exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received signal: %d\n");
// int status;
// pid_t pid = waitpid(-1, &status, WNOHANG);
// if (pid > 0 && WIFEXITED(status)) {
// atlogger_log(LOGGER_TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "pid %d exited\n", pid);
// }
// }
static void exit_handler(int sig) {
atlogger_log("exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received signal: %d\n", sig);
should_run = 0;
exit(1);
}
static void child_exit_handler(int sig) {
atlogger_log("child_exit_handler", ATLOGGER_LOGGING_LEVEL_WARN, "Received signal: %d\n", sig);
int status;
pid_t pid = waitpid(-1, &status, WNOHANG);
if (pid > 0 && WIFEXITED(status)) {
atlogger_log(LOGGER_TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "pid %d exited\n", pid);
}
}

int main(int argc, char **argv) {
int res = 0;
int exit_res = 0;

// Catch sigint and pass to the handler
// signal(SIGINT, exit_handler);
// signal(SIGCHLD, child_exit_handler);
signal(SIGINT, exit_handler);
signal(SIGCHLD, child_exit_handler);

// 1. Load default values
apply_default_values_to_sshnpd_params(&params);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/features/logging/logging.dart';
import 'package:npt_flutter/styles/sizes.dart';

Expand All @@ -11,7 +12,7 @@ class DebugDumpLogsButton extends StatelessWidget {
Widget build(BuildContext context) {
if (!kDebugMode) return gap0;
return ElevatedButton(
child: const Text("Dev: Dump Logs to terminal"),
child: Text(AppLocalizations.of(context)!.debugDumpLogTitle),
onPressed: () {
var list = context.read<LogsCubit>().logs;
for (final line in list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:convert';

import 'package:at_onboarding_flutter/at_onboarding_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/app.dart';
import 'package:npt_flutter/features/onboarding/util/activate_util.dart';
import 'package:npt_flutter/widgets/spinner.dart';
import 'package:pin_code_fields/pin_code_fields.dart';
Expand Down Expand Up @@ -46,15 +48,16 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {
_getPinCode();
}

final strings = AppLocalizations.of(App.navState.currentContext!)!;

@override
Widget build(BuildContext context) {
return AlertDialog(
title: Center(
child: switch (status) {
// TODO localize
ActivationStatus.preparing => const Text("Preparing for activation"),
ActivationStatus.otpWait => const Text("Please enter the OTP from your email"),
ActivationStatus.activating => const Text("Activating"),
ActivationStatus.preparing => Text(strings.activationStatusPreparing),
ActivationStatus.otpWait => Text(strings.activationStatusOtpWait),
ActivationStatus.activating => Text(strings.activationStatusActivating),
},
),
content: SizedBox(
Expand All @@ -66,7 +69,6 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {
height: 80,
child: Column(
children: [
// TODO localize
PinCodeTextField(
focusNode: pinFocusNode,
appContext: context,
Expand Down Expand Up @@ -128,11 +130,10 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {
} else {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
SnackBar(
backgroundColor: Colors.red,
// TODO localize
content: Text(
"Failed to request an OTP, try resending, or contact support if the issue persists",
strings.errorOtpRequestFailed,
),
),
);
Expand All @@ -144,8 +145,7 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {

Widget get cancelButton => TextButton(
key: const Key("NoPortsActivateCancelButton"),
// TODO localize
child: const Text("Cancel"),
child: Text(strings.cancel),
onPressed: () {
Navigator.of(context).pop(AtOnboardingResult.cancelled());
},
Expand All @@ -154,8 +154,7 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {
Widget get resendPinButton => TextButton(
key: const Key("NoPortsActivateResendButton"),
onPressed: _getPinCode,
// TODO localize
child: const Text("Resend Pin"),
child: Text(strings.resendPin),
);

Widget get confirmPinButton => TextButton(
Expand All @@ -174,11 +173,10 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {

if (cramkey == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
SnackBar(
backgroundColor: Colors.red,
content: Text(
// TODO localize
"Failed to verify the OTP with the activation server, please try again. Contact support if the issue persists",
strings.errorOtpVerificationFailed,
),
),
);
Expand All @@ -198,7 +196,6 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {
if (!mounted) return;
Navigator.of(context).pop(result);
},
// TODO localize
child: const Text("Confirm"),
child: Text(strings.confirm),
);
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import 'dart:developer';
import 'dart:io';

import 'package:at_contacts_flutter/at_contacts_flutter.dart';
import 'package:at_onboarding_flutter/at_onboarding_flutter.dart';
import 'package:at_onboarding_flutter/at_onboarding_screens.dart';
import 'package:at_onboarding_flutter/at_onboarding_services.dart';
// ignore: implementation_imports
import 'package:at_onboarding_flutter/src/utils/at_onboarding_app_constants.dart';
import 'package:at_server_status/at_server_status.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/app.dart';
import 'package:npt_flutter/constants.dart';
import 'package:npt_flutter/features/onboarding/onboarding.dart';
import 'package:npt_flutter/features/onboarding/util/atsign_manager.dart';
import 'package:npt_flutter/features/onboarding/util/onboarding_util.dart';
import 'package:npt_flutter/features/onboarding/widgets/activate_atsign_dialog.dart';
import 'package:npt_flutter/features/onboarding/widgets/onboarding_dialog.dart';
import 'package:npt_flutter/routes.dart';

import 'package:npt_flutter/util/language.dart';
import 'package:path_provider/path_provider.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';

final strings = AppLocalizations.of(App.navState.currentContext!)!;
Future<AtClientPreference> loadAtClientPreference(String rootDomain) async {
var dir = await getApplicationSupportDirectory();

Expand Down Expand Up @@ -71,10 +73,8 @@ class _OnboardingButtonState extends State<OnboardingButton> {
),
iconAlignment: IconAlignment.end,
),
// TODO: localize
_OnboardingButtonStatus.picking => const Text("Waiting for file to be picked"),
// TODO: localize
_OnboardingButtonStatus.processingFile => const Text("Processing file"),
_OnboardingButtonStatus.picking => Text(strings.onboardingButtonStatusPicking),
_OnboardingButtonStatus.processingFile => Text(strings.onboardingButtonStatusProcessingFile),
};
}

Expand Down Expand Up @@ -167,12 +167,12 @@ class _OnboardingButtonState extends State<OnboardingButton> {

Future<AtOnboardingResult?> handleAtsignByStatus(String atsign, NoPortsOnboardingUtil util) async {
AtStatus status;

try {
status = await util.atServerStatus(atsign);
} catch (_) {
return AtOnboardingResult.error(
// TODO localize
message: "Failed to retrieve the atserver status, make sure you have a stable internet connection",
message: strings.errorAtServerUnavailable,
);
}
AtOnboardingResult? result;
Expand All @@ -185,15 +185,14 @@ class _OnboardingButtonState extends State<OnboardingButton> {

if (apiKey == null) {
result = AtOnboardingResult.error(
// TODO localize
message: "The atSign you have requested, doesn't exist in this root domain",
message: strings.errorAtSignNotExist,
);
break;
}
AtOnboardingConstants.setApiKey(apiKey);
AtOnboardingConstants.rootDomain = util.config.atClientPreference.rootDomain;
// TODO: localize locale - right now hardcoded to english
await AtOnboardingLocalizations.load(const Locale("en"));

await AtOnboardingLocalizations.load(LanguageUtil.getLanguageFromLocale(Locale(Platform.localeName)).locale);
if (!mounted) return null;
Map<String, String> apis = {
"root.atsign.org": "my.atsign.com",
Expand All @@ -202,8 +201,7 @@ class _OnboardingButtonState extends State<OnboardingButton> {
var regUrl = apis[util.config.atClientPreference.rootDomain];
if (regUrl == null) {
result ??= AtOnboardingResult.error(
// TODO: localize
message: "The specified root domain is not supported by automatic activation.",
message: strings.errorRootDomainNotSupported,
);
break;
}
Expand All @@ -224,7 +222,7 @@ class _OnboardingButtonState extends State<OnboardingButton> {
var onboardingService = OnboardingService.getInstance();
bool res = await onboardingService.changePrimaryAtsign(atsign: result.atsign!);
if (!res) {
result = AtOnboardingResult.error(message: "Failed to switch atSigns after activation");
result = AtOnboardingResult.error(message: strings.errorSwitchAtSignFailed);
}
}
}
Expand All @@ -237,20 +235,16 @@ class _OnboardingButtonState extends State<OnboardingButton> {
result = await handleFileUploadStatusStream(statusStream, atsign);
case AtSignStatus.notFound:
result = AtOnboardingResult.error(
// TODO: localize
message: "The atSign you have requested, doesn't exist in this root domain",
message: strings.errorAtSignNotExist,
);
case AtSignStatus.unavailable:
result = AtOnboardingResult.error(
// TODO: localize
message: "The atSign is unavailable. Make sure you have pressed \"Activate\" from your dashboard "
"and have a stable internet connection.",
message: strings.errorAtServerUnavailable,
);
case null: // This case should never happen, treat it as an error
case AtSignStatus.error:
result = AtOnboardingResult.error(
// TODO: localize
message: "Failed to retrieve the atserver status",
message: strings.errorAtServerUnavailable,
);
}
return result;
Expand All @@ -265,44 +259,37 @@ class _OnboardingButtonState extends State<OnboardingButton> {
switch (status) {
case ErrorIncorrectKeyFile():
result = AtOnboardingResult.error(
// TODO: localize
message: "Invalid atKeys file detected",
message: strings.errorAtKeysInvalid,
);
break outer;
case ErrorAtSignMismatch():
result = AtOnboardingResult.error(
// TODO: localize
message: "The atKeys file you uploaded did not match the atSign requested",
message: strings.errorAtKeysUploadedMismatch,
);
break outer;
case ErrorFailedFileProcessing():
result = AtOnboardingResult.error(
// TODO: localize
message: "Failed to process the atKeys file",
message: strings.errorAtKeysFileProcessFailed,
);
break outer;
case ErrorAtServerUnreachable():
result = AtOnboardingResult.error(
// TODO: localize
message: "Unable to connect to the atServer, make sure you have a stable internet connection",
message: strings.errorAtServerUnavailable,
);
break outer;
case ErrorAuthFailed():
result = AtOnboardingResult.error(
// TODO: localize
message: "Authentication failed",
message: strings.errorAuthenticatinFailed,
);
break outer;
case ErrorAuthTimeout():
result = AtOnboardingResult.error(
// TODO: localize
message: "Authentication timed out",
message: strings.errorAuthenticationTimedOut,
);
break outer;
case ErrorPairedAtsign _:
result = AtOnboardingResult.error(
// TODO: localize
message: "The atSign ${status.atSign ?? atsign} is already paired, please contact support.",
message: strings.errorAtSignAlreadyPaired(status.atSign ?? atsign),
);
break outer;
case FilePickingInProgress():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class OnboardingDialog extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("Select or type the client atSign"),
Text(strings.selectorTitleAtsign),
gapH16,
AtsignSelector(
options: options,
),
gapH16,
const Text("Select or type the root domain"),
Text(strings.selectorTitleRootDomain),
AtDirectorySelector(
options: options,
),
Expand All @@ -53,7 +53,7 @@ class OnboardingDialog extends StatelessWidget {
onPressed: () {
Navigator.of(context).pop(true);
},
child: const Text("Next"),
child: Text(strings.next),
),
],
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class ProfileHeaderView extends StatelessWidget {
);

case ProfileListFailedLoad _:
return const Row(
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Failed to load this profile, please refresh manually:"),
ProfileListRefreshButton(),
Text(strings.errorProfileLoadFailed),
const ProfileListRefreshButton(),
],
);

Expand Down
Loading

0 comments on commit 0a098d6

Please sign in to comment.