Fix QoS warning when running Test app server on main thread (#2873)

Move web server work on background thread and don't block main thread. No need to close connection on termination.
This commit is contained in:
Zorg authored and GitHub committed 2026-05-03 17:36:01 -07:00
1 parent f27a02f068
commit 2f33f56afb
3 files changed
+54 -59

No files matched your search

+38 -41
View File
@@ -297,45 +297,47 @@
abort();
}
self->_webServer = webServer;
// Set up updater and the updater settings window
{
self->_updateSettingsWindowController = [[SUUpdateSettingsWindowController alloc] init];
NSWindow *settingsWindow = self->_updateSettingsWindowController.window;
NSBundle *hostBundle = [NSBundle mainBundle];
NSBundle *applicationBundle = hostBundle;
id<SPUUserDriver> userDriver;
[webServer startWithReadyHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
// Set up updater and the updater settings window
self->_updateSettingsWindowController = [[SUUpdateSettingsWindowController alloc] init];
NSWindow *settingsWindow = self->_updateSettingsWindowController.window;
NSBundle *hostBundle = [NSBundle mainBundle];
NSBundle *applicationBundle = hostBundle;
id<SPUUserDriver> userDriver;
#if SPARKLE_BUILD_UI_BITS
if (shiftKeyHeldDown) {
userDriver = [[SUPopUpTitlebarUserDriver alloc] initWithWindow:settingsWindow];
} else {
userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:hostBundle delegate:nil];
}
if (shiftKeyHeldDown) {
userDriver = [[SUPopUpTitlebarUserDriver alloc] initWithWindow:settingsWindow];
} else {
userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:hostBundle delegate:nil];
}
#else
userDriver = [[SUPopUpTitlebarUserDriver alloc] initWithWindow:settingsWindow];
userDriver = [[SUPopUpTitlebarUserDriver alloc] initWithWindow:settingsWindow];
#endif
SPUUpdater *updater = [[SPUUpdater alloc] initWithHostBundle:hostBundle applicationBundle:applicationBundle userDriver:userDriver delegate:self];
self->_updater = updater;
self->_updateSettingsWindowController.updater = updater;
NSError *updaterError = nil;
if (![updater startUpdater:&updaterError]) {
NSLog(@"Failed to start updater with error: %@", updaterError);
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = @"Updater Error";
alert.informativeText = @"The Updater failed to start. For detailed error information, check the Console.app log.";
[alert addButtonWithTitle:@"OK"];
[alert runModal];
}
[self->_updateSettingsWindowController showWindow:nil];
}
SPUUpdater *updater = [[SPUUpdater alloc] initWithHostBundle:hostBundle applicationBundle:applicationBundle userDriver:userDriver delegate:self];
self->_updater = updater;
self->_updateSettingsWindowController.updater = updater;
NSError *updaterError = nil;
if (![updater startUpdater:&updaterError]) {
NSLog(@"Failed to start updater with error: %@", updaterError);
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = @"Updater Error";
alert.informativeText = @"The Updater failed to start. For detailed error information, check the Console.app log.";
[alert addButtonWithTitle:@"OK"];
[alert runModal];
}
[self->_updateSettingsWindowController showWindow:nil];
});
}];
});
}];
}
@@ -366,11 +368,6 @@
}];
}
- (void)applicationWillTerminate:(NSNotification * __unused)notification
{
[_webServer close];
}
- (IBAction)checkForUpdates:(id __unused)sender
{
[_updater checkForUpdates];
+1 -1
View File
@@ -12,6 +12,6 @@ SPU_OBJC_DIRECT_MEMBERS @interface SUTestWebServer : NSObject
- (instancetype)initWithPort:(int)port workingDirectory:(NSString*)workingDirectory;
- (void)close;
- (void)startWithReadyHandler:(dispatch_block_t)readyHandler;
@end
+15 -17
View File
@@ -174,6 +174,7 @@
SPU_OBJC_DIRECT_MEMBERS @interface SUTestWebServer () <SUTestWebServerConnectionDelegate> {
CFSocketRef _socket;
NSThread *_serverThread;
}
@property (nonatomic) NSMutableArray *connections;
@@ -227,14 +228,23 @@ static void connectCallback(CFSocketRef __unused s, CFSocketCallBackType type, C
_connections = [[NSMutableArray alloc] init];
_workingDirectory = workingDirectory;
CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, _socket, 0);
assert(source != NULL);
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
CFRelease(source);
return self;
}
- (void)startWithReadyHandler:(dispatch_block_t)readyHandler
{
_serverThread = [[NSThread alloc] initWithBlock:^{
CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, self->_socket, 0);
assert(source != NULL);
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
CFRelease(source);
readyHandler();
[[NSRunLoop currentRunLoop] run];
}];
[_serverThread start];
}
- (void)connectionDidClose:(SUTestWebServerConnection *)sender
{
assert(_connections != nil);
@@ -252,16 +262,4 @@ static void connectCallback(CFSocketRef __unused s, CFSocketCallBackType type, C
}
}
- (void)close
{
for (SUTestWebServerConnection *conn in _connections) {
[conn close];
}
if (_socket) {
CFSocketInvalidate(_socket);
CFRelease(_socket);
_socket = NULL;
}
}
@end