Browse Source

macosx: handle termination through libvlc_Quit

Note: this doesn't break quitting from the interface but SIGINT now
requires two attempts to trigger quitting. This will be fixed in
following commit.
pull/183/head
Alexandre Janniaux 10 months ago
committed by Felix Paul Kühne
parent
commit
025ea2fd6a
  1. 3
      modules/gui/macosx/main/VLCApplication.h
  2. 21
      modules/gui/macosx/main/VLCApplication.m
  3. 20
      modules/gui/macosx/main/VLCMain.m
  4. 2
      modules/gui/macosx/menus/VLCStatusBarIcon.h
  5. 7
      modules/gui/macosx/menus/VLCStatusBarIcon.m

3
modules/gui/macosx/main/VLCApplication.h

@ -25,6 +25,8 @@
#import <Cocoa/Cocoa.h>
typedef struct intf_thread_t intf_thread_t;
/*****************************************************************************
* VLCApplication interface
*****************************************************************************/
@ -45,4 +47,5 @@
@property(strong, readonly) NSImage *vlcAppIconImage;
@property(assign, readonly) BOOL winterHolidaysTheming;
- (void)setIntf:(intf_thread_t *)intf;
@end

21
modules/gui/macosx/main/VLCApplication.m

@ -31,6 +31,7 @@
#import "extensions/NSString+Helpers.h"
#import <vlc_configuration.h>
#import <vlc_interface.h>
/*****************************************************************************
* VLCApplication implementation
@ -40,6 +41,7 @@
{
NSURL *_appLocationURL;
NSImage *_vlcAppIconImage;
intf_thread_t *_intf;
}
@end
@ -74,6 +76,11 @@
return self;
}
- (void)setIntf:(intf_thread_t*)intf
{
_intf = intf;
}
- (void)dealloc
{
[NSNotificationCenter.defaultCenter removeObserver:self];
@ -140,19 +147,7 @@
- (void)terminate:(id)sender
{
[self activateIgnoringOtherApps:YES];
[self stop:sender];
// Trigger event in loop to force evaluating the stop flag
NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined
location:NSMakePoint(0,0)
modifierFlags:0
timestamp:0.0
windowNumber:0
context:nil
subtype:0
data1:0
data2:0];
[NSApp postEvent:event atStart:YES];
libvlc_Quit(vlc_object_instance(_intf));
}
@end

20
modules/gui/macosx/main/VLCMain.m

@ -141,6 +141,7 @@ NSString * const kVLCPreferencesVersion = @"VLCPreferencesVersion";
static intf_thread_t *p_interface_thread;
static vlc_preparser_t *p_network_preparser;
vlc_sem_t g_wait_quit;
intf_thread_t *getIntf()
{
@ -178,6 +179,7 @@ int OpenIntf (vlc_object_t *p_this)
@try {
VLCApplication * const application = VLCApplication.sharedApplication;
NSCAssert(application != nil, @"VLCApplication must not be nil");
[application setIntf:p_intf];
VLCMain * const main = VLCMain.sharedInstance;
NSCAssert(main != nil, @"VLCMain must not be nil");
@ -192,6 +194,7 @@ int OpenIntf (vlc_object_t *p_this)
dispatch_semaphore_signal(sem);
[NSApp run];
}
vlc_sem_post(&g_wait_quit);
});
CFRunLoopWakeUp(CFRunLoopGetMain());
@ -208,15 +211,24 @@ void CloseIntf (vlc_object_t *p_this)
[VLCMain.sharedInstance applicationWillTerminate:nil];
[VLCMain killInstance];
}
p_interface_thread = nil;
vlc_preparser_Delete(p_network_preparser);
p_network_preparser = nil;
[NSApp stop:nil];
NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined
location:NSMakePoint(0,0)
modifierFlags:0
timestamp:0.0
windowNumber:0
context:nil
subtype:0
data1:0
data2:0];
[NSApp postEvent:event atStart:YES];
};
if (CFRunLoopGetCurrent() == CFRunLoopGetMain())
release_intf();
else
dispatch_sync(dispatch_get_main_queue(), release_intf);
vlc_sem_wait(&g_wait_quit);
}
/*****************************************************************************
@ -337,7 +349,7 @@ static VLCMain *sharedInstance = nil;
[self migrateOldPreferences];
}
_statusBarIcon = [[VLCStatusBarIcon alloc] init];
_statusBarIcon = [[VLCStatusBarIcon alloc] init:_p_intf];
/* on macOS 11 and later, check whether the user attempts to deploy
* the x86_64 binary on ARM-64 - if yes, log it */

2
modules/gui/macosx/menus/VLCStatusBarIcon.h

@ -21,6 +21,7 @@
*****************************************************************************/
#import <Cocoa/Cocoa.h>
#include <vlc_interface.h>
@interface VLCStatusBarIcon : NSObject <NSMenuDelegate>
@ -30,6 +31,7 @@
@property (strong) IBOutlet NSView *playbackInfoView;
@property (strong) IBOutlet NSView *controlsView;
- (instancetype)init:(intf_thread_t *)intf;
- (IBAction)statusBarIconShowMainWindow:(id)sender;
- (IBAction)statusBarIconTogglePlayPause:(id)sender;
- (IBAction)statusBarIconNext:(id)sender;

7
modules/gui/macosx/menus/VLCStatusBarIcon.m

@ -34,6 +34,8 @@
@interface VLCStatusBarIcon ()
{
intf_thread_t *_intf;
NSMenuItem *_vlcStatusBarMenuItem;
/* Outlets for Now Playing labels */
@ -71,10 +73,11 @@
#pragma mark -
#pragma mark Init
- (instancetype)init
- (instancetype)init:(intf_thread_t *)intf;
{
self = [super init];
if (self) {
_intf = intf;
[[NSBundle mainBundle] loadNibNamed:@"VLCStatusBarIconMainMenu" owner:self topLevelObjects:nil];
}
return self;
@ -489,7 +492,7 @@
// Action: Quit VLC
- (IBAction)quitAction:(id)sender
{
[NSApplication.sharedApplication terminate:nil];
libvlc_Quit(vlc_object_instance(_intf));
}
- (IBAction)statusBarIconShowMiniAudioPlayer:(id)sender

Loading…
Cancel
Save