Post

Replies

Boosts

Views

Activity

AppShortcutProvider does not launch the shortcut in macOS
I have created an intent using AppIntent and this intent(TWIntent in the code below) can be seen in the shortcuts app as an action to create the shortcut. I am using AppShortcutProvider to create the shortcut so that user can directly make use of it. However, my shortcut does not appear in the shortcut app. The phrases used also do not launch the intent in the spotlight search. Below is my AppShortcutProvider file: @available(macOS 13.0, *) struct TWShortcuts: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut( intent: TWIntent(), phrases: [ "Open Intent in \(.applicationName)", "Open \(.applicationName) Intent", "Open my Intent in \(.applicationName)", "Open my \(.applicationName) Intent", "Open TWIntent" ], shortTitle: "Open TWIntent", systemImageName: "rectangle.stack.fill" ) } static var shortcutTileColor: ShortcutTileColor = .lightBlue } Is there something I m missing? Also can these phrases be used for siri launch in macOS because the documentation mentions that macOS does not have siri capability? Below is my AppIntent file: import SwiftUI @available(macOS 13, *) struct TWIntent: AppIntent { static let title: LocalizedStringResource = "TWIntent" static var description = IntentDescription("try adding this sample action as your TW shortcut") //launch app on running action static var openAppWhenRun: Bool = false static var parameterSummary: some ParameterSummary { Summary("Get information on \(\.$TWType)") } @Parameter(title: "TWType", description: "The type to get information on.") var TWType: String func perform() async throws -> some IntentResult & ReturnsValue<String> & ProvidesDialog { //perform essential task here to update the application content return .result(value: TWType, dialog: "Logged a 15 minute break.\(TWType)") } }
0
0
491
May ’24
How does AppIntent changes get reflected in macOS
I have a basic Xcode project where I am adding a swift file with the below AppIntent. This causes the AppIntent action to be added in the Shortcuts app in MacOS. I wanted to know how is this AppIntent directly be able to add the Intent action in the shortcuts app. I have checked the build setting in the Xcode project but I did not find anything being generated that could have caused this. Can someone help me understand what internally happens that causes the action to be added to the shortcuts app? import AppIntents import SwiftUI @available(macOS 13, *) struct TWIntent: AppIntent { static let title: LocalizedStringResource = "TWMeditationIntent" static var description = IntentDescription("try adding this sample action as your TW shortcut") static var parameterSummary: some ParameterSummary { Summary("Get information on \(\.$TWType)") } // we can have multiple parameter of diff types @Parameter(title: "TWType", description: "The type to get information on.") var TWType: String func perform() async throws -> some IntentResult & ReturnsValue<String> & ProvidesDialog { NSLog(AppDelegate.TAG + "Inside perform() in MeditationIntent") return .result(value: TWType, dialog: "Logged a 15 minute break.\(TWType)") } }
0
3
437
Apr ’24
SA_RESETHAND flag in sigaction not working for swift exceptions
I have an exception handling frame for an Xcode application in macOS, which contains Cpp and Swift code. I am using the Unix signals frame for handling exceptions using sigaction. My sigaction signal handler get invoked when there is a swift or Cpp exception. However for some exceptions like SIGSEGV, the signal handler gets called repeatedly. To handle this I am using the SA_RESETHAND flag so that the handler gets invoked only once, and then the default action for the signal take over to terminate the process. This approach works well when an exception occurs due to Cpp code, however when it occurs due to Swift code, the signal handler still gets invoked repeatedly. Can someone explain why is this happening and What is the solution to this?
1
0
462
Apr ’24
How to use mach Exception handling
I wanted to perform handling for the exception in my mac and ios application, I am following this link, where it is suggested to follow either the mach exception handling or use Unix signals. I did not find many resources that could be followed to implement mach exception as suggested. Below are the few resources I could find. Can someone point to the some documentation that apple provides for this or some other helpful documentation. https://gist.github.com/rodionovd/01fff61927a665d78ecf
3
0
799
Apr ’24
Running .app bundled application in non GUI environment causing app to fail at runtime
I am having a bundled application(.app file) and I am wanting to run this application via ssh session which does not have GUI access. Launching this application in a desktop GUI session, runs the application perfectly. However, on running it on the same machine via ssh session produces an error. Note: My application does not bring up any GUI window(it' just produces some logs on the terminal), so running it in a non-GUI environment should have worked. I get the below error when trying to launch the unix exe in the .app bundle( ./Myapp.app/Contents/MacOS/Myapp ) on the terminal. I have observed that applicationDidFinishLaunching(_:) gets called and then the below error occurs. +[NSXPCSharedListener endpointForReply:withListenerName:replyErrorCode:]: an error occurred while attempting to obtain endpoint for listener 'ClientCallsAuxiliary': Connection interrupted I tried running other bundled applications via ssh, but all seems to produce the same error. Can someone confirm Is running bundled application in a non GUI session not allowed by Apple. If its allowed, how can I solve this? Even running the .app file using the open command fails to launch the application, although it produces a different error which is consistent across different applications.
1
0
525
Mar ’24
Expected behaviour for running a macOS bundled app as a daemon
I have a very basic macOS bundled application with just the empty delegate methods implemented. I want to run this application as a daemon, and so I have created the below daemon property list file. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.demo.GUIDaemon.plist</string> <key>RunAtLoad</key> <true/> <key>StandardErrorPath</key> <string>/Users/vipul.g/MySystemWorkspace/stderr.log</string> <key>StandardOutPath</key> <string>/Users/vipul.g/MySystemWorkspace/stdout.log</string> <key>Program</key> <string>/Users/vipul.g/Library/Developer/Xcode/DerivedData/Build/Products/Debug/GUIDaemon.app/Contents/MacOS/GUIDaemon</string> </dict> </plist> After loading the daemon, I can see the application running in the Activity monitor, but only the below delegates can be observed getting invoked in the logs. Other delegate like didBecomeActive, willResignActive are not being invoked. Is this the expected behaviour for launching a bundled application as daemon? Also there are some additional items logged, which I m not sure If they are denoting If something went wrong. Can someone confirm what should be expected? 024-03-14 18:09:59.452 GUIDaemon[45883:5345352] inside main.swift 2024-03-14 18:09:59.454 GUIDaemon[45883:5345352] applicationWillFinishLaunching(_:) 2024-03-14 18:09:59.567 GUIDaemon[45883:5345352] TISFileInterrogator updateSystemInputSources false but old data invalid: currentCacheHeaderPtr nonNULL? 0, ->cacheFormatVersion 0, ->magicCookie 00000000, inputSourceTableCountSys 0 Keyboard Layouts: duplicate keyboard layout identifier -17410. Keyboard Layouts: keyboard layout identifier -17410 has been replaced with -28673. Keyboard Layouts: duplicate keyboard layout identifier -30769. Keyboard Layouts: keyboard layout identifier -30769 has been replaced with -28674. Keyboard Layouts: duplicate keyboard layout identifier -14934. Keyboard Layouts: keyboard layout identifier -14934 has been replaced with -28675. 2024-03-14 18:09:59.664 GUIDaemon[45883:5345352] applicationDidFinishLaunching(_:)
0
0
319
Mar ’24
Unable to launch application as daemon in macOS
I have a very basic macOS bundled application with just the empty delegate methods implemented. I am wanting to launch this application as a daemon but when I am loading my daemon, it fails to run with the error: The application cannot be opened for an unexpected reason, error=Error Domain=NSCocoaErrorDomain Code=257 "The file “GUIDaemon” couldn’t be opened because you don’t have permission to view it." UserInfo={NSURL=file:///Users/vipul.g/Library/Developer/Xcode/DerivedData/Build/Products/Debug/GUIDaemon.app/, NSFilePath=/Users/vipul.g/Library/Developer/Xcode/DerivedData/Build/Products/Debug/GUIDaemon.app, NSUnderlyingError=0x600000034870 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}} Below is my daemon property list file. Can someone help what am I doing wrong here. I have made sure that my app has all the permission required. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.demo.GUIDaemonApp.plist</string> <key>RunAtLoad</key> <true/> <key>StandardErrorPath</key> <string>/Users/vipul.g/MySystemWorkspace/stderr.log</string> <key>StandardOutPath</key> <string>/Users/vipul.g/MySystemWorkspace/stdout.log</string> <key>ProgramArguments</key> <array> <string>/usr/bin/open</string> <string>/Users/vipul.g/Library/Developer/Xcode/DerivedData/Build/Products/Debug/GUIDaemon.app</string> </array> </dict> </plist>
0
0
300
Mar ’24
Adding intent to the AppIntentsExtension
I have added an "App Intents Extension" target to my main application in macOS. This generated the below two files: TWAppIntent.swift import AppIntents struct TWAppIntent: AppIntent { static var title: LocalizedStringResource = "TWAppIntent" static var parameterSummary: some ParameterSummary { Summary("Get information on \(\.$TWType)") } // we can have multiple parameter of diff types @Parameter(title: "TWType") var TWType: String func perform() async throws -> some IntentResult { return .result(dialog: "Executed TWAppIntent.") } } TWAppIntentExtension.swift import AppIntents @main struct TWAppIntentExtension: AppIntentsExtension { } I m able to build the extension target and I my intent action is available in the shortcuts app. However, on launching a shortcut with the above created intent action. I m getting the below popups: From what I understand, I m getting this error because I have not added my 'TWAppIntent' to the TWAppIntentExtension.swift file which is the entry point for the extension, but I could not find any documentation around how to add it. Can someone help on how to do it or Is there something else that I m doing wrong?
2
0
827
Feb ’24
Passing Cpp object to swift
I have a macOS app project implementing the direct Cpp-swift interop mechanism. The project some cpp classes and few Swift class. I wanted to pass a cpp object to a swift function as parameter, so I can use it in my swift code. But the documentation is not very clear on how to do this. Can some please share a code snippet explaining how can I achieve this? I have tried the below code, but it is giving linker error. Swift code: import StClass_modulemap public class SwiftClass { .. public static func getCppObj (pObj: inout StClass) -> Void { ... } } Cpp code: #include "Student.hpp" #include "StClass.hpp" #include <InteropLib-Swift.h> using namespace InteropLib; void Student::Introduce() { //creating cpp to be passed to swift // StClass StObj(50); // Teacher::getCppObj(StObj); std::cout<< "header included in hpp " <<std::endl; } calling Student::Introduce is giving a linker error for StClass
0
0
306
Feb ’24
Passing Swift String type to a Cpp function in the new interop
I have implemented the new cpp-swift interop mechanism using modulemap file. I have a use case to pass a swift string to the cpp function. I observed that the below code works and I am able to pass a swift String type directly to a cpp function which received it as const char *. This works only if its received as const char * in cpp(and not char *). However, this is not an interop documented behaviour for interoperating String types and wanted to know whether this is safe to use. If not, can someone suggest an alternative approach to pass a swift string to Cpp. // Swift code public static func StringToCharPointer () -&gt; Void { // calling cpp function and passing a swift String type as argument, which is received as const char * Student.Convert (sUItextdata) //sUItextdata is of type 'String' } //static Cpp function void Student::Convert (const char * pStr) { std::string s(pStr); std::cout &lt;&lt; "char * converted from swift String : " &lt;&lt; s &lt;&lt; std::endl; } Note : I am aware that there is a way to pass it to cpp and receive it as std:string, but I do not wish to use that.
1
0
618
Feb ’24
Swift extension method not accessible in Cpp using interop
I have a project implementing new interop mechanism and I m able to successfully invoke swift class method directly from swift. However, when I try to invoke the swift extension method it produces an error : No member named 'GetExtData' in 'InteropExtension::SwiftCode' Below is my cpp code: #include "CppSource.hpp" #include "InteropExtension-Swift.h" void CppSource::CppToSwiftCall() { // successfull call InteropExtension::SwiftCode::GetClassData(); //Below call is causing error. Why is swift extension method not invoked? InteropExtension::SwiftCode::GetExtData(); } Below is my swift code: import Foundation public class SwiftCode { public static func GetClassData () -&gt; String { return "classMethod" } } extension SwiftCode { public static func GetExtData () -&gt; String { return "ExtMethod" } } Can someone helpout on why is the extension methods not being invoked, and how can I invoke it?
1
2
548
Feb ’24
Can macOS dynamically change QoS value for pthreads
I have observed that in my application, Even If I set the QoS value of all the thread created to USER_INTERACTIVE, the OS is producing a warning "Thread running at User-Interactive QoS class waiting on a lower QoS thread running at Default QoS class. Investigate ways to avoid priority inversions". I am aware that it is not right to set all threads as USER_INTERACTIVE QoS, but If we assume this case for once, then it means that the OS can dynamically change the QoS of the threads even if we are explicitly setting it. Is this the correct understanding? Also, the main thread has QoS value USER_INTERACTIVE, then is it the case that its child threads will inherit the QoS value from the parent thread, If we are not setting any QoS for a pthread?
1
2
840
Jan ’24
QOS Class not getting set for pthread in macOS
I am building a macOS project where I m creating a thread using pthread in cpp. I am setting the QOS class using the pthread_attr_set_qos_class_np and later checking the value of the QOS class using the pthread_attr_get_qos_class_np. These calls are successful but the QOS class is not being set. Below is the cpp function that I m invoking from my swift code. bool CppThread::CreateThread () { pthread_t threadId; pthread_attr_t attr; qos_class_t qos_class; int relative_priority; int rc = pthread_attr_init(&attr); if (rc) { printf ("pthread_attr_init failed"); } if (pthread_attr_set_qos_class_np (&attr, QOS_CLASS_BACKGROUND, 5)) { printf ("pthread_attr_set_qos_class_np failed\n"); } int retval = pthread_create(&threadId, &attr, threadFunction, NULL); if (retval) { std::cerr << "Error creating thread" << std::endl; return false; } if (pthread_attr_get_qos_class_np (&attr, &qos_class, &relative_priority)) { printf ("pthread_attr_get_qos_class_np failed\n"); } printf ("QoS class: %d, Relative priority: %d\n", qos_class, relative_priority); pthread_join(threadId, NULL); // Wait for thread to finish std::cout << "Thread finished" << std::endl; return true; } OUTPUT: QoS class: 0, Relative priority: 0 Thread finished I have tried setting multiple QOS values but the output always shows the QOS class value as 0. Why is it not getting set?
0
0
340
Jan ’24
Type mismatch in SessionGetInfo() swift
The Apple documentation for SessionGetInfo for swift mentions that this API takes third argument of type UnsafeMutablePointer&lt;SessionAttributeBits&gt;? but I m getting the below error when I pass an argument of this type. Cannot convert value of type 'UnsafeMutablePointer&lt;SessionAttributeBits&gt;' to expected argument type 'UnsafeMutablePointer&lt;UInt32&gt;' Why is it expecting a different type. The documentation states otherwise. How to resolve this? Is this a Bug? public static func GetSessionInfo () -&gt; Void { var sessionID = SecuritySessionId() var sessionAttrs = SessionAttributeBits() let status = SessionGetInfo(callerSecuritySession, &amp;sessionID, &amp;sessionAttrs) //error:Cannot convert value of type 'UnsafeMutablePointer&lt;SessionAttributeBits&gt;' to expected argument type 'UnsafeMutablePointer&lt;UInt32&gt;' if status != errSessionSuccess { print("Could not get session info. Error \(status)") } }
6
0
776
Jan ’24