Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: github-actions
labels: []
directory: /
target-branch: dev
schedule:
interval: weekly

- package-ecosystem: npm
labels: []
directory: /
target-branch: dev
schedule:
interval: weekly
22 changes: 22 additions & 0 deletions .github/workflows/build_pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build pull request

on:
workflow_dispatch:
pull_request:
branches:
- dev

jobs:
build:
name: Build
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: latest

- name: Build
run: xmake -y
30 changes: 30 additions & 0 deletions .github/workflows/open_pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Open a PR to main

on:
push:
branches:
- dev
workflow_dispatch:

env:
MESSAGE: Merge branch `${{ github.head_ref || github.ref_name }}` to `main`

permissions:
contents: write
pull-requests: write

jobs:
pull-request:
name: Open pull request
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Open pull request
uses: repo-sync/pull-request@v2
with:
destination_branch: 'main'
pr_title: 'chore: ${{ env.MESSAGE }}'
pr_body: 'This pull request will ${{ env.MESSAGE }}.'
pr_draft: true
55 changes: 55 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Release

on:
workflow_dispatch:
push:
branches:
- main
- dev

jobs:
release:
name: Release
permissions:
contents: write
packages: write
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: latest

- name: Build
run: xmake -y

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Install dependencies
run: npm install

- name: Release
uses: cycjimmy/semantic-release-action@v4
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build distribution packages
if: steps.release.outputs.new_release_published == 'true'
run: xmake build_dist

