Skip to content

Commit e5ae558

Browse files
author
dsward2
committed
More changes for Catalina -
The HTTPS streaming audio with a Bonjour host name does not work in Catalina or iOS 13, so that feature has been removed as a user interface option. For the remaining HTTP connection, a Sharing button has been added to provide a convenient way to open LocalRadio on an iPhone via AirDrop. In a few places, the Xcode static analyzer found some secondary processes trying to call methods that are allowed on the main thread only. Those lines of code were wrapped in GCD calls to switch to the main thread when needed.
1 parent b58d9f7 commit e5ae558

File tree

11 files changed

+740
-599
lines changed

11 files changed

+740
-599
lines changed

LocalRadio/LocalRadio-Source/AppDelegate.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define kListenModeScan 2
3030
#define kListenModeDevice 3
3131

32-
@interface AppDelegate : NSObject <NSApplicationDelegate, NSStreamDelegate, NSTabViewDelegate>
32+
@interface AppDelegate : NSObject <NSApplicationDelegate, NSStreamDelegate, NSTabViewDelegate, NSSharingServiceDelegate>
3333

3434
//NS_ASSUME_NONNULL_BEGIN
3535

@@ -57,6 +57,9 @@
5757
@property (weak) IBOutlet NSTextField * localRadioHTTPSURLTextField;
5858
@property (weak) IBOutlet NSTextField * localRadioHTTPURLTextField;
5959

60+
@property (weak) IBOutlet NSButton * shareHTTPURLButton;
61+
@property (weak) IBOutlet NSButton * shareHTTPSURLButton;
62+
6063
@property (weak) IBOutlet NSTextField * statusIcecastServerTextField;
6164
@property (weak) IBOutlet NSTextField * statusIcecastSourceTextField;
6265
@property (weak) IBOutlet NSTextField * statusRTLSDRTextField;
@@ -194,5 +197,7 @@
194197
- (NSString *)localHostString;
195198
- (NSString *)localHostIPString;
196199

200+
- (IBAction)shareWebPreviewURL:(id)sender;
201+
197202
@end
198203

LocalRadio/LocalRadio-Source/AppDelegate.m

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ - (void)terminateTasks
101101
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
102102
{
103103
[self performSelectorInBackground:@selector(configureServices) withObject:NULL];
104+
105+
[self.shareHTTPSURLButton sendActionOn:NSEventMaskLeftMouseDown];
106+
[self.shareHTTPURLButton sendActionOn:NSEventMaskLeftMouseDown];
104107
}
105108

106109
//==================================================================================
@@ -318,7 +321,23 @@ - (IBAction)updateCurrentTasksText:(id)sender
318321
[tasksString appendFormat:@"%@ %@\n\n",
319322
self.icecastController.quotedIcecastPath, self.icecastController.icecastTaskArgsString];
320323

321-
AppDelegate * appDelegate = (AppDelegate *)[NSApp delegate];
324+
//AppDelegate * appDelegate = (AppDelegate *)[NSApp delegate];
325+
326+
__block AppDelegate * appDelegate = NULL;
327+
328+
if ([(NSThread*)[NSThread currentThread] isMainThread] == NO)
329+
{
330+
dispatch_sync(dispatch_get_main_queue(), ^{
331+
appDelegate = (AppDelegate *)[NSApp delegate];
332+
});
333+
}
334+
else
335+
{
336+
appDelegate = (AppDelegate *)[NSApp delegate];
337+
}
338+
339+
340+
322341
IcecastController * icecastController = appDelegate.icecastController;
323342
NSDictionary * icecastStatusDictionary = [icecastController icecastStatusDictionary];
324343

@@ -1499,6 +1518,68 @@ - (IBAction)reloadWebView:(id)sender
14991518
[self.webViewDelegate.webView reload:self];
15001519
}
15011520

