mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-08 06:31:50 +08:00
fixed helper tool:
used xpc communicate between gui and mhp made helper tool optional gave more feedback
This commit is contained in:
@@ -4,11 +4,9 @@
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>synmacph</string>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>LaunchOnlyOnce</key>
|
||||
<true/>
|
||||
<key>KeepAlive</key>
|
||||
<false/>
|
||||
</dict>
|
||||
<key>MachServices</key>
|
||||
<dict>
|
||||
<key>synmacph</key>
|
||||
<true/>
|
||||
</dict></dict>
|
||||
</plist>
|
||||
|
||||
@@ -19,16 +19,78 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <xpc/xpc.h>
|
||||
|
||||
const char* const label = "synmacph";
|
||||
|
||||
static void xpcEventHandler(xpc_connection_t connection, xpc_object_t event)
|
||||
{
|
||||
syslog(LOG_NOTICE, "received event in helper");
|
||||
|
||||
xpc_type_t type = xpc_get_type(event);
|
||||
|
||||
if (type == XPC_TYPE_ERROR) {
|
||||
if (event == XPC_ERROR_CONNECTION_INVALID) {
|
||||
// the client process on the other end of the connection has either
|
||||
// crashed or cancelled the connection. After receiving this error,
|
||||
// the connection is in an invalid state, and you do not need to
|
||||
// call xpc_connection_cancel(). Just tear down any associated state
|
||||
// here.
|
||||
}
|
||||
else if (event == XPC_ERROR_TERMINATION_IMMINENT) {
|
||||
// handle per-connection termination cleanup.
|
||||
}
|
||||
}
|
||||
else {
|
||||
xpc_connection_t remote = xpc_dictionary_get_remote_connection(event);
|
||||
|
||||
const char* command = xpc_dictionary_get_string(event, "request");
|
||||
syslog(LOG_NOTICE, "received command in helper: %s", command);
|
||||
system(command);
|
||||
|
||||
xpc_object_t reply = xpc_dictionary_create_reply(event);
|
||||
xpc_dictionary_set_string(reply, "reply", "command has been executed");
|
||||
xpc_connection_send_message(remote, reply);
|
||||
xpc_release(reply);
|
||||
}
|
||||
}
|
||||
|
||||
static void xpcConnectionHandler(xpc_connection_t connection)
|
||||
{
|
||||
syslog(LOG_NOTICE, "configuring message event handler for helper");
|
||||
|
||||
xpc_connection_set_event_handler(connection, ^(xpc_object_t event) {
|
||||
xpcEventHandler(connection, event);
|
||||
});
|
||||
|
||||
xpc_connection_resume(connection);
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
#pragma unused(argc)
|
||||
#pragma unused(argv)
|
||||
|
||||
system("sudo sqlite3 /Library/Application\\ Support/com.apple.TCC/TCC.db 'delete from access where client like \"%Synergy.app%\"'");
|
||||
#pragma unused(argc)
|
||||
#pragma unused(argv)
|
||||
|
||||
(void) sleep(10);
|
||||
xpc_connection_t service = xpc_connection_create_mach_service(
|
||||
label,
|
||||
dispatch_get_main_queue(),
|
||||
XPC_CONNECTION_MACH_SERVICE_LISTENER);
|
||||
|
||||
if (!service) {
|
||||
syslog(LOG_NOTICE, "failed to create service");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
syslog(LOG_NOTICE, "configuring connection event handler for helper");
|
||||
xpc_connection_set_event_handler(service, ^(xpc_object_t connection) {
|
||||
xpcConnectionHandler(connection);
|
||||
});
|
||||
|
||||
xpc_connection_resume(service);
|
||||
|
||||
dispatch_main();
|
||||
|
||||
xpc_release(service);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user