Skip to content

Commit

Permalink
Remove observeConsoleUserServerIsDisabledNotification
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed May 31, 2024
1 parent d0ccebf commit e9e50e0
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 158 deletions.
3 changes: 0 additions & 3 deletions src/apps/Menu/src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ public class AppDelegate: NSObject, NSApplicationDelegate {

libkrbn_initialize()

KarabinerAppHelper.shared.observeVersionUpdated()
KarabinerAppHelper.shared.observeConsoleUserServerIsDisabledNotification()

MenuController.shared.setup()
}

Expand Down
3 changes: 0 additions & 3 deletions src/apps/MultitouchExtension/src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public class AppDelegate: NSObject, NSApplicationDelegate {

libkrbn_initialize()

KarabinerAppHelper.shared.observeVersionUpdated()
KarabinerAppHelper.shared.observeConsoleUserServerIsDisabledNotification()

NSApplication.shared.disableRelaunchOnLogin()

//
Expand Down
3 changes: 0 additions & 3 deletions src/apps/NotificationWindow/src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ public class AppDelegate: NSObject, NSApplicationDelegate {

libkrbn_initialize()

// There is no need for Karabiner-NotificationWindow to relaunch itself, as it is restarted by launchd.
KarabinerAppHelper.shared.observeVersionUpdated(relaunch: false)

NotificationWindowManager.shared.start()
}

Expand Down
1 change: 0 additions & 1 deletion src/apps/SettingsWindow/src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class AppDelegate: NSObject, NSApplicationDelegate {
ProcessInfo.processInfo.enableSuddenTermination()

KarabinerAppHelper.shared.observeVersionUpdated()
KarabinerAppHelper.shared.observeConsoleUserServerIsDisabledNotification()

NotificationCenter.default.addObserver(
forName: Updater.didFindValidUpdate,
Expand Down
42 changes: 3 additions & 39 deletions src/apps/share/swift/KarabinerAppHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,12 @@ private func versionUpdatedCallbackRelaunch() {
Relauncher.relaunch()
}

private func versionUpdatedCallbackTerminate() {
NSApplication.shared.terminate(nil)
}

final class KarabinerAppHelper: NSObject {
final class KarabinerAppHelper {
public static let shared = KarabinerAppHelper()

func observeVersionUpdated() {
observeVersionUpdated(relaunch: true)
}

func observeVersionUpdated(relaunch: Bool) {
libkrbn_enable_version_monitor()
if relaunch {
libkrbn_register_version_updated_callback(versionUpdatedCallbackRelaunch)
} else {
libkrbn_register_version_updated_callback(versionUpdatedCallbackTerminate)
}
}

func observeConsoleUserServerIsDisabledNotification() {
var buffer = [Int8](repeating: 0, count: 32 * 1024)

libkrbn_get_distributed_notification_console_user_server_is_disabled(&buffer, buffer.count)
let name = String(cString: buffer)

libkrbn_get_distributed_notification_observed_object(&buffer, buffer.count)
let object = String(cString: buffer)

DistributedNotificationCenter.default().addObserver(
self,
selector: #selector(consoleUserServerIsDisabledCallback),
name: Notification.Name(name),
object: object,
suspensionBehavior: .deliverImmediately)
}

@objc
private func consoleUserServerIsDisabledCallback() {
Task { @MainActor in
print("console_user_server is disabled")
NSApplication.shared.terminate(self)
}
libkrbn_register_version_updated_callback(versionUpdatedCallbackRelaunch)
}

func endAllAttachedSheets(_ window: NSWindow) {
Expand All @@ -73,6 +36,7 @@ final class KarabinerAppHelper: NSObject {
}
} else {
libkrbn_services_unregister_all_agents()
libkrbn_killall_settings()
}
}
}
1 change: 0 additions & 1 deletion src/core/grabber/include/grabber/device_grabber.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "apple_notification_center.hpp"
#include "chrono_utility.hpp"
#include "components_manager_killer.hpp"
#include "constants.hpp"
Expand Down
5 changes: 1 addition & 4 deletions src/lib/libkrbn/include/libkrbn/libkrbn.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ void libkrbn_terminate(void);

void libkrbn_enqueue_callback(void (*callback)(void));

void libkrbn_get_distributed_notification_observed_object(char* buffer,
size_t length);
void libkrbn_get_distributed_notification_console_user_server_is_disabled(char* buffer,
size_t length);
void libkrbn_get_user_configuration_directory(char* buffer,
size_t length);
void libkrbn_get_user_complex_modifications_assets_directory(char* buffer,
Expand All @@ -51,6 +47,7 @@ bool libkrbn_services_grabber_daemon_running(void);

void libkrbn_launch_event_viewer(void);
void libkrbn_launch_settings(void);
void libkrbn_killall_settings(void);
void libkrbn_launch_multitouch_extension(void);
void libkrbn_launch_uninstaller(void);

Expand Down
14 changes: 4 additions & 10 deletions src/lib/libkrbn/src/libkrbn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ void libkrbn_enqueue_callback(void (*callback)(void)) {
}
}

void libkrbn_get_distributed_notification_observed_object(char* buffer,
size_t length) {
strlcpy(buffer, krbn::constants::get_distributed_notification_observed_object(), length);
}

void libkrbn_get_distributed_notification_console_user_server_is_disabled(char* buffer,
size_t length) {
strlcpy(buffer, krbn::constants::get_distributed_notification_console_user_server_is_disabled(), length);
}

void libkrbn_get_user_configuration_directory(char* buffer,
size_t length) {
strlcpy(buffer, krbn::constants::get_user_configuration_directory().c_str(), length);
Expand Down Expand Up @@ -162,6 +152,10 @@ void libkrbn_launch_settings(void) {
krbn::application_launcher::launch_settings();
}

void libkrbn_killall_settings(void) {
krbn::application_launcher::killall_settings();
}

void libkrbn_launch_multitouch_extension(void) {
krbn::application_launcher::launch_multitouch_extension(false);
}
Expand Down
85 changes: 0 additions & 85 deletions src/share/apple_notification_center.hpp

This file was deleted.

4 changes: 4 additions & 0 deletions src/share/application_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class application_launcher final {
system("open '/Applications/Karabiner-Elements.app'");
}

static void killall_settings(void) {
system("killall Karabiner-Elements");
}

static void launch_multitouch_extension(bool as_start_at_login) {
//
// Kill an existing process
Expand Down
8 changes: 0 additions & 8 deletions src/share/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,6 @@ class constants final {
return directory;
}

static const char* get_distributed_notification_observed_object(void) {
return "org.pqrs.karabiner";
}

static const char* get_distributed_notification_console_user_server_is_disabled(void) {
return "console_user_server_is_disabled";
}

static const size_t get_local_datagram_buffer_size(void) {
return 32 * 1024;
}
Expand Down
1 change: 0 additions & 1 deletion src/share/services_utility.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "apple_notification_center.hpp"
#include "constants.hpp"

namespace krbn {
Expand Down

0 comments on commit e9e50e0

Please sign in to comment.