1521+
// AirDrop methods
1522+
1523+
- (IBAction)shareWebPreviewURL:(id)sender
1524+
{
1525+
NSString * urlString = self.localRadioHTTPURLTextField.stringValue;
1526+
NSRect frameRect = self.localRadioHTTPURLTextField.frame;
1527+
NSButton * senderButton = sender;
1528+
1529+
if (sender == self.shareHTTPURLButton)
1530+
{
1531+
urlString = self.localRadioHTTPURLTextField.stringValue;
1532+
frameRect = self.localRadioHTTPURLTextField.bounds;
1533+
}
1534+
else if (sender == self.shareHTTPSURLButton)
1535+
{
1536+
urlString = self.localRadioHTTPSURLTextField.stringValue;
1537+
frameRect = self.localRadioHTTPSURLTextField.bounds;
1538+
}
1539+
1540+
NSURL* url = [NSURL URLWithString:urlString];
1541+
1542+
NSSharingServicePicker *sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:[NSArray arrayWithObjects:url, nil]];
1543+
1544+
__weak id weakSelf = self;
1545+
sharingServicePicker.delegate = weakSelf;
1546+
1547+
[sharingServicePicker showRelativeToRect:frameRect
1548+
ofView:senderButton
1549+
preferredEdge:NSMinYEdge];
1550+
}
1551+
1552+
1553+
- (NSRect) sharingService: (NSSharingService *) sharingService
1554+
sourceFrameOnScreenForShareItem: (id<NSPasteboardWriting>) item
1555+
{
1556+
if([item isKindOfClass: [NSURL class]])
1557+
{
1558+
//return a rect from where the image will fly
1559+
return NSZeroRect;
1560+
}
1561+
1562+
return NSZeroRect;
1563+
}
1564+
1565+
- (NSImage *) sharingService: (NSSharingService *) sharingService
1566+
transitionImageForShareItem: (id <NSPasteboardWriting>) item
1567+
contentRect: (NSRect *) contentRect
1568+
{
1569+
if([item isKindOfClass: [NSURL class]])
1570+
{
1571+
1572+
return [NSImage imageNamed:@"svg-logo.png"];
1573+
}
1574+
1575+
return nil;
1576+
}
1577+
1578+
- (id < NSSharingServiceDelegate >)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker delegateForSharingService:(NSSharingService *)sharingService
1579+
{
1580+
return self;
1581+
}
1582+
15021583

15031584

15041585
@end

LocalRadio/LocalRadio-Source/Base.lproj/MainMenu.xib

Lines changed: 35 additions & 30 deletions
Large diffs are not rendered by default.

LocalRadio/LocalRadio-Source/HTTPWebServerConnection.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,19 @@ - (id)initWithAsyncSocket:(GCDAsyncSocket *)newSocket configuration:(HTTPConfig
4242
{
4343
if ((self = [super initWithAsyncSocket:newSocket configuration:aConfig]))
4444
{
45-
self.appDelegate = (AppDelegate *)[NSApp delegate];
45+
//self.appDelegate = (AppDelegate *)[NSApp delegate];
46+
47+
if ([(NSThread*)[NSThread currentThread] isMainThread] == NO)
48+
{
49+
dispatch_sync(dispatch_get_main_queue(), ^{
50+
self.appDelegate = (AppDelegate *)[NSApp delegate];
51+
});
52+
}
53+
else
54+
{
55+
self.appDelegate = (AppDelegate *)[NSApp delegate];
56+
}
57+
4658
self.sqliteController = self.appDelegate.sqliteController;
4759
self.icecastController = self.appDelegate.icecastController;
4860
self.sdrController = self.appDelegate.sdrController;

LocalRadio/LocalRadio-Source/TaskPipelineManager.m

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,22 @@ - (void) configureTaskPipes
128128
[taskItem.task setStandardOutput:[NSFileHandle fileHandleWithNullDevice]];
129129
}
130130

131-
AppDelegate * appDelegate = (AppDelegate *)[NSApp delegate];
131+
//AppDelegate * appDelegate = (AppDelegate *)[NSApp delegate];
132+
133+
__block AppDelegate * appDelegate = NULL;
134+
135+
if ([(NSThread*)[NSThread currentThread] isMainThread] == NO)
136+
{
137+
dispatch_sync(dispatch_get_main_queue(), ^{
138+
appDelegate = (AppDelegate *)[NSApp delegate];
139+
});
140+
}
141+
else
142+
{
143+
appDelegate = (AppDelegate *)[NSApp delegate];
144+
}
145+
146+
132147
NSNumber * captureStderrNumber = [appDelegate.localRadioAppSettings integerForKey:@"CaptureStderr"];
133148
BOOL captureStderr = captureStderrNumber.boolValue;
134149

@@ -215,7 +230,21 @@ - (void) startTasks
215230

216231
self.taskPipelineStatus = kTaskPipelineStatusRunning;
217232

218-
AppDelegate * appDelegate = (AppDelegate *)[NSApp delegate];
233+
//AppDelegate * appDelegate = (AppDelegate *)[NSApp delegate];
234+
235+
__block AppDelegate * appDelegate = NULL;
236+
237+
if ([(NSThread*)[NSThread currentThread] isMainThread] == NO)
238+
{
239+
dispatch_sync(dispatch_get_main_queue(), ^{
240+
appDelegate = (AppDelegate *)[NSApp delegate];
241+
});
242+
}
243+
else
244+
{
245+
appDelegate = (AppDelegate *)[NSApp delegate];
246+
}
247+
219248
[appDelegate updateCurrentTasksText:self];
220249
}
221250
}
12.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)