Example #1
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            var apps = NSRunningApplication.GetRunningApplications(NSBundle.MainBundle.BundleIdentifier);

            if (apps.Length > 1)
            {
                Console.WriteLine($"アプリケーションはすでに起動しています。");
                NSApplication.SharedApplication.Terminate(this);
            }
        }
Example #2
0
 /// <summary>
 /// Because we are creating our own mac application delegate we are removing / overriding
 /// the one that Avalonia creates. This causes the application to not be handled as it should.
 /// This is the Avalonia Implementation: https://github.com/AvaloniaUI/Avalonia/blob/5a2ef35dacbce0438b66d9f012e5f629045beb3d/native/Avalonia.Native/src/OSX/app.mm
 /// So what we are doing here is re-creating this implementation to mimick their behavior.
 /// </summary>
 /// <param name="notification"></param>
 public override void WillFinishLaunching(NSNotification notification)
 {
     if (NSApplication.SharedApplication.ActivationPolicy != NSApplicationActivationPolicy.Regular)
     {
         foreach (var x in NSRunningApplication.GetRunningApplications(@"com.apple.dock"))
         {
             x.Activate(NSApplicationActivationOptions.ActivateIgnoringOtherWindows);
             break;
         }
         NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular;
     }
 }
Example #3
0
        public static IEnumerable <InspectableWindow> GetWindows(string bundleIdentifier,
                                                                 bool onScreenOnly = true)
        {
            var apps = NSRunningApplication.GetRunningApplications(bundleIdentifier);

            if (apps == null)
            {
                yield break;
            }

            var windows = GetWindowList(onScreenOnly);

            if (windows == null || windows.Length == 0)
            {
                yield break;
            }

            foreach (var app in apps)
            {
                foreach (var dict in windows)
                {
                    var windowOwnerPid = dict [keyWindowOwnerPid] as NSNumber;
                    if ((windowOwnerPid?.Int32Value ?? -1) != app.ProcessIdentifier)
                    {
                        continue;
                    }

                    CGRect bounds;
                    if (!TryGetBounds(dict, out bounds))
                    {
                        continue;
                    }

                    yield return(new InspectableWindow {
                        Application = app,
                        Title = GetTitle(dict),
                        Bounds = bounds
                    });
                }
            }
        }