Add keybinds to toggle configuration

Fixes #1418
This commit is contained in:
Hootan Hemmati 2024-09-04 01:01:38 +03:30
parent 2a177256ce
commit 3644b56f94
4 changed files with 12 additions and 2 deletions

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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();
}
}
});
}