Device battery indicators on your Lock Screen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 4 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* NSTask.h
  2. Copyright (c) 1996-2017, Apple Inc. All rights reserved.
  3. */
  4. #import <Foundation/NSObject.h>
  5. #import <Foundation/NSNotification.h>
  6. @class NSArray<ObjectType>, NSDictionary<KeyType, ObjectType>, NSString;
  7. NS_ASSUME_NONNULL_BEGIN
  8. typedef NS_ENUM(NSInteger, NSTaskTerminationReason) {
  9. NSTaskTerminationReasonExit = 1,
  10. NSTaskTerminationReasonUncaughtSignal = 2
  11. } NS_ENUM_AVAILABLE(10_6, NA);
  12. @interface NSTask : NSObject
  13. // Create an NSTask which can be run at a later time
  14. // An NSTask can only be run once. Subsequent attempts to
  15. // run an NSTask will raise.
  16. // Upon task death a notification will be sent
  17. // { Name = NSTaskDidTerminateNotification; object = task; }
  18. //
  19. - (instancetype)init NS_DESIGNATED_INITIALIZER;
  20. // these methods can only be set before a launch
  21. @property (nullable, copy) NSURL *executableURL API_AVAILABLE(macos(10.13)) API_UNAVAILABLE(ios, watchos, tvos);
  22. @property (nullable, copy) NSArray<NSString *> *arguments;
  23. @property (nullable, copy) NSDictionary<NSString *, NSString *> *environment; // if not set, use current
  24. @property (nullable, copy) NSURL *currentDirectoryURL API_AVAILABLE(macos(10.13)) API_UNAVAILABLE(ios, watchos, tvos);
  25. // standard I/O channels; could be either an NSFileHandle or an NSPipe
  26. @property (nullable, retain) id standardInput;
  27. @property (nullable, retain) id standardOutput;
  28. @property (nullable, retain) id standardError;
  29. // actions
  30. - (BOOL)launchAndReturnError:(out NSError **_Nullable)error API_AVAILABLE(macos(10.13)) API_UNAVAILABLE(ios, watchos, tvos);
  31. - (void)interrupt; // Not always possible. Sends SIGINT.
  32. - (void)terminate; // Not always possible. Sends SIGTERM.
  33. - (BOOL)suspend;
  34. - (BOOL)resume;
  35. // status
  36. @property (readonly) int processIdentifier;
  37. @property (readonly, getter=isRunning) BOOL running;
  38. @property (readonly) int terminationStatus;
  39. @property (readonly) NSTaskTerminationReason terminationReason API_AVAILABLE(macos(10.6)) API_UNAVAILABLE(ios, watchos, tvos);
  40. /*
  41. A block to be invoked when the process underlying the NSTask terminates. Setting the block to nil is valid, and stops the previous block from being invoked, as long as it hasn't started in any way. The NSTask is passed as the argument to the block so the block does not have to capture, and thus retain, it. The block is copied when set. Only one termination handler block can be set at any time. The execution context in which the block is invoked is undefined. If the NSTask has already finished, the block is executed immediately/soon (not necessarily on the current thread). If a terminationHandler is set on an NSTask, the NSTaskDidTerminateNotification notification is not posted for that task. Also note that -waitUntilExit won't wait until the terminationHandler has been fully executed. You cannot use this property in a concrete subclass of NSTask which hasn't been updated to include an implementation of the storage and use of it.
  42. */
  43. @property (nullable, copy) void (^terminationHandler)(NSTask *) API_AVAILABLE(macos(10.7)) API_UNAVAILABLE(ios, watchos, tvos);
  44. @property NSQualityOfService qualityOfService API_AVAILABLE(macos(10.10), ios(8.0), watchos(2.0), tvos(9.0)); // read-only after the task is launched
  45. @end
  46. @interface NSTask (NSTaskConveniences)
  47. + (nullable NSTask *)launchedTaskWithExecutableURL:(NSURL *)url arguments:(NSArray<NSString *> *)arguments error:(out NSError ** _Nullable)error terminationHandler:(void (^_Nullable)(NSTask *))terminationHandler API_AVAILABLE(macos(10.13)) API_UNAVAILABLE(ios, watchos, tvos);
  48. - (void)waitUntilExit;
  49. // poll the runLoop in defaultMode until task completes
  50. @end
  51. @interface NSTask (NSDeprecated)
  52. @property (nullable, copy) NSString *launchPath;
  53. @property (copy) NSString *currentDirectoryPath; // if not set, use current
  54. - (void)launch;
  55. + (NSTask *)launchedTaskWithLaunchPath:(NSString *)path arguments:(NSArray<NSString *> *)arguments;
  56. // convenience; create and launch
  57. @end
  58. FOUNDATION_EXPORT NSNotificationName const NSTaskDidTerminateNotification;
  59. NS_ASSUME_NONNULL_END