Skip to content

Commit

Permalink
history_index -> frontmost_application_history_index
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Dec 4, 2024
1 parent 0aa48f7 commit b12b9a0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Fixed an overflow issue with the mouse key movements.
- Fixed an issue that the fn key is unintentionally tapped when use the media keys if "Use all F1, F2, etc. keys as standard function keys" is enabled.
- ✨ New Features
- Added `history_index` option into `open_application`.
- Added `frontmost_application_history_index` option into `open_application`.
- ⚡️ Improvements
- Support the following keys:
- consumer::ac_zoom_out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ class software_function_handler final : public pqrs::dispatcher::extra::dispatch
pqrs::osx::workspace::open_application_by_bundle_identifier(*v);
} else if (auto v = open_application.get_file_path()) {
pqrs::osx::workspace::open_application_by_file_path(*v);
} else if (auto v = open_application.get_history_index()) {
} else if (auto v = open_application.get_frontmost_application_history_index()) {
auto history_index = *v;

// If the number of applications specified by history_index does not exist, the oldest application will be selected.
// If the number of applications specified by frontmost_application_history_index does not exist, the oldest application will be selected.
std::optional<pqrs::osx::frontmost_application_monitor::application> target_application;

for (const auto& h : frontmost_application_history_) {
Expand Down
20 changes: 10 additions & 10 deletions src/share/types/software_function_details/open_application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ class open_application {
file_path_ = value;
}

const std::optional<size_t>& get_history_index(void) const {
return history_index_;
const std::optional<size_t>& get_frontmost_application_history_index(void) const {
return frontmost_application_history_index_;
}

void set_history_index(const std::optional<size_t>& value) {
history_index_ = value;
void set_frontmost_application_history_index(const std::optional<size_t>& value) {
frontmost_application_history_index_ = value;
}

constexpr bool operator==(const open_application&) const = default;

private:
std::optional<std::string> bundle_identifier_;
std::optional<std::string> file_path_;
std::optional<size_t> history_index_;
std::optional<size_t> frontmost_application_history_index_;
};

inline void to_json(nlohmann::json& json, const open_application& value) {
Expand All @@ -52,8 +52,8 @@ inline void to_json(nlohmann::json& json, const open_application& value) {
if (auto v = value.get_file_path()) {
json["file_path"] = *v;
}
if (auto v = value.get_history_index()) {
json["history_index"] = *v;
if (auto v = value.get_frontmost_application_history_index()) {
json["frontmost_application_history_index"] = *v;
}
}

Expand All @@ -67,9 +67,9 @@ inline void from_json(const nlohmann::json& json, open_application& value) {
} else if (k == "file_path") {
pqrs::json::requires_string(v, "`" + k + "`");
value.set_file_path(v.get<std::string>());
} else if (k == "history_index") {
} else if (k == "frontmost_application_history_index") {
pqrs::json::requires_number(v, "`" + k + "`");
value.set_history_index(v.get<size_t>());
value.set_frontmost_application_history_index(v.get<size_t>());
} else {
throw pqrs::json::unmarshal_error(fmt::format("unknown key: `{0}`", k));
}
Expand All @@ -86,7 +86,7 @@ struct hash<krbn::software_function_details::open_application> final {

pqrs::hash::combine(h, value.get_bundle_identifier());
pqrs::hash::combine(h, value.get_file_path());
pqrs::hash::combine(h, value.get_history_index());
pqrs::hash::combine(h, value.get_frontmost_application_history_index());

return h;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,11 @@
"input": {
"software_function": {
"open_application": {
"history_index": null
"frontmost_application_history_index": null
}
}
},
"error": "`software_function` error: `open_application` error: `history_index` must be number, but is `null`"
"error": "`software_function` error: `open_application` error: `frontmost_application_history_index` must be number, but is `null`"
},
{
"class": "event_definition",
Expand Down
4 changes: 2 additions & 2 deletions tests/src/types/src/software_function_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ void run_software_function_test(void) {

{
auto json = nlohmann::json::object({
{"history_index", 1},
{"frontmost_application_history_index", 1},
});

auto value = json.get<krbn::software_function_details::open_application>();
expect(1 == value.get_history_index());
expect(1 == value.get_frontmost_application_history_index());

expect(nlohmann::json(value) == json);
}
Expand Down

0 comments on commit b12b9a0

Please sign in to comment.