From 3644b56f9404112669ef0ed3b18b5c639d45bb50 Mon Sep 17 00:00:00 2001 From: Hootan Hemmati Date: Wed, 4 Sep 2024 01:01:38 +0330 Subject: [PATCH] Add keybinds to toggle configuration Fixes #1418 --- main/NekoGui_DataStore.hpp | 4 ++-- main/main.cpp | 1 + ui/dialog_hotkey.cpp | 2 ++ ui/mainwindow.cpp | 7 +++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/main/NekoGui_DataStore.hpp b/main/NekoGui_DataStore.hpp index ec0ff247c..616ba5e18 100644 --- a/main/NekoGui_DataStore.hpp +++ b/main/NekoGui_DataStore.hpp @@ -1,5 +1,3 @@ -// DO NOT INCLUDE THIS - namespace NekoGui { class Routing : public JsonStore { @@ -89,6 +87,7 @@ namespace NekoGui { bool flag_debug = false; bool flag_restart_tun_on = false; bool flag_reorder = false; + bool flag_toggle_config = false; // Pbac2 // Saved @@ -159,6 +158,7 @@ namespace NekoGui { QString hotkey_group = ""; QString hotkey_route = ""; QString hotkey_system_proxy_menu = ""; + QString hotkey_toggle_config = ""; // Pf754 // Core int core_box_clash_api = -9090; diff --git a/main/main.cpp b/main/main.cpp index b14f04f0e..d062aecef 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -91,6 +91,7 @@ int main(int argc, char* argv[]) { if (NekoGui::dataStore->argv.contains("-debug")) NekoGui::dataStore->flag_debug = true; if (NekoGui::dataStore->argv.contains("-flag_restart_tun_on")) NekoGui::dataStore->flag_restart_tun_on = true; if (NekoGui::dataStore->argv.contains("-flag_reorder")) NekoGui::dataStore->flag_reorder = true; + if (NekoGui::dataStore->argv.contains("-toggle_config")) NekoGui::dataStore->flag_toggle_config = true; #ifdef NKR_CPP_USE_APPDATA NekoGui::dataStore->flag_use_appdata = true; // Example: Package & MacOS #endif diff --git a/ui/dialog_hotkey.cpp b/ui/dialog_hotkey.cpp index d53278d0a..50cb3ff99 100644 --- a/ui/dialog_hotkey.cpp +++ b/ui/dialog_hotkey.cpp @@ -9,6 +9,7 @@ DialogHotkey::DialogHotkey(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog ui->show_groups->setKeySequence(NekoGui::dataStore->hotkey_group); ui->show_routes->setKeySequence(NekoGui::dataStore->hotkey_route); ui->system_proxy->setKeySequence(NekoGui::dataStore->hotkey_system_proxy_menu); + ui->toggle_config->setKeySequence(NekoGui::dataStore->hotkey_toggle_config); GetMainWindow()->RegisterHotkey(true); } @@ -18,6 +19,7 @@ DialogHotkey::~DialogHotkey() { NekoGui::dataStore->hotkey_group = ui->show_groups->keySequence().toString(); NekoGui::dataStore->hotkey_route = ui->show_routes->keySequence().toString(); NekoGui::dataStore->hotkey_system_proxy_menu = ui->system_proxy->keySequence().toString(); + NekoGui::dataStore->hotkey_toggle_config = ui->toggle_config->keySequence().toString(); NekoGui::dataStore->Save(); } GetMainWindow()->RegisterHotkey(false); diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index d7ed7c475..909e7fc2b 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -1724,6 +1724,7 @@ void MainWindow::RegisterHotkey(bool unregister) { NekoGui::dataStore->hotkey_group, NekoGui::dataStore->hotkey_route, NekoGui::dataStore->hotkey_system_proxy_menu, + NekoGui::dataStore->hotkey_toggle_config, }; for (const auto &key: regstr) { @@ -1754,6 +1755,12 @@ void MainWindow::HotkeyEvent(const QString &key) { on_menu_routing_settings_triggered(); } else if (key == NekoGui::dataStore->hotkey_system_proxy_menu) { ui->menu_spmode->popup(QCursor::pos()); + } else if (key == NekoGui::dataStore->hotkey_toggle_config) { + if (NekoGui::dataStore->started_id >= 0) { + neko_stop(); + } else { + neko_start(); + } } }); }