Skip to content

Commit

Permalink
Move register_application("/Applications/Karabiner-Elements.app") to …
Browse files Browse the repository at this point in the history
…cli from karabiner_grabber
  • Loading branch information
tekezo committed May 5, 2024
1 parent f13d561 commit fcfcca4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 23 deletions.
14 changes: 12 additions & 2 deletions pkginfo/Scripts/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

# ------------------------------------------------------------
#
# Set suid
#

chmod 4755 '/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_session_monitor'

# ------------------------------------------------------------
#
# Register /Applications/Karabiner-Elements.app in the Launch Services database.
#

'/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli' --lsregister-karabiner-elements

#
# Relaunch karabiner processes
#

killall karabiner_grabber
killall karabiner_session_monitor
killall karabiner_console_user_server
killall Karabiner-NotificationWindow

#
# Update version file
#

cp \
'/Library/Application Support/org.pqrs/Karabiner-Elements/package-version' \
Expand Down
59 changes: 48 additions & 11 deletions src/bin/cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "run_loop_thread_utility.hpp"
#include <iostream>
#include <nlohmann/json.hpp>
#include <pqrs/osx/launch_services.hpp>
#include <pqrs/thread_wait.hpp>
#include <spdlog/sinks/stdout_color_sinks.h>

Expand Down Expand Up @@ -118,31 +119,57 @@ int main(int argc, char** argv) {
krbn::logger::set_stdout_color_logger("karabiner_cli",
"[%l] %v");

cxxopts::Options options("karabiner_cli", "A command line utility of Karabiner-Elements.");
cxxopts::Options options("karabiner_cli",
"A command line utility of Karabiner-Elements");

options.add_options()("select-profile",
"Select a profile by name", cxxopts::value<std::string>());

options.add_options()("show-current-profile-name",
"Show current profile name");

options.add_options()("list-profile-names",
"Show all profile names");

options.add_options()("set-variables",
"Json string: {[key: string]: number|boolean|string}",
cxxopts::value<std::string>());

options.add_options()("copy-current-profile-to-system-default-profile",
"Copy the current profile to system default profile");

options.add_options()("remove-system-default-profile",
"Remove the system default profile");

options.add_options()("select-profile", "Select a profile by name.", cxxopts::value<std::string>());
options.add_options()("show-current-profile-name", "Show current profile name");
options.add_options()("list-profile-names", "Show all profile names");
options.add_options()("set-variables", "Json string: {[key: string]: number|boolean|string}", cxxopts::value<std::string>());
options.add_options()("copy-current-profile-to-system-default-profile", "Copy the current profile to system default profile.");
options.add_options()("remove-system-default-profile", "Remove the system default profile.");
options.add_options()("lint-complex-modifications",
"Check complex_modifications.json",
cxxopts::value<std::vector<std::string>>(),
"glob-patterns");

options.add_options()("format-json",
"Format json files",
cxxopts::value<std::vector<std::string>>(),
"glob-patterns");

options.add_options()("eval-js",
"Run javascript files using Duktape",
cxxopts::value<std::vector<std::string>>(),
"glob-patterns");
options.add_options()("version", "Displays version.");
options.add_options()("version-number", "Displays version_number.");
options.add_options()("help", "Print help.");

options.add_options()("lsregister-karabiner-elements",
"Register Karabier-Elements.app in the Launch Services database");

options.add_options()("version",
"Displays version");

options.add_options()("version-number",
"Displays version_number");

options.add_options()("help",
"Print help");

options.add_options()("silent",
"Suppress messages.",
"Suppress messages",
cxxopts::value<bool>()->default_value("false"));

options.parse_positional({
Expand Down Expand Up @@ -308,6 +335,16 @@ int main(int argc, char** argv) {
}
}

{
std::string key = "lsregister-karabiner-elements";
if (parse_result.count(key)) {
auto status = pqrs::osx::launch_services::register_application("/Applications/Karabiner-Elements.app", false);
std::cout << fmt::format("{0}: {1}", key, status.to_string()) << std::endl;

goto finish;
}
}

{
std::string key = "version";
if (parse_result.count(key)) {
Expand Down
10 changes: 0 additions & 10 deletions src/core/grabber/include/grabber/main/daemon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "process_utility.hpp"
#include <iostream>
#include <mach/mach.h>
#include <pqrs/osx/launch_services.hpp>
#include <pqrs/osx/workspace.hpp>

namespace krbn {
Expand Down Expand Up @@ -66,15 +65,6 @@ int daemon(void) {
}
}

//
// Register /Applications/Karabiner-Elements.app to launch services
//

{
auto status = pqrs::osx::launch_services::register_application("/Applications/Karabiner-Elements.app");
logger::get_logger()->info("launch_services::register_application /Applications/Karabiner-Elements.app: {0}", status.to_string());
}

//
// Check Karabiner-Elements.app exists
//
Expand Down

0 comments on commit fcfcca4

Please sign in to comment.