Release v0.3.0: move settings into an on-demand single-instance configurator
This commit is contained in:
+37
-2
@@ -1,6 +1,7 @@
|
||||
#include "app.h"
|
||||
#include "../resources/resource.h"
|
||||
#include "ocr.h"
|
||||
#include "configuration.h"
|
||||
#include <algorithm>
|
||||
#include <commctrl.h>
|
||||
#include <set>
|
||||
@@ -398,6 +399,18 @@ void App::reloadLayouts()
|
||||
}
|
||||
registerHotkeys(settings);
|
||||
}
|
||||
void App::clearHistory()
|
||||
{
|
||||
if (busy) throw std::runtime_error("Wait for the current operation to finish.");
|
||||
if (history) history->clear();
|
||||
if (historyWindow) refreshHistory(*this);
|
||||
}
|
||||
void App::setHotkeyCapture(HWND field)
|
||||
{
|
||||
hotkeyCapture = field;
|
||||
hotkeyCaptureProcess = 0;
|
||||
if (field) GetWindowThreadProcessId(field, &hotkeyCaptureProcess);
|
||||
}
|
||||
bool App::isHotkey(DWORD key, UINT mods)
|
||||
{
|
||||
for (auto &[id, text] : shortcuts(settings))
|
||||
@@ -496,6 +509,10 @@ bool App::handleKeyboard(const KBDLLHOOKSTRUCT &key, bool down, UINT mods)
|
||||
// down AND up events use exactly the same path as physical keyboard input.
|
||||
if (ownKeyboardInput(key) || installingUpdate)
|
||||
return false;
|
||||
DWORD captureProcess{};
|
||||
if (hotkeyCapture) GetWindowThreadProcessId(hotkeyCapture, &captureProcess);
|
||||
if (hotkeyCapture && (!captureProcess || captureProcess != hotkeyCaptureProcess))
|
||||
setHotkeyCapture(nullptr);
|
||||
if (hotkeyCapture && GetForegroundWindow() == GetAncestor(hotkeyCapture, GA_ROOT))
|
||||
{
|
||||
bool modifier = key.vkCode == VK_CONTROL || key.vkCode == VK_SHIFT || key.vkCode == VK_MENU ||
|
||||
@@ -579,6 +596,11 @@ void App::dispatch(int command)
|
||||
showSettings(*this);
|
||||
return;
|
||||
}
|
||||
if (command == 22)
|
||||
{
|
||||
showLogs(*this);
|
||||
return;
|
||||
}
|
||||
if (command == 21)
|
||||
{
|
||||
showSnippets(*this);
|
||||
@@ -1129,9 +1151,9 @@ void App::trayMenu()
|
||||
break;
|
||||
case 16:
|
||||
MessageBoxW(window,
|
||||
L"KSwitcher 0.2.2\nNative C++ / Win32 keyboard and clipboard utility\n\nBased on "
|
||||
(std::wstring(L"KSwitcher ") + AppVersion + L"\nNative C++ / Win32 keyboard and clipboard utility\n\nBased on "
|
||||
L"Typlo by bitcodepro. MIT license.\nHistory is encrypted for your Windows "
|
||||
L"account.\nNo .NET, WebView or graphics framework.",
|
||||
L"account.\nNo .NET, WebView or graphics framework.").c_str(),
|
||||
L"About KSwitcher", MB_OK);
|
||||
break;
|
||||
case 17:
|
||||
@@ -1165,6 +1187,11 @@ void App::trayMenu()
|
||||
void App::checkUpdate(bool interactive, bool install, const std::wstring &version)
|
||||
{
|
||||
if (updateRunning) return;
|
||||
if (install && FindWindowW(L"KSwitcher.Config", nullptr))
|
||||
{
|
||||
report(L"Close the configurator before installing an update.");
|
||||
return;
|
||||
}
|
||||
if (install && busy)
|
||||
{
|
||||
report(L"Wait for the current text operation to finish, then select Update again.");
|
||||
@@ -1284,6 +1311,11 @@ LRESULT CALLBACK App::windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
case WM_COPYDATA:
|
||||
{
|
||||
auto *data = (COPYDATASTRUCT *)lp;
|
||||
if (data && data->dwData >= ConfigRead && data->dwData < ConfigReply)
|
||||
{
|
||||
if (app->installingUpdate) return FALSE;
|
||||
return configurationRequest(*app, (HWND)wp, *data);
|
||||
}
|
||||
if (data && data->dwData == 1 && data->cbData == sizeof(int))
|
||||
{
|
||||
int cmd;
|
||||
@@ -1340,6 +1372,9 @@ LRESULT CALLBACK App::windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
DestroyWindow(hwnd);
|
||||
return 0;
|
||||
case WM_DESTROY:
|
||||
if (auto config = FindWindowW(L"KSwitcher.Config", nullptr);
|
||||
config && configurationPeer(config, L"KSwitcher.Config.exe"))
|
||||
PostMessageW(config, WM_CLOSE, 0, 0);
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user