From cda1136aa5e6a8ecdef933e3ccf6294aa183fb99 Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Mon, 2 Dec 2024 22:21:08 +0900 Subject: [PATCH] Update vendor/cget --- .../osx/frontmost_application_monitor.hpp | 2 +- .../application.hpp | 36 ++++++++++++++++++- .../extra/nlohmann_json.hpp | 18 ++++++++++ .../frontmost_application_monitor/impl/impl.h | 6 +++- .../frontmost_application_monitor/monitor.hpp | 18 ++++++++-- ...RSOSXFrontmostApplicationMonitorImpl.swift | 31 ++++++++-------- 6 files changed, 91 insertions(+), 20 deletions(-) diff --git a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor.hpp b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor.hpp index 49ed91eb8..b12f7b5f4 100644 --- a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor.hpp +++ b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor.hpp @@ -1,6 +1,6 @@ #pragma once -// pqrs::osx::frontmost_application_monitor v5.0 +// pqrs::osx::frontmost_application_monitor v5.1 // (C) Copyright Takayama Fumihiko 2019. // Distributed under the Boost Software License, Version 1.0. diff --git a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/application.hpp b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/application.hpp index 6d2320d78..bfd6985f3 100644 --- a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/application.hpp +++ b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/application.hpp @@ -25,6 +25,15 @@ class application final { return *this; } + const std::optional& get_bundle_path(void) const { + return bundle_path_; + } + + application& set_bundle_path(const std::optional& value) { + bundle_path_ = value; + return *this; + } + const std::optional& get_file_path(void) const { return file_path_; } @@ -34,9 +43,20 @@ class application final { return *this; } + const std::optional& get_pid(void) const { + return pid_; + } + + application& set_pid(const std::optional& value) { + pid_ = value; + return *this; + } + bool operator==(const application& other) const { return bundle_identifier_ == other.bundle_identifier_ && - file_path_ == other.file_path_; + bundle_path_ == other.bundle_path_ && + file_path_ == other.file_path_ && + pid_ == other.pid_; } bool operator!=(const application& other) const { @@ -45,7 +65,9 @@ class application final { private: std::optional bundle_identifier_; + std::optional bundle_path_; std::optional file_path_; + std::optional pid_; }; } // namespace frontmost_application_monitor } // namespace osx @@ -63,12 +85,24 @@ struct hash final { pqrs::hash::combine(h, 0); } + if (auto& bundle_path = value.get_bundle_path()) { + pqrs::hash::combine(h, *bundle_path); + } else { + pqrs::hash::combine(h, 0); + } + if (auto& file_path = value.get_file_path()) { pqrs::hash::combine(h, *file_path); } else { pqrs::hash::combine(h, 0); } + if (auto& pid = value.get_pid()) { + pqrs::hash::combine(h, *pid); + } else { + pqrs::hash::combine(h, 0); + } + return h; } }; diff --git a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/extra/nlohmann_json.hpp b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/extra/nlohmann_json.hpp index 9a2cbe2a5..6ea3b7744 100644 --- a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/extra/nlohmann_json.hpp +++ b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/extra/nlohmann_json.hpp @@ -17,9 +17,17 @@ inline void to_json(nlohmann::json& j, const application& s) { j["bundle_identifier"] = *v; } + if (auto& v = s.get_bundle_path()) { + j["bundle_path"] = *v; + } + if (auto& v = s.get_file_path()) { j["file_path"] = *v; } + + if (auto& v = s.get_pid()) { + j["pid"] = *v; + } } inline void from_json(const nlohmann::json& j, application& s) { @@ -33,11 +41,21 @@ inline void from_json(const nlohmann::json& j, application& s) { s.set_bundle_identifier(value.get()); + } else if (key == "bundle_path") { + json::requires_string(value, "`"s + key + "`"); + + s.set_bundle_path(value.get()); + } else if (key == "file_path") { json::requires_string(value, "`"s + key + "`"); s.set_file_path(value.get()); + } else if (key == "pid") { + json::requires_number(value, "`"s + key + "`"); + + s.set_pid(value.get()); + } else { throw json::unmarshal_error("unknown key: `"s + key + "`"s); } diff --git a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/impl/impl.h b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/impl/impl.h index 8bfd3bb4c..9de17bd61 100644 --- a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/impl/impl.h +++ b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/impl/impl.h @@ -4,6 +4,8 @@ // Distributed under the Boost Software License, Version 1.0. // (See https://www.boost.org/LICENSE_1_0.txt) +#include + #ifdef __cplusplus extern "C" { #endif @@ -11,7 +13,9 @@ extern "C" { // Do not use these functions directly. typedef void (*pqrs_osx_frontmost_application_monitor_callback)(const char* bundle_identifier, - const char* file_path); + const char* bundle_path, + const char* file_path, + pid_t pid); void pqrs_osx_frontmost_application_monitor_set_callback(pqrs_osx_frontmost_application_monitor_callback callback); void pqrs_osx_frontmost_application_monitor_unset_callback(void); diff --git a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/monitor.hpp b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/monitor.hpp index ece0e95c8..e62cd6332 100644 --- a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/monitor.hpp +++ b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/include/pqrs/osx/frontmost_application_monitor/monitor.hpp @@ -62,23 +62,35 @@ class monitor final : public dispatcher::extra::dispatcher_client { private: static void static_cpp_callback(const char* bundle_identifier, - const char* file_path) { + const char* bundle_path, + const char* file_path, + pid_t pid) { auto m = shared_monitor_; if (m) { m->cpp_callback(bundle_identifier, - file_path); + bundle_path, + file_path, + pid); } } void cpp_callback(const char* bundle_identifier, - const char* file_path) { + const char* bundle_path, + const char* file_path, + pid_t pid) { auto application_ptr = std::make_shared(); if (bundle_identifier) { application_ptr->set_bundle_identifier(bundle_identifier); } + if (bundle_path) { + application_ptr->set_bundle_path(bundle_path); + } if (file_path) { application_ptr->set_file_path(file_path); } + if (pid) { + application_ptr->set_pid(pid); + } enqueue_to_dispatcher([this, application_ptr] { frontmost_application_changed(application_ptr); diff --git a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/src/pqrs/osx/frontmost_application_monitor/PQRSOSXFrontmostApplicationMonitorImpl.swift b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/src/pqrs/osx/frontmost_application_monitor/PQRSOSXFrontmostApplicationMonitorImpl.swift index e24fd68ae..24973f851 100644 --- a/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/src/pqrs/osx/frontmost_application_monitor/PQRSOSXFrontmostApplicationMonitorImpl.swift +++ b/src/vendor/cget/cget/pkg/pqrs-org__cpp-osx-frontmost_application_monitor/install/src/pqrs/osx/frontmost_application_monitor/PQRSOSXFrontmostApplicationMonitorImpl.swift @@ -33,10 +33,7 @@ private class PQRSOSXFrontmostApplicationMonitor { return } - let bundleIdentifier = runningApplication.bundleIdentifier ?? "" - let path = runningApplication.executableURL?.path ?? "" - - self.runCallback(bundleIdentifier: bundleIdentifier, path: path) + self.runCallback(runningApplication) } } @@ -52,14 +49,23 @@ private class PQRSOSXFrontmostApplicationMonitor { } } - func runCallback(bundleIdentifier: String, path: String) { + func runCallback(_ runningApplication: NSRunningApplication) { + let bundleIdentifier = runningApplication.bundleIdentifier ?? "" + let bundlePath = runningApplication.bundleURL?.path ?? "" + let filePath = runningApplication.executableURL?.path ?? "" + let processIdentifier = runningApplication.processIdentifier + lock.withLock { bundleIdentifier.utf8CString.withUnsafeBufferPointer { bundleIdentifierPtr in - path.utf8CString.withUnsafeBufferPointer { pathPtr in - callback?( - bundleIdentifierPtr.baseAddress, - pathPtr.baseAddress - ) + bundlePath.utf8CString.withUnsafeBufferPointer { bundlePathPtr in + filePath.utf8CString.withUnsafeBufferPointer { filePathPtr in + callback?( + bundleIdentifierPtr.baseAddress, + bundlePathPtr.baseAddress, + filePathPtr.baseAddress, + processIdentifier + ) + } } } } @@ -67,10 +73,7 @@ private class PQRSOSXFrontmostApplicationMonitor { func runCallbackWithFrontmostApplication() { if let runningApplication = NSWorkspace.shared.frontmostApplication { - let bundleIdentifier = runningApplication.bundleIdentifier ?? "" - let path = runningApplication.executableURL?.path ?? "" - - runCallback(bundleIdentifier: bundleIdentifier, path: path) + runCallback(runningApplication) } } }