Skip to content

Commit

Permalink
Add libkrbn_services_core_daemons_enabled, libkrbn_services_core_agen…
Browse files Browse the repository at this point in the history
…ts_enabled
  • Loading branch information
tekezo committed Jun 24, 2024
1 parent f25790b commit e436a77
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/apps/SettingsWindow/src/ServicesMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ public class ServicesMonitor: ObservableObject {
}
}

timer?.fire()
// When updating Karabiner-Elements, after the new version is installed, the daemons, agents, and Settings will restart.
// To prevent alerts from appearing at that time, if the daemons or agents are enabled, wait for the timer to fire for the process startup check.
// If either the daemons or agents are not enabled, usually when the daemons are not approved, trigger the timer immediately after startup to show the alert right away.
if libkrbn_services_core_daemons_enabled() && libkrbn_services_core_agents_enabled() {
// Wait for the timer to fire.
} else {
timer?.fire()
}
}

public func stop() {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/libkrbn/include/libkrbn/libkrbn.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ void libkrbn_services_register_core_agents(void);
void libkrbn_services_bootout_old_agents(void);
void libkrbn_services_restart_console_user_server_agent(void);
void libkrbn_services_unregister_all_agents(void);
bool libkrbn_services_core_daemons_enabled(void);
bool libkrbn_services_core_agents_enabled(void);
bool libkrbn_services_daemon_running(const char* service_name);
bool libkrbn_services_agent_running(const char* service_name);
bool libkrbn_services_core_daemons_running(void);
Expand Down
8 changes: 8 additions & 0 deletions src/lib/libkrbn/src/libkrbn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ void libkrbn_services_unregister_all_agents(void) {
krbn::services_utility::unregister_all_agents();
}

bool libkrbn_services_core_daemons_enabled(void) {
return krbn::services_utility::core_daemons_enabled();
}

bool libkrbn_services_core_agents_enabled(void) {
return krbn::services_utility::core_agents_enabled();
}

bool libkrbn_services_daemon_running(const char* service_name) {
return krbn::services_utility::daemon_running(service_name);
}
Expand Down
14 changes: 14 additions & 0 deletions src/share/services_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ inline void unregister_all_agents(void) {
unregister_notification_window_agent();
}

inline bool core_daemons_enabled(void) {
auto exit_code = system(fmt::format("'{0}' core-daemons-enabled",
daemons_path)
.c_str());
return exit_code == 0;
}

inline bool core_agents_enabled(void) {
auto exit_code = system(fmt::format("'{0}' core-agents-enabled",
daemons_path)
.c_str());
return exit_code == 0;
}

inline bool daemon_running(const std::string& service_name) {
auto pid = pqrs::osx::launchctl::find_pid(pqrs::dispatcher::extra::get_shared_dispatcher(),
pqrs::osx::launchctl::make_system_domain_target(),
Expand Down

0 comments on commit e436a77

Please sign in to comment.