diff --git a/NAPS2.App.Mac/Info.plist b/NAPS2.App.Mac/Info.plist index 4feecdee2..00796f969 100644 --- a/NAPS2.App.Mac/Info.plist +++ b/NAPS2.App.Mac/Info.plist @@ -2,6 +2,8 @@ + + CFBundleName NAPS2 CFBundleIdentifier @@ -17,10 +19,77 @@ CFBundleIconFile Icon.icns NSPrincipalClass + NSApplication LSBackgroundOnly + + + CFBundleDocumentTypes + + + CFBundleTypeRole + Editor + CFBundleTypeName + PDF + LSItemContentTypes + + com.adobe.pdf + + + + CFBundleTypeRole + Editor + CFBundleTypeName + JPG + LSItemContentTypes + + public.jpeg + + + + CFBundleTypeRole + Editor + CFBundleTypeName + JP2 + LSItemContentTypes + + public.jpeg-2000 + + + + CFBundleTypeRole + Editor + CFBundleTypeName + PNG + LSItemContentTypes + + public.png + + + + CFBundleTypeRole + Editor + CFBundleTypeName + TIFF + LSItemContentTypes + + public.tiff + + + + CFBundleTypeRole + Editor + CFBundleTypeName + BMP + LSItemContentTypes + + com.microsoft.bmp + + + + diff --git a/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs b/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs index c1c67dc6b..c6837ccc8 100644 --- a/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs +++ b/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs @@ -6,6 +6,7 @@ using Eto.Mac.Drawing; using NAPS2.EtoForms.Layout; using NAPS2.EtoForms.Widgets; using NAPS2.Images.Mac; +using NAPS2.Remoting; namespace NAPS2.EtoForms.Mac; @@ -23,7 +24,9 @@ public class MacEtoPlatform : EtoPlatform public override Application CreateApplication() { - return new Application(Platforms.macOS); + var application = new Application(Platforms.macOS); + ((NSApplication) application.ControlObject).Delegate = new MacAppDelegate(); + return application; } public override void Invoke(Application application, Action action) @@ -160,4 +163,20 @@ public class MacEtoPlatform : EtoPlatform }); control.UnLoad += (_, _) => NSEvent.RemoveMonitor(monitor); } + + private class MacAppDelegate : AppDelegate + { + public override bool OpenFile(NSApplication sender, string filename) + { + Task.Run(() => + ProcessCoordinator.CreateDefault().OpenFile(Process.GetCurrentProcess(), 100, filename)); + return true; + } + + public override void OpenFiles(NSApplication sender, string[] filenames) + { + Task.Run(() => + ProcessCoordinator.CreateDefault().OpenFile(Process.GetCurrentProcess(), 100, filenames)); + } + } } \ No newline at end of file diff --git a/NAPS2.Lib/Remoting/ProcessCoordinator.cs b/NAPS2.Lib/Remoting/ProcessCoordinator.cs index edaea150f..e0996c0aa 100644 --- a/NAPS2.Lib/Remoting/ProcessCoordinator.cs +++ b/NAPS2.Lib/Remoting/ProcessCoordinator.cs @@ -65,9 +65,12 @@ public class ProcessCoordinator(string instanceLockPath, string pipeNameFormat) TrySendMessage(recipient, timeout, client => client.ScanWithDevice(new ScanWithDeviceRequest { Device = device })); - public bool OpenFile(Process recipient, int timeout, string path) => - TrySendMessage(recipient, timeout, - client => client.OpenFile(new OpenFileRequest { Path = { path } })); + public bool OpenFile(Process recipient, int timeout, params string[] paths) + { + var req = new OpenFileRequest(); + req.Path.AddRange(paths); + return TrySendMessage(recipient, timeout, client => client.OpenFile(req)); + } public bool TryTakeInstanceLock() {