From 6cbd11eb7c09146ac67f0d0596a12bc3114dc08d Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Fri, 15 Sep 2023 16:19:39 -0700 Subject: [PATCH] Fixing warning about not being able to invoke some keychain functions on the main thread --- .../Mac-Cocoa/PLSLoginWindowController.mm | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSLoginWindowController.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSLoginWindowController.mm index a9c3497319..7a847e8c25 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSLoginWindowController.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSLoginWindowController.mm @@ -64,6 +64,7 @@ @interface PLSLoginWindowController () #define FAKE_PASS_STRING @"********" static NSOperationQueue* _loginQueue = nil; +static dispatch_queue_t _keychainQueue = dispatch_queue_create(nullptr, DISPATCH_QUEUE_SERIAL); @implementation PLSLoginController @@ -131,11 +132,13 @@ - (void)save ST::string username = [self.username STString]; ST::string password = [self.password STString]; - pfPasswordStore* store = pfPasswordStore::Instance(); - if (self.rememberPassword) - store->SetPassword(username, password); - else - store->SetPassword(username, ST::string()); + dispatch_async(_keychainQueue, ^{ + pfPasswordStore* store = pfPasswordStore::Instance(); + if (self.rememberPassword) + store->SetPassword(username, password); + else + store->SetPassword(username, ST::string()); + }); } } @@ -150,8 +153,10 @@ - (void)load if (self.rememberPassword) { pfPasswordStore* store = pfPasswordStore::Instance(); ST::string username = [self.username STString]; - ST::string password = store->GetPassword(username); - self.password = [NSString stringWithSTString:password]; + dispatch_sync(_keychainQueue, ^{ + ST::string password = store->GetPassword(username); + self.password = [NSString stringWithSTString:password]; + }); } }