How to capture right click in a MacCatalyst app? - swift

How can I present a context menu or even better a iOS Popover controller when right clicking in a MacCatalyst app? Right now I have it set up for long presses, not that doesn't feel right on a desktop app.

https://developer.apple.com/design/human-interface-guidelines/ios/controls/context-menus/
We use this to develop right click menus with MacCatalyst

Related

SwiftUI How do I capture a keyboard shortcut with a button

I am writing a menubar application with a popup view but no menu and no storyboard. Among other things, I want to activate a button with keyboard shortcut.
Everything I have found so far is either for Swift 2.0 or for menu based applications. I would like my application to run on Catalina, though by the time it is finished I know that Big Sur will be out.
Is there a way for a SwiftUI button to respond to a keyboard shortcut, or some other way for a view to do that?
I am on MacOS 10.15.6, and XCode 11.7.

New tab button - UIWindowScene and macOS Catalyst

Is it possible to add a "New Tab" button to the tabBar, like Safari and Finder has? My app is a Mac Catalyst app and has support for multiple windows, but to open new windows the user has to select it from the menu bar or use keyboard shortcuts.
The idea is to have this built-in Tab Bar work much like https://github.com/stuffmc/TabbedViews does.
.
The built-in one has:
No + button (and no New Tab menu either)
Only the option to display the full display of a window. This one can display the Tab Bar anywhere, and especially also on iOS.
This one though has no support yet for Move Tab to New Window and of course one need not to forget to remove Merge All Windows, otherwise both will conflict.

How to debug js code inside a wkwebview of safair app extensionn popover?

It's not just a wkwebview, it's a single page app running inside a wkwebview which is the popover of Safari app extension.
I need to communicate between my SafariExtensionViewController and this spa inside wkwebview.
I totally lost the idea of how to deal with it.
if you want to debug javascript code that wkwebview is presenting you need to go to Safari -> Preferences -> Advanced -> Show Develop Menu In Menu Bar
then a new tab will appear on Safari "Develop"
press on it and select the simulator or the device that your app is running on
(if you don't see any device or a simulator its because you ran Safari before the app was running. close it by left click -> close and open it again, it will work)
it will show you the html that the app is currently presenting.. press on it
the you have the option to debug your app, see logs/error on the console
hope I helped

Cocoa Swift: Connect Main Menu to Preferences Window Controller & Disabling Items like Minimise in Attributes Inspector doesn't work in Xcode?

I have a simple Menubar app in which it has 2 options - namely Preferences & Quit
After clicking on Preferences it opens a new window but doesn't show the menu bar
I tried connecting from Main Menu to the Window Controller but it doesn't work.
I drag it from the Application Name to the Window Controller or View Controller using Ctrl+Drag but still it doesn't work.
Another issue is my Preferences Window is resizing even though I unchecked the resize button in the Attributes Inspector.
Even Maximise & Minimise checkboxes are disabled but they are still showing.
Any solutions?
See NSApplication.activationPolicy.
If you want the app's main menu bar to appear, you'll need to change the activationPolicy to NSApplicationActivationPolicyRegular. Once you do that, the app's main menu will appear when your app is the active one. (It will also appear in the dock.)
If you want this to happen only when your preferences window is open, then you'll need to change the activationPolicy when the window opens, then set it back again when it closes.
You don't need to connect any outlets for this; the Main Menu should already be a resource for your app and should be loaded automatically when your app launches.
I think I had given Storyboard Id to my View Controller rather than my Window Controller so it wasn't working.
I also checked some apps like Dropbox which didn't have Main Menu Bar because it was a background or accessory app so I ditched it.
Some apps like Focus have it though. But I went with the popular choice.
As for no resizing, no minimising & no maximising goes, I pasted below code & it worked
var myWindow: NSWindow? = nil
myWindow?.styleMask.remove(NSWindow.StyleMask.resizable)
myWindow?.standardWindowButton(.miniaturizeButton)?.isEnabled=false
myWindow?.standardWindowButton(.zoomButton)?.isEnabled=false

Screenshot of currently running application on IPhone

On the IPhone, is it possible to get a screenshot of the currently running application, from another application that is running/backgrounded/being launched? or somehow make available a screenshot of the current application to another application that is then automatically launched?
No it is not possible. It is not possible to know anything about another apps in iOS (if you're using documented methods).
This is possible using Xcode's Organizer:
in Xcode, select "Window" menu and then "Organizer"
in the newOrganizer window, select "Devices"
select your iPhone device and unfold
select "Screenshots" at the bottom of the list
now click on the "New screenshot" button (bottom right of the window)
You can export screenshots just by drag/drop on your desktop.