1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2 * Permission is hereby granted, free of charge, to any person obtaining a copy
3 * of this software and associated documentation files (the "Software"), to
4 * deal in the Software without restriction, including without limitation the
5 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6 * sell copies of the Software, and to permit persons to whom the Software is
7 * furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 #include <TargetConditionals.h>
24 # include <CoreFoundation/CoreFoundation.h>
25 # include <ApplicationServices/ApplicationServices.h>
29 int uv__set_process_title(const char* title) {
33 typedef CFTypeRef (*LSGetCurrentApplicationASNType)(void);
34 typedef OSStatus (*LSSetApplicationInformationItemType)(int,
39 typedef CFDictionaryRef (*LSApplicationCheckInType)(int, CFDictionaryRef);
40 typedef OSStatus (*SetApplicationIsDaemonType)(int);
41 typedef void (*LSSetApplicationLaunchServicesServerConnectionStatusType)(
43 CFBundleRef launch_services_bundle;
44 LSGetCurrentApplicationASNType ls_get_current_application_asn;
45 LSSetApplicationInformationItemType ls_set_application_information_item;
46 CFStringRef* display_name_key;
48 CFStringRef display_name;
50 CFBundleRef hi_services_bundle;
51 LSApplicationCheckInType ls_application_check_in;
52 SetApplicationIsDaemonType set_application_is_daemon;
53 LSSetApplicationLaunchServicesServerConnectionStatusType
54 ls_set_application_launch_services_server_connection_status;
56 launch_services_bundle =
57 CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices"));
59 if (launch_services_bundle == NULL)
62 ls_get_current_application_asn = (LSGetCurrentApplicationASNType)
63 CFBundleGetFunctionPointerForName(launch_services_bundle,
64 CFSTR("_LSGetCurrentApplicationASN"));
66 if (ls_get_current_application_asn == NULL)
69 ls_set_application_information_item = (LSSetApplicationInformationItemType)
70 CFBundleGetFunctionPointerForName(launch_services_bundle,
71 CFSTR("_LSSetApplicationInformationItem"));
73 if (ls_set_application_information_item == NULL)
76 display_name_key = CFBundleGetDataPointerForName(launch_services_bundle,
77 CFSTR("_kLSDisplayNameKey"));
79 if (display_name_key == NULL || *display_name_key == NULL)
82 /* Black 10.9 magic, to remove (Not responding) mark in Activity Monitor */
84 CFBundleGetBundleWithIdentifier(CFSTR("com.apple.HIServices"));
85 if (hi_services_bundle == NULL)
88 set_application_is_daemon = CFBundleGetFunctionPointerForName(
90 CFSTR("SetApplicationIsDaemon"));
91 ls_application_check_in = CFBundleGetFunctionPointerForName(
92 launch_services_bundle,
93 CFSTR("_LSApplicationCheckIn"));
94 ls_set_application_launch_services_server_connection_status =
95 CFBundleGetFunctionPointerForName(
96 launch_services_bundle,
97 CFSTR("_LSSetApplicationLaunchServicesServerConnectionStatus"));
98 if (set_application_is_daemon == NULL ||
99 ls_application_check_in == NULL ||
100 ls_set_application_launch_services_server_connection_status == NULL) {
104 if (set_application_is_daemon(1) != noErr)
107 ls_set_application_launch_services_server_connection_status(0, NULL);
109 /* Check into process manager?! */
110 ls_application_check_in(-2,
111 CFBundleGetInfoDictionary(CFBundleGetMainBundle()));
113 display_name = CFStringCreateWithCString(NULL, title, kCFStringEncodingUTF8);
114 asn = ls_get_current_application_asn();
115 err = ls_set_application_information_item(-2, /* Magic value. */
121 return (err == noErr) ? 0 : -1;
122 #endif /* !TARGET_OS_IPHONE */