Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Groundwork for the coverage tool integration #9415

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions main/src/addins/MacPlatform/MacPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ static void RegisterUncaughtExceptionHandler ()
NSSetUncaughtExceptionHandler (uncaughtHandler);
}

internal static List<IDisposable> AllObservers { get; } = new List<IDisposable> ();

public override Xwt.Toolkit LoadNativeToolkit ()
{
var loaded = NativeToolkitHelper.LoadCocoa ();
Expand All @@ -307,6 +309,10 @@ public override Xwt.Toolkit LoadNativeToolkit ()
var appDelegate = NSApplication.SharedApplication.Delegate as Xwt.Mac.AppDelegate;
if (appDelegate != null) {
appDelegate.Terminating += async (object o, TerminationEventArgs e) => {
foreach (var observer in AllObservers)
observer.Dispose ();
AllObservers.Clear ();

if (MonoDevelop.Ide.IdeApp.IsRunning) {
// If GLib the mainloop is still running that means NSApplication.Terminate() was called
// before Gtk.Application.Quit(). Cancel Cocoa termination and exit the mainloop.
Expand All @@ -319,14 +325,17 @@ public override Xwt.Toolkit LoadNativeToolkit ()
e.Reply = NSApplicationTerminateReply.Now;
}
};

// TODO: only attach this if coverage profiler is on
appDelegate.Terminate += () => Environment.Exit (0);
appDelegate.ShowDockMenu += AppDelegate_ShowDockMenu;
}

// Listen to the AtkCocoa notification for the presence of VoiceOver
SwizzleNSApplication ();

var nc = NSNotificationCenter.DefaultCenter;
notificationObservers.Add (nc.AddObserver ((NSString)"AtkCocoaAccessibilityEnabled", (NSNotification) => {
AllObservers.Add (nc.AddObserver ((NSString)"AtkCocoaAccessibilityEnabled", (NSNotification) => {
LoggingService.LogInfo ($"VoiceOver on {IdeTheme.AccessibilityEnabled}");
if (!IdeTheme.AccessibilityEnabled) {
ShowVoiceOverNotice ();
Expand Down Expand Up @@ -582,15 +591,15 @@ void InitApp (CommandManager commandManager)

if (MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) {
IdeTheme.HighContrastThemeEnabled = GetIsHighContrastActive ();
notificationObservers.Add (NSApplication.SharedApplication.AddObserver ("effectiveAppearance", NSKeyValueObservingOptions.New, notif =>
AllObservers.Add (NSApplication.SharedApplication.AddObserver ("effectiveAppearance", NSKeyValueObservingOptions.New, notif =>
Core.Runtime.RunInMainThread (() => {
IdeTheme.HighContrastThemeEnabled = GetIsHighContrastActive ();
PatchGtkTheme ();
})
));
} else {
IdeTheme.HighContrastThemeEnabled = false;
notificationObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread (
AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread (
delegate {
Styles.LoadStyle ();
PatchGtkTheme ();
Expand Down
2 changes: 1 addition & 1 deletion main/src/addins/MacPlatform/MainToolbar/AwesomeBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public override void ViewDidMoveToWindow ()
public override void ViewWillMoveToSuperview (NSView newSuperview)
{
if (Superview != null && superviewFrameChangeObserver != null) {
NSNotificationCenter.DefaultCenter.RemoveObserver (superviewFrameChangeObserver);
superviewFrameChangeObserver.Dispose ();
superviewFrameChangeObserver = null;

Superview.PostsFrameChangedNotifications = false;
Expand Down
8 changes: 4 additions & 4 deletions main/src/addins/MacPlatform/MainToolbar/MainToolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ public MainToolbar (Gtk.Window window)
item.MinSize = size;
}
});
NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, resizeAction, nswin);
NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidEndLiveResizeNotification, resizeAction, nswin);
MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, resizeAction, nswin));
MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidEndLiveResizeNotification, resizeAction, nswin));
}

NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.WillEnterFullScreenNotification, (note) => IsFullscreen = true, nswin);
NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.WillExitFullScreenNotification, (note) => IsFullscreen = false, nswin);
MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.WillEnterFullScreenNotification, (note) => IsFullscreen = true, nswin));
MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.WillExitFullScreenNotification, (note) => IsFullscreen = false, nswin));
}

internal void Initialize ()
Expand Down
8 changes: 4 additions & 4 deletions main/src/addins/MacPlatform/MainToolbar/SearchBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void UpdateLayout ()

void Initialize ()
{
NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResignKeyNotification, notification => Runtime.RunInMainThread (() => {
MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResignKeyNotification, notification => Runtime.RunInMainThread (() => {
var other = (NSWindow)notification.Object;

if (notification.Object == Window) {
Expand All @@ -252,16 +252,16 @@ void Initialize ()
LostFocus (this, null);
}
}
}));
NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, notification => Runtime.RunInMainThread (() => {
})));
MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, notification => Runtime.RunInMainThread (() => {
var other = (NSWindow)notification.Object;
if (notification.Object == Window) {
if (IsFirstResponderOfWindow (Window)) {
if (LostFocus != null)
LostFocus (this, null);
}
}
}));
})));
}

bool IsFirstResponderOfWindow (NSWindow window)
Expand Down
4 changes: 2 additions & 2 deletions main/src/addins/MacPlatform/MainToolbar/SelectorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,8 @@ public override void ViewDidMoveToWindow ()
{
base.ViewDidMoveToWindow ();

NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidChangeBackingPropertiesNotification,
notification => Runtime.RunInMainThread ((Action) RealignTexts));
MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidChangeBackingPropertiesNotification,
notification => Runtime.RunInMainThread ((Action) RealignTexts)));
RealignTexts ();
}

Expand Down
4 changes: 2 additions & 2 deletions main/src/addins/MacPlatform/ScreenMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public static class ScreenMonitor
static ScreenMonitor ()
{
screenToGdk = UpdateScreenLayout ();
NSNotificationCenter.DefaultCenter.AddObserver (NSApplication.DidChangeScreenParametersNotification, (obj) => {
MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSApplication.DidChangeScreenParametersNotification, (obj) => {
screenToGdk = UpdateScreenLayout ();
});
}));
}

public static CGPoint GdkPointForNSScreen (NSScreen screen)
Expand Down