- name: Upload artifacts
if: steps.release.outputs.new_release_published == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release.outputs.new_release_git_tag }}
files: dist/*.7z
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ logs/
.cache
.xmake
build/
vcpkg_installed/
vcpkg_installed/
dist/
57 changes: 57 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"branches": [
"main",
{
"name": "dev",
"prerelease": true
}
],
"plugins": [
[
"@semantic-release/commit-analyzer", {
"releaseRules": [
{ "type": "fix", "release": "patch" },
{ "type": "feat", "release": "minor" },
{ "type": "perf", "release": "patch" },
{ "type": "build", "scope": "Needs bump", "release": "patch" }
]
}
],
[
"@semantic-release/release-notes-generator", {
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{ "type": "fix", "section": "🐛 Bug Fixes", "hidden": false },
{ "type": "feat", "section": "✨ New Features", "hidden": false },
{ "type": "perf", "section": "🔧 Improvements", "hidden": false },
{ "type": "build", "hidden": true }
]
}
}
],
"@semantic-release/changelog",
[
"@semantic-release/exec", {
"prepareCmd": "sed -i 's/set_version(\"[^\"]*\"/set_version(\"${nextRelease.version}\"/' xmake.lua"
}
],
[
"@semantic-release/git", {
"assets": ["CHANGELOG.md", "xmake.lua"],
"message": "chore: Release v${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
],
[
"@semantic-release/github", {
"successComment": false
}
],
[
"@cleyrop-org/semantic-release-backmerge", {
"backmergeBranches": [{"from": "main", "to": "dev"}],
"clearWorkspace": true
}
]
]
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## [0.1.2-dev.1](https://github.com/IMXEren/InterceptKeys/compare/v0.1.1...v0.1.2-dev.1) (2026-07-12)

### 🐛 Bug Fixes

* **ci:** pass -y to xmake to auto-install packages ([3e68b38](https://github.com/IMXEren/InterceptKeys/commit/3e68b385a82c7bcaf00eb4bd2c8d7a6ca6313618))
40 changes: 17 additions & 23 deletions Cli.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

#pragma once

#include "config.h"
#include "CLI11.hpp"
#include "CLI/CLI.hpp"
#include "Service.hpp"
#include "MapConfig.hpp"
#include "common.h"

#include <algorithm>
#include <filesystem>
#include <iostream>
#include <iterator>
#include <string>
#include <system_error>
Expand All @@ -21,7 +20,7 @@ class Cli {
std::error_code ec;
auto path = std::filesystem::canonical(config_path, ec);
if (ec) {
INTERCEPT_LOGE_N_ERR(gLogger, "Invalid path: '{}'. {}", config_path, ec.message());
INTERCEPT_LOGE_N_ERR(g_Logger, "Invalid path: '{}'. {}", config_path, ec.message());
return false;
}
return true;
Expand All @@ -43,7 +42,7 @@ class Cli {

gApp.add_flag("--status", status_flag, "Fetch the running status of InterceptKeysService.");
gApp.add_flag("--detect-keys-only", detect_keys_only_flag, "Helper to detect key clicks to find the necessary scancode.");
gApp.add_flag("--service", SERVICE_FLAG, "Run the interception as a service. Recommended after you've setup the map config.");
gApp.add_flag("--service", g_ServiceFlag, "Run the interception as a service. Recommended after you've setup the map config.");

std::filesystem::path log_directory = std::filesystem::current_path() / "logs";
auto logging_option = gApp.add_option("--logging", log_directory, "Enable logging")
Expand Down Expand Up @@ -73,7 +72,7 @@ class Cli {

try {
gApp.parse(argc, argv);
INTERCEPT_LOGD_N_OUT(gLogger, "Parsed args!");
INTERCEPT_LOG_DEBUG(g_Logger, "Parsed args!");
}
catch (const CLI::ParseError& e) {
int code = gApp.exit(e);
Expand All @@ -87,22 +86,22 @@ class Cli {
INTERCEPT_EPRINTLN("Failed to create log directory: {}. {}", log_directory.string(), ec.message());
exit(ec.value());
}
LOGGING_FLAG = true;
g_LoggingFlag = true;
initLogging(log_directory);
INTERCEPT_LOGD_N_OUT(gLogger, "Using log directory: {}", log_directory.string());
INTERCEPT_LOGD_N_OUT(g_Logger, "Using log directory: {}", log_directory.string());
}

for (auto& config_path : map_config) {
auto path = std::filesystem::canonical(config_path);
INTERCEPT_LOGD_N_OUT(gLogger, "Using map config: {}", path.string());
INTERCEPT_LOGD_N_OUT(g_Logger, "Using map config: {}", path.string());
config_path = path.string();
}

if (gApp.got_subcommand(install_command)) {
INTERCEPT_LOGD_N_OUTW(gLogger, "Installing InterceptKeysService...");
INTERCEPT_LOGD_N_OUTW(g_Logger, "Installing InterceptKeysService...");
std::vector<std::string> args = {};
args.push_back("--service");
if (LOGGING_FLAG) {
if (g_LoggingFlag) {
args.push_back(logging_option->get_name());
args.push_back(log_directory.string());
}
Expand All @@ -112,19 +111,19 @@ class Cli {
install(args);
}
else if (gApp.got_subcommand(start_command)) {
INTERCEPT_LOGD_N_OUT(gLogger, "Starting InterceptKeysService...");
INTERCEPT_LOGD_N_OUT(g_Logger, "Starting InterceptKeysService...");
start();
}
else if (gApp.got_subcommand(stop_command)) {
INTERCEPT_LOGD_N_OUT(gLogger, "Stopping InterceptKeysService...");
INTERCEPT_LOGD_N_OUT(g_Logger, "Stopping InterceptKeysService...");
stop();
}
else if (gApp.got_subcommand(restart_command)) {
INTERCEPT_LOGD_N_OUT(gLogger, "Restarting InterceptKeysService...");
INTERCEPT_LOGD_N_OUT(g_Logger, "Restarting InterceptKeysService...");
restart();
}
else if (gApp.got_subcommand(uninstall_command)) {
INTERCEPT_LOGD_N_OUT(gLogger, "Uninstalling InterceptKeysService...");
INTERCEPT_LOGD_N_OUT(g_Logger, "Uninstalling InterceptKeysService...");
uninstall();
}
else if (status_flag == true) {
Expand All @@ -134,41 +133,37 @@ class Cli {
}

int run = RUN_AS_CONSOLE;
if (SERVICE_FLAG)
if (g_ServiceFlag)
run = RUN_AS_SERVICE;

MapConfig mc(std::move(map_config));
mc.load_config();
return run;
}

[[noreturn]]
static void install(const std::vector<std::string>& exe_args) {
Service intercept_service;
BOOL ok = intercept_service.create_or_update_service(exe_args);
if (!ok) {
INTERCEPT_LOGE_N_ERR(gLogger, "Failed to install the service.");
INTERCEPT_LOGE_N_ERR(g_Logger, "Failed to install the service.");
exit(1);
}
ok = intercept_service.start_service();
exit(~ok);
}

[[noreturn]]
static void start() {
Service intercept_service;
BOOL ok = intercept_service.start_service();
exit(~ok);
}

[[noreturn]]
static void stop() {
Service intercept_service;
BOOL ok = intercept_service.stop_service();
exit(~ok);
}

[[noreturn]]
static void restart() {
Service intercept_service;
BOOL ok = intercept_service.stop_service();
Expand All @@ -179,12 +174,11 @@ class Cli {
exit(~ok);
}

[[noreturn]]
static void uninstall() {
Service intercept_service;
BOOL ok = intercept_service.delete_service();
exit(~ok);
}
};

inline Cli gCli;
inline Cli g_Cli;
Loading
Loading