Skip to content

Commit

Permalink
Fix Safari cancel message
Browse files Browse the repository at this point in the history
WE2-571

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored and mrts committed Oct 7, 2021
1 parent f82e14c commit 1a47fc8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
19 changes: 5 additions & 14 deletions src/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@
#include "utils.hpp"
#include "inputoutputmode.hpp"
#include "writeresponse.hpp"
#include "logging.hpp"

#include "magic_enum/magic_enum.hpp"

#include <QApplication>
#include <QScopedPointer>
#include <QVariantMap>

using namespace pcsc_cpp;
using namespace electronic_id;
Expand Down Expand Up @@ -77,6 +72,7 @@ void Controller::run()
<< (isInStdinMode ? "stdin/stdout" : "command-line") << "mode";

try {
// TODO: cut out stdin mode separate class to avoid bugs in safari mode
if (isInStdinMode) {
// In stdin/stdout mode we first output the version as required by the WebExtension
// and then wait for the actual command.
Expand Down Expand Up @@ -327,25 +323,20 @@ void Controller::onDialogOK(const CardCertificateAndPinInfo& cardCertAndPinInfo)
void Controller::onDialogCancel()
{
qDebug() << "User cancelled";

_result = makeErrorObject(RESP_USER_CANCEL, QStringLiteral("User cancelled"));
writeResponseToStdOut(isInStdinMode, _result, commandType());
disposeUI();

writeResponseToStdOut(isInStdinMode,
makeErrorObject(RESP_USER_CANCEL, QStringLiteral("User cancelled")),
commandType());
exit();
}

void Controller::onCriticalFailure(const QString& error)
{
qCritical() << "Exiting due to command" << std::string(commandType())
<< "fatal error:" << error;
writeResponseToStdOut(isInStdinMode, makeErrorObject(RESP_TECH_ERROR, error), commandType());

_result = makeErrorObject(RESP_TECH_ERROR, error);
writeResponseToStdOut(isInStdinMode, _result, commandType());
disposeUI();

WebEidUI::showFatalError();

exit();
}

Expand Down
9 changes: 1 addition & 8 deletions src/controller/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@

#include "commandhandler.hpp"

#include "ui.hpp"

#include "pcsc-cpp/pcsc-cpp.hpp"

#include "observer_ptr.hpp"

#include <unordered_map>
#include <cstdint>

class ControllerChildThread;
class CardEventMonitorThread;
Expand All @@ -42,7 +35,7 @@ class Controller : public QObject
Q_OBJECT

public:
explicit Controller(CommandWithArgumentsPtr cmd) : QObject(nullptr), command(std::move(cmd)) {}
explicit Controller(CommandWithArgumentsPtr cmd) : command(std::move(cmd)) {}

const QVariantMap& result() const { return _result; }

Expand Down
2 changes: 2 additions & 0 deletions src/mac/safari-extension.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ @implementation SafariWebExtensionHandler

- (id)init {
if (self = [super init]) {
NSLog(@"web-eid-safari-extension: starting");
contexts = [[NSMutableDictionary<NSString *, NSExtensionContext *> alloc] init];
[NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(notificationEvent:) name:WebEidExtension object:nil];
}
Expand All @@ -43,6 +44,7 @@ - (id)init {

- (void)dealloc
{
NSLog(@"web-eid-safari-extension: stopping");
[NSDistributedNotificationCenter.defaultCenter removeObserver:self name:WebEidExtension object:nil];
}

Expand Down

0 comments on commit 1a47fc8

Please sign in to comment.