Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59d01375ff | ||
|
|
2ffee2f880 | ||
|
|
e5987dee22 | ||
|
|
77aa5b7894 |
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(KSwitcher VERSION 0.8.10 LANGUAGES C CXX RC)
|
||||
project(KSwitcher VERSION 0.8.11 LANGUAGES C CXX RC)
|
||||
if(NOT WIN32)
|
||||
message(FATAL_ERROR "KSwitcher uses native Windows APIs")
|
||||
endif()
|
||||
|
||||
@@ -46,20 +46,24 @@ Saving Settings now merges independent resident/editor changes. If the same fiel
|
||||
changed on both sides, choose whether to retain your draft without closing the
|
||||
window. Declining preserves all draft edits. No export/import workaround is needed.
|
||||
|
||||
## Custom shortcuts — v0.8.9
|
||||
## Custom shortcuts
|
||||
|
||||
In **Settings → Shortcuts → Custom shortcuts**, choose **Add shortcut…** and
|
||||
record a global key combination. **Launch app** can start the program each time
|
||||
or activate its last-used window and start it if closed. **Send text to app**
|
||||
inserts text into an editable Windows **Edit** or **RichEdit** field selected
|
||||
with the KSwitcher crosshair. Use **Apply** or **Save** to activate the rule.
|
||||
with the KSwitcher crosshair. **Open URL** opens an HTTP or HTTPS address in the
|
||||
default browser, Chrome, or a browser executable you choose. For Chrome, you can
|
||||
pick a profile from its standard data folder. Use **Apply** or **Save** to activate the rule.
|
||||
Custom shortcuts are stored on this PC.
|
||||
|
||||
**Українською.** У **Settings → Shortcuts → Custom shortcuts** натисніть
|
||||
**Add shortcut…** і запишіть глобальну комбінацію клавіш. **Launch app** запускає
|
||||
програму щоразу або активує її останнє використане вікно й запускає програму,
|
||||
якщо вона закрита. **Send text to app** вставляє текст у поле Windows **Edit**
|
||||
або **RichEdit**, вибране прицілом KSwitcher. Застосуйте зміни кнопкою **Apply**
|
||||
або **RichEdit**, вибране прицілом KSwitcher. **Open URL** відкриває адресу HTTP
|
||||
або HTTPS у типовому браузері, Chrome чи іншому вказаному браузері. Для Chrome
|
||||
можна вибрати профіль зі стандартної папки даних. Застосуйте зміни кнопкою **Apply**
|
||||
або **Save**. Власні шорткати зберігаються на цьому ПК.
|
||||
|
||||
## Mouse buttons for applications
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# Latest Windows release
|
||||
|
||||
## v0.8.11 — 2026-11-30
|
||||
|
||||
**Open URL** is a new action in **Settings → Shortcuts → Custom shortcuts**. Open an HTTP or HTTPS address in the default browser, Google Chrome, or another browser by picking its executable. Choose a Chrome profile from its standard data folder if needed. The shortcut editor uses a white content area and the same tinted footer style as Settings.
|
||||
|
||||
**Українською.** У **Settings → Shortcuts → Custom shortcuts** з’явилася дія **Open URL**. Відкривайте адреси HTTP або HTTPS у типовому браузері, Google Chrome або іншому браузері, вказавши його `.exe`. Для Chrome за потреби виберіть профіль зі стандартної папки даних. Редактор шорткатів має білу область вмісту й тонований футер у стилі Settings.
|
||||
|
||||
## v0.8.10 — 2026-11-30
|
||||
|
||||
After **Apply** saves your changes, Settings disables **Apply** and **Save** and offers **Close**, including when **Start with Windows** is enabled. A new edit enables the saving controls again.
|
||||
|
||||
@@ -1 +1 @@
|
||||
e5cb3913c815bbb91f1d455b78589a27dc9ca9fb1cab58d40ef003aad7182779 KSwitcher-win-x64.zip
|
||||
fbae717c7a2ea07f29bb4f034e7c7169d17eedfab425a8666e74de237f9a3fdb KSwitcher-win-x64.zip
|
||||
+78
-78
@@ -1,181 +1,181 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"version": "0.8.10",
|
||||
"files": [
|
||||
{
|
||||
"sha256": "51c2b60bd27676ef92c674033e0a7295ab666c95ec19f0514dc6e6af22787c43",
|
||||
"size": 3283456,
|
||||
"path": "KSwitcher.exe"
|
||||
"path": "KSwitcher.exe",
|
||||
"size": 3298816,
|
||||
"sha256": "5be88613e9e3b7cf7b8eddc78bd44e9cf54ae0e7f6b6ed329d8095c76d60a1ae"
|
||||
},
|
||||
{
|
||||
"sha256": "f3f9f375bde4afc5e0099fc6db5187e5d34e7a1bb4f98e27255b29a0aad36240",
|
||||
"size": 2870784,
|
||||
"path": "KSwitcher.Config.exe"
|
||||
"path": "KSwitcher.Config.exe",
|
||||
"size": 2889728,
|
||||
"sha256": "fb67fc2ac9e075a6925bb4aae0f772d2d4077d7adbc2a87508315cf9ba1ac73a"
|
||||
},
|
||||
{
|
||||
"sha256": "bf3c38225db36eb5f73ffb41da7b45094d5c41d08ca74c82dd7612ec563e779d",
|
||||
"size": 3200512,
|
||||
"path": "KSwitcher.Screenshot.exe"
|
||||
"path": "KSwitcher.Screenshot.exe",
|
||||
"size": 3209216,
|
||||
"sha256": "69c56f621be5c6ca9aaa98d98d892004141508067809c7a39511371bfd797e7a"
|
||||
},
|
||||
{
|
||||
"sha256": "3303797ea63154f9ec3ef302e792884abdaba87f174811cfcf91e1595bc1bfa6",
|
||||
"size": 6019072,
|
||||
"path": "KSwitcher.Files.exe"
|
||||
"path": "KSwitcher.Files.exe",
|
||||
"size": 6030336,
|
||||
"sha256": "7f0a12afe77c0ab5142700069c7bc360206bd00dc5fb5d1595502c66cfacb637"
|
||||
},
|
||||
{
|
||||
"sha256": "d3fce90bdeecb08596e377dea6a316354dd8949e32ff09b89d51be00c14e21b6",
|
||||
"path": "WebView2Loader.dll",
|
||||
"size": 194912,
|
||||
"path": "WebView2Loader.dll"
|
||||
"sha256": "d3fce90bdeecb08596e377dea6a316354dd8949e32ff09b89d51be00c14e21b6"
|
||||
},
|
||||
{
|
||||
"sha256": "e256f01188af527e4d06d21d06fbf785ae9c50d4b328bf03cbe0ba7f0aa4228f",
|
||||
"path": "terminal/addon-fit-LICENSE.txt",
|
||||
"size": 1103,
|
||||
"path": "terminal/addon-fit-LICENSE.txt"
|
||||
"sha256": "e256f01188af527e4d06d21d06fbf785ae9c50d4b328bf03cbe0ba7f0aa4228f"
|
||||
},
|
||||
{
|
||||
"sha256": "ba3ea256ce0620a0992a197d6c9baea64823fc93d8da07a9e366ca9943c18527",
|
||||
"path": "terminal/addon-fit.js",
|
||||
"size": 1521,
|
||||
"path": "terminal/addon-fit.js"
|
||||
"sha256": "ba3ea256ce0620a0992a197d6c9baea64823fc93d8da07a9e366ca9943c18527"
|
||||
},
|
||||
{
|
||||
"sha256": "084d97a727b778fb10d31adcd557ee7840a38377ed60e0ef0f3ece93b349b1ef",
|
||||
"path": "terminal/index.html",
|
||||
"size": 527,
|
||||
"path": "terminal/index.html"
|
||||
"sha256": "084d97a727b778fb10d31adcd557ee7840a38377ed60e0ef0f3ece93b349b1ef"
|
||||
},
|
||||
{
|
||||
"sha256": "792c48c5a849a15fdf9e37e8bcf9e6d1dd13b32b46c642a748a0a46a9919d473",
|
||||
"path": "terminal/markdown-it-LICENSE.txt",
|
||||
"size": 1073,
|
||||
"path": "terminal/markdown-it-LICENSE.txt"
|
||||
"sha256": "792c48c5a849a15fdf9e37e8bcf9e6d1dd13b32b46c642a748a0a46a9919d473"
|
||||
},
|
||||
{
|
||||
"sha256": "391f2aa638e75e6c7859d0a5c5650ef0956722a45998f17e05b83bc655778e1e",
|
||||
"path": "terminal/markdown-it.js",
|
||||
"size": 100786,
|
||||
"path": "terminal/markdown-it.js"
|
||||
"sha256": "391f2aa638e75e6c7859d0a5c5650ef0956722a45998f17e05b83bc655778e1e"
|
||||
},
|
||||
{
|
||||
"sha256": "98984c8f76bd231dab00ef54034bfc2f29b365ee0b31c05edb16ad5216bd5bc2",
|
||||
"path": "terminal/markdown.html",
|
||||
"size": 3800,
|
||||
"path": "terminal/markdown.html"
|
||||
"sha256": "98984c8f76bd231dab00ef54034bfc2f29b365ee0b31c05edb16ad5216bd5bc2"
|
||||
},
|
||||
{
|
||||
"sha256": "8b5429a035ce8ce11f77a222b5ee946844fd1e2999e1bb5c8f7c030ddbb1ff96",
|
||||
"path": "terminal/markdown.js",
|
||||
"size": 18721,
|
||||
"path": "terminal/markdown.js"
|
||||
"sha256": "8b5429a035ce8ce11f77a222b5ee946844fd1e2999e1bb5c8f7c030ddbb1ff96"
|
||||
},
|
||||
{
|
||||
"sha256": "ec9fb67dcb25eccc416ed56e1aab819222c805a2a4bfe4cb19e7556bf2ffde80",
|
||||
"path": "terminal/mermaid-LICENSE.txt",
|
||||
"size": 1089,
|
||||
"path": "terminal/mermaid-LICENSE.txt"
|
||||
"sha256": "ec9fb67dcb25eccc416ed56e1aab819222c805a2a4bfe4cb19e7556bf2ffde80"
|
||||
},
|
||||
{
|
||||
"sha256": "336df803d87a38b70a01e736e666c8f7601d2ce42f5e47c8fafe5d721074b9a3",
|
||||
"path": "terminal/mermaid.js",
|
||||
"size": 5537838,
|
||||
"path": "terminal/mermaid.js"
|
||||
"sha256": "336df803d87a38b70a01e736e666c8f7601d2ce42f5e47c8fafe5d721074b9a3"
|
||||
},
|
||||
{
|
||||
"sha256": "838707e2813f7d007f7f60670a78ae4a4a6c97ca9a235d623cb85e16dc50e0c7",
|
||||
"path": "terminal/terminal.js",
|
||||
"size": 6627,
|
||||
"path": "terminal/terminal.js"
|
||||
"sha256": "838707e2813f7d007f7f60670a78ae4a4a6c97ca9a235d623cb85e16dc50e0c7"
|
||||
},
|
||||
{
|
||||
"sha256": "b569f629d00f2626a8100df2a1798210535621e42164dfd426a6fe5aac7b0ccd",
|
||||
"path": "terminal/xterm-LICENSE.txt",
|
||||
"size": 1261,
|
||||
"path": "terminal/xterm-LICENSE.txt"
|
||||
"sha256": "b569f629d00f2626a8100df2a1798210535621e42164dfd426a6fe5aac7b0ccd"
|
||||
},
|
||||
{
|
||||
"sha256": "854a7c0fb70e8b1a083c16797ab827299fb18744f5ad34f227b48337e33293c6",
|
||||
"path": "terminal/xterm.css",
|
||||
"size": 7112,
|
||||
"path": "terminal/xterm.css"
|
||||
"sha256": "854a7c0fb70e8b1a083c16797ab827299fb18744f5ad34f227b48337e33293c6"
|
||||
},
|
||||
{
|
||||
"sha256": "14903579ff54664cd72f8e8699e6961a6272c21863ec1c3b118cdc8af5d4a972",
|
||||
"path": "terminal/xterm.js",
|
||||
"size": 488663,
|
||||
"path": "terminal/xterm.js"
|
||||
"sha256": "14903579ff54664cd72f8e8699e6961a6272c21863ec1c3b118cdc8af5d4a972"
|
||||
},
|
||||
{
|
||||
"sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c",
|
||||
"path": "LICENSE",
|
||||
"size": 4401,
|
||||
"path": "LICENSE"
|
||||
"sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c"
|
||||
},
|
||||
{
|
||||
"sha256": "61e08da79c44061654015ce6b0c4061c23ee1dd18237fbf09e9bfda3c0ea2831",
|
||||
"path": "json-LICENSE.txt",
|
||||
"size": 1096,
|
||||
"path": "json-LICENSE.txt"
|
||||
"sha256": "61e08da79c44061654015ce6b0c4061c23ee1dd18237fbf09e9bfda3c0ea2831"
|
||||
},
|
||||
{
|
||||
"sha256": "185c5a37521316e940ead89cbf0b1ba5862d810c7c966e6c6a14a4a515b23625",
|
||||
"path": "files-text-license.txt",
|
||||
"size": 883,
|
||||
"path": "files-text-license.txt"
|
||||
"sha256": "185c5a37521316e940ead89cbf0b1ba5862d810c7c966e6c6a14a4a515b23625"
|
||||
},
|
||||
{
|
||||
"sha256": "57d6d9b1f85ac93b3bc73f6f7bdf4346e896c4644d6fa461c380ae29070c029d",
|
||||
"path": "files-archive-license.txt",
|
||||
"size": 4990,
|
||||
"path": "files-archive-license.txt"
|
||||
"sha256": "57d6d9b1f85ac93b3bc73f6f7bdf4346e896c4644d6fa461c380ae29070c029d"
|
||||
},
|
||||
{
|
||||
"sha256": "7997c62a2f766674ceb99976485a6cf5c772309e79101a400c421d526b82f6e4",
|
||||
"path": "files-image-license.txt",
|
||||
"size": 3044,
|
||||
"path": "files-image-license.txt"
|
||||
"sha256": "7997c62a2f766674ceb99976485a6cf5c772309e79101a400c421d526b82f6e4"
|
||||
},
|
||||
{
|
||||
"sha256": "19c254c71ee49aefbd8854ac55b05d719c5f1e4f8ef9a982324b898501b39594",
|
||||
"path": "files-sftp-license.txt",
|
||||
"size": 2064,
|
||||
"path": "files-sftp-license.txt"
|
||||
"sha256": "19c254c71ee49aefbd8854ac55b05d719c5f1e4f8ef9a982324b898501b39594"
|
||||
},
|
||||
{
|
||||
"sha256": "a71afa4f0c1bd4d676b5fc261f1e5436752f6a1af3ae77068ad35803d615e9e3",
|
||||
"size": 107765,
|
||||
"path": "README.md"
|
||||
"path": "README.md",
|
||||
"size": 108205,
|
||||
"sha256": "d9a53cb9190dfde2415df54c131b8bd293efbd627014a4e0976cea717ae855ae"
|
||||
},
|
||||
{
|
||||
"sha256": "4eac1f410e6b544aa45756e24f4fdfe9193c6f732410656160be54ab27a0d7e4",
|
||||
"path": "LAN-PREVIEW.md",
|
||||
"size": 17245,
|
||||
"path": "LAN-PREVIEW.md"
|
||||
"sha256": "4eac1f410e6b544aa45756e24f4fdfe9193c6f732410656160be54ab27a0d7e4"
|
||||
},
|
||||
{
|
||||
"sha256": "d0c022b27b9fbc2ff7b6b8bec723cc1adc4eef517202f9ff77eed5d8bea3acb9",
|
||||
"path": "dictionaries/en.txt",
|
||||
"size": 732485,
|
||||
"path": "dictionaries/en.txt"
|
||||
"sha256": "d0c022b27b9fbc2ff7b6b8bec723cc1adc4eef517202f9ff77eed5d8bea3acb9"
|
||||
},
|
||||
{
|
||||
"sha256": "0bdfb0201d1803634f268cdff0993b8349d2c70e956a06dbb667c8dd65254ec5",
|
||||
"path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt",
|
||||
"size": 20566,
|
||||
"path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt"
|
||||
"sha256": "0bdfb0201d1803634f268cdff0993b8349d2c70e956a06dbb667c8dd65254ec5"
|
||||
},
|
||||
{
|
||||
"sha256": "3017bf44d3be9d9dfab21bd6778aa52b7947e61acf9ce2bc86b41d6e949ac311",
|
||||
"path": "dictionaries/README.md",
|
||||
"size": 2265,
|
||||
"path": "dictionaries/README.md"
|
||||
"sha256": "3017bf44d3be9d9dfab21bd6778aa52b7947e61acf9ce2bc86b41d6e949ac311"
|
||||
},
|
||||
{
|
||||
"sha256": "80e6b6a27815973535f7facb636c597eb845dfee45cfabfc4e9b3341b9332849",
|
||||
"path": "dictionaries/ru.txt",
|
||||
"size": 1109134,
|
||||
"path": "dictionaries/ru.txt"
|
||||
"sha256": "80e6b6a27815973535f7facb636c597eb845dfee45cfabfc4e9b3341b9332849"
|
||||
},
|
||||
{
|
||||
"sha256": "98e5b3fe7304e37705c9e5ff48b0b399ccb16e806736d21f09921b99e5f2a408",
|
||||
"path": "dictionaries/sources.json",
|
||||
"size": 1280,
|
||||
"path": "dictionaries/sources.json"
|
||||
"sha256": "98e5b3fe7304e37705c9e5ff48b0b399ccb16e806736d21f09921b99e5f2a408"
|
||||
},
|
||||
{
|
||||
"sha256": "d30e990d6ec2983c04f3644a3c61c6c668e8c542323f5931916fdd55b916eebf",
|
||||
"path": "dictionaries/uk.txt",
|
||||
"size": 940799,
|
||||
"path": "dictionaries/uk.txt"
|
||||
"sha256": "d30e990d6ec2983c04f3644a3c61c6c668e8c542323f5931916fdd55b916eebf"
|
||||
},
|
||||
{
|
||||
"sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a",
|
||||
"path": "tools/README.txt",
|
||||
"size": 993,
|
||||
"path": "tools/README.txt"
|
||||
"sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a"
|
||||
},
|
||||
{
|
||||
"sha256": "500c399c5bfdf0ba6ff61986cf9cb25d32394c2d4ff9e3304884d372fbff435d",
|
||||
"path": "tools/StayHere.exe",
|
||||
"size": 133120,
|
||||
"path": "tools/StayHere.exe"
|
||||
"sha256": "465450da62ad16c1c89e3a6cf79435d1fa06c5e347f5149b9825297c6196c5e8"
|
||||
},
|
||||
{
|
||||
"sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413",
|
||||
"path": "tools/StayHere-README.md",
|
||||
"size": 2796,
|
||||
"path": "tools/StayHere-README.md"
|
||||
"sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413"
|
||||
}
|
||||
]
|
||||
],
|
||||
"version": "0.8.11",
|
||||
"schema": 1
|
||||
}
|
||||
+3
-3
@@ -14,8 +14,8 @@ IDC_SCREENSHOT_PENCIL CURSOR "icons/lucide/pencil.cur"
|
||||
1 RT_MANIFEST "app.manifest"
|
||||
201 RCDATA "update.ps1"
|
||||
1 VERSIONINFO
|
||||
FILEVERSION 0,8,10,0
|
||||
PRODUCTVERSION 0,8,10,0
|
||||
FILEVERSION 0,8,11,0
|
||||
PRODUCTVERSION 0,8,11,0
|
||||
FILEOS VOS_NT_WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
BEGIN
|
||||
@@ -25,7 +25,7 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "FileDescription", "KSwitcher — native keyboard and clipboard utility"
|
||||
VALUE "ProductName", "KSwitcher"
|
||||
VALUE "FileVersion", "0.8.10"
|
||||
VALUE "FileVersion", "0.8.11"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
@@ -3731,6 +3731,12 @@ LRESULT CALLBACK App::windowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if (app->installingUpdate || app->busy || app->hotkeyCapture || index >= app->settings.customShortcuts.size()) return 0;
|
||||
const auto &rule = app->settings.customShortcuts[index];
|
||||
if (!rule.enabled || Hotkey::parse(rule.shortcut) != Hotkey{LOWORD(lp), HIWORD(lp)}) return 0;
|
||||
if (rule.action == CustomShortcutAction::OpenUrl)
|
||||
{
|
||||
if (!openShortcutUrl(rule))
|
||||
app->report(L"Could not open the URL for " + rule.name + L". Check the configured browser and profile.");
|
||||
return 0;
|
||||
}
|
||||
if (rule.action == CustomShortcutAction::SendText)
|
||||
{
|
||||
const auto target = shortcutAppWindow(rule.executable, app->recentForegroundWindows);
|
||||
|
||||
+5
-1
@@ -82,7 +82,8 @@ struct MouseAction
|
||||
int volumeStep = DefaultMouseVolumeStep;
|
||||
bool operator==(const MouseAction &) const = default;
|
||||
};
|
||||
enum class CustomShortcutAction { LaunchApp, SendText };
|
||||
enum class CustomShortcutAction { LaunchApp, SendText, OpenUrl };
|
||||
enum class ShortcutBrowser { Default, Chrome, Other };
|
||||
struct CustomShortcut
|
||||
{
|
||||
std::wstring name, shortcut, executable;
|
||||
@@ -91,6 +92,9 @@ struct CustomShortcut
|
||||
CustomShortcutAction action = CustomShortcutAction::LaunchApp;
|
||||
std::wstring controlClass, text;
|
||||
int controlId = 0;
|
||||
std::wstring url;
|
||||
ShortcutBrowser browser = ShortcutBrowser::Default;
|
||||
std::wstring chromeProfile;
|
||||
bool operator==(const CustomShortcut &) const = default;
|
||||
};
|
||||
struct Settings
|
||||
|
||||
+120
-7
@@ -1,4 +1,5 @@
|
||||
#include "platform.h"
|
||||
#include "windows_command_line.h"
|
||||
#include "../vendor/json.hpp"
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
@@ -17,6 +18,7 @@
|
||||
#include <shldisp.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <wincrypt.h>
|
||||
#include <winhttp.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
namespace ks
|
||||
@@ -348,9 +350,10 @@ std::wstring mouseApplicationName(HWND window)
|
||||
}, reinterpret_cast<LPARAM>(&hosted));
|
||||
return hosted.empty() ? name : hosted;
|
||||
}
|
||||
bool launchThroughExplorer(const std::wstring &path)
|
||||
namespace
|
||||
{
|
||||
bool shellOpenThroughExplorer(const std::wstring &target, const std::wstring &arguments, const std::wstring &directory)
|
||||
{
|
||||
const auto directory = std::filesystem::path(path).parent_path().wstring();
|
||||
HANDLE token{};
|
||||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) return false;
|
||||
TOKEN_ELEVATION elevation{};
|
||||
@@ -362,7 +365,8 @@ bool launchThroughExplorer(const std::wstring &path)
|
||||
{
|
||||
SHELLEXECUTEINFOW launch{sizeof(launch)};
|
||||
launch.fMask = SEE_MASK_FLAG_NO_UI;
|
||||
launch.lpFile = path.c_str();
|
||||
launch.lpFile = target.c_str();
|
||||
launch.lpParameters = arguments.empty() ? nullptr : arguments.c_str();
|
||||
launch.lpDirectory = directory.empty() ? nullptr : directory.c_str();
|
||||
launch.nShow = SW_SHOWNORMAL;
|
||||
return ShellExecuteExW(&launch) != FALSE;
|
||||
@@ -410,17 +414,126 @@ bool launchThroughExplorer(const std::wstring &path)
|
||||
hr = application->QueryInterface(IID_IShellDispatch2, reinterpret_cast<void **>(&shellRaw));
|
||||
std::unique_ptr<IShellDispatch2, decltype(release)> shell(shellRaw, release);
|
||||
if (FAILED(hr) || !shell) return false;
|
||||
std::unique_ptr<OLECHAR, decltype(&SysFreeString)> executable(SysAllocString(path.c_str()), SysFreeString);
|
||||
std::unique_ptr<OLECHAR, decltype(&SysFreeString)> executable(SysAllocString(target.c_str()), SysFreeString);
|
||||
std::unique_ptr<OLECHAR, decltype(&SysFreeString)> workingDirectory(SysAllocString(directory.c_str()), SysFreeString);
|
||||
if (!executable || !workingDirectory) return false;
|
||||
VARIANT location{}, shown{};
|
||||
std::unique_ptr<OLECHAR, decltype(&SysFreeString)> parameters(SysAllocString(arguments.c_str()), SysFreeString);
|
||||
if (!executable || !workingDirectory || !parameters) return false;
|
||||
VARIANT location{}, shown{}, args{};
|
||||
location.vt = VT_BSTR;
|
||||
location.bstrVal = workingDirectory.get();
|
||||
shown.vt = VT_I4;
|
||||
shown.lVal = SW_SHOWNORMAL;
|
||||
hr = shell->ShellExecute(executable.get(), empty, location, empty, shown);
|
||||
args.vt = VT_BSTR;
|
||||
args.bstrVal = parameters.get();
|
||||
hr = shell->ShellExecute(executable.get(), args, location, empty, shown);
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
std::filesystem::path shortcutKnownFolder(REFKNOWNFOLDERID folder)
|
||||
{
|
||||
PWSTR raw{};
|
||||
if (FAILED(SHGetKnownFolderPath(folder, 0, nullptr, &raw))) return {};
|
||||
std::unique_ptr<wchar_t, decltype(&CoTaskMemFree)> path(raw, CoTaskMemFree);
|
||||
return std::filesystem::path(path.get());
|
||||
}
|
||||
|
||||
std::filesystem::path chromeUserData()
|
||||
{
|
||||
const auto local = shortcutKnownFolder(FOLDERID_LocalAppData);
|
||||
return local.empty() ? local : local / L"Google/Chrome/User Data";
|
||||
}
|
||||
|
||||
std::filesystem::path chromeExecutable()
|
||||
{
|
||||
constexpr wchar_t key[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe";
|
||||
std::error_code ec;
|
||||
for (const auto hive : {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE})
|
||||
{
|
||||
wchar_t path[32768]{};
|
||||
DWORD bytes = sizeof(path);
|
||||
if (RegGetValueW(hive, key, nullptr, RRF_RT_REG_SZ | RRF_RT_REG_EXPAND_SZ, nullptr, path, &bytes) == ERROR_SUCCESS)
|
||||
{
|
||||
const std::filesystem::path candidate(path);
|
||||
if (candidate.is_absolute() && lower(candidate.filename().wstring()) == L"chrome.exe" &&
|
||||
std::filesystem::is_regular_file(candidate, ec)) return candidate;
|
||||
}
|
||||
}
|
||||
for (const auto *folder : {&FOLDERID_LocalAppData, &FOLDERID_ProgramFiles, &FOLDERID_ProgramFilesX86})
|
||||
{
|
||||
const auto base = shortcutKnownFolder(*folder);
|
||||
if (base.empty()) continue;
|
||||
const auto candidate = (base / L"Google/Chrome/Application/chrome.exe").make_preferred();
|
||||
if (std::filesystem::is_regular_file(candidate, ec)) return candidate;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool launchThroughExplorer(const std::wstring &path)
|
||||
{
|
||||
return shellOpenThroughExplorer(path, {}, std::filesystem::path(path).parent_path().wstring());
|
||||
}
|
||||
|
||||
bool validShortcutUrl(const std::wstring &url)
|
||||
{
|
||||
if (url.empty() || url.size() > 16384 || std::any_of(url.begin(), url.end(), [](wchar_t ch) {
|
||||
return ch <= L' ' || ch == L'\x7f' || ch == L'\\' || ch == L'"';
|
||||
})) return false;
|
||||
URL_COMPONENTSW parts{};
|
||||
parts.dwStructSize = sizeof(parts);
|
||||
parts.dwHostNameLength = static_cast<DWORD>(-1);
|
||||
return WinHttpCrackUrl(url.c_str(), static_cast<DWORD>(url.size()), 0, &parts) &&
|
||||
(parts.nScheme == INTERNET_SCHEME_HTTP || parts.nScheme == INTERNET_SCHEME_HTTPS) && parts.dwHostNameLength;
|
||||
}
|
||||
|
||||
bool validChromeProfileName(std::wstring_view name)
|
||||
{
|
||||
return !name.empty() && name.size() <= 255 && name.back() != L'.' && name.back() != L' ' &&
|
||||
name.find_first_of(L"<>:\"/\\|?*") == name.npos && std::none_of(name.begin(), name.end(), [](wchar_t ch) {
|
||||
return ch < L' ';
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::wstring, std::wstring>> chromeShortcutProfiles()
|
||||
{
|
||||
std::vector<std::pair<std::wstring, std::wstring>> profiles;
|
||||
const auto root = chromeUserData();
|
||||
if (root.empty()) return profiles;
|
||||
try
|
||||
{
|
||||
const auto state = nlohmann::json::parse(readFile(root / L"Local State", 16 * 1024 * 1024));
|
||||
const auto &cache = state.at("profile").at("info_cache");
|
||||
if (!cache.is_object()) return profiles;
|
||||
for (const auto &[id, entry] : cache.items())
|
||||
{
|
||||
const auto directory = wide(id);
|
||||
std::error_code ec;
|
||||
if (!validChromeProfileName(directory) || !entry.is_object() ||
|
||||
!std::filesystem::is_directory(root / directory, ec)) continue;
|
||||
auto display = entry.find("name");
|
||||
const auto name = display != entry.end() && display->is_string() ? wide(display->get<std::string>()) : directory;
|
||||
profiles.emplace_back(directory, name.empty() ? directory : name);
|
||||
}
|
||||
}
|
||||
catch (const std::exception &) {} // Chrome may be uninstalled or may be rewriting Local State.
|
||||
return profiles;
|
||||
}
|
||||
|
||||
bool openShortcutUrl(const CustomShortcut &rule)
|
||||
{
|
||||
if (rule.browser == ShortcutBrowser::Default) return shellOpenThroughExplorer(rule.url, {}, {});
|
||||
const auto path = rule.browser == ShortcutBrowser::Chrome ? chromeExecutable() : std::filesystem::path(rule.executable);
|
||||
if (path.empty()) return false;
|
||||
auto arguments = quoteWindowsArgument(rule.url);
|
||||
if (rule.browser == ShortcutBrowser::Chrome && !rule.chromeProfile.empty())
|
||||
{
|
||||
const auto root = chromeUserData();
|
||||
std::error_code ec;
|
||||
if (root.empty() || !std::filesystem::is_directory(root / rule.chromeProfile, ec)) return false;
|
||||
arguments = quoteWindowsArgument(L"--profile-directory=" + rule.chromeProfile) + L" " + arguments;
|
||||
}
|
||||
return shellOpenThroughExplorer(path.wstring(), arguments, path.parent_path().wstring());
|
||||
}
|
||||
bool clipboardHasImage()
|
||||
{
|
||||
return IsClipboardFormatAvailable(CF_DIB) || IsClipboardFormatAvailable(CF_DIBV5) ||
|
||||
|
||||
@@ -54,6 +54,10 @@ std::wstring shortcutTextControlClass(HWND);
|
||||
HWND findShortcutTextControl(HWND, std::wstring_view controlClass, int controlId);
|
||||
std::wstring mouseApplicationName(HWND);
|
||||
bool launchThroughExplorer(const std::wstring &);
|
||||
bool validShortcutUrl(const std::wstring &);
|
||||
bool validChromeProfileName(std::wstring_view);
|
||||
std::vector<std::pair<std::wstring, std::wstring>> chromeShortcutProfiles();
|
||||
bool openShortcutUrl(const CustomShortcut &);
|
||||
enum class ClipboardRead { All, Selection, WithoutImages };
|
||||
bool clipboardHasImage();
|
||||
Clip readClipboard(HWND, size_t limit = 32 * 1024 * 1024,
|
||||
|
||||
+39
-6
@@ -216,10 +216,21 @@ void validateSettings(const Settings &s)
|
||||
const auto key = Hotkey::parse(rule.shortcut);
|
||||
if (!key || !key->key)
|
||||
throw std::runtime_error("Enter a key combination for the custom shortcut.");
|
||||
const std::filesystem::path path(rule.executable);
|
||||
if (rule.executable.size() > 32700 || rule.executable.find_first_of(L"\r\n\"") != std::wstring::npos ||
|
||||
rule.executable.find(L'\0') != std::wstring::npos || !path.is_absolute() || lower(path.extension().wstring()) != L".exe")
|
||||
throw std::runtime_error("Choose a program executable (.exe) for the custom shortcut.");
|
||||
if (rule.action != CustomShortcutAction::OpenUrl || rule.browser == ShortcutBrowser::Other)
|
||||
{
|
||||
const std::filesystem::path path(rule.executable);
|
||||
if (rule.executable.size() > 32700 || rule.executable.find_first_of(L"\r\n\"") != std::wstring::npos ||
|
||||
rule.executable.find(L'\0') != std::wstring::npos || !path.is_absolute() || lower(path.extension().wstring()) != L".exe")
|
||||
throw std::runtime_error("Choose a program executable (.exe) for the custom shortcut.");
|
||||
}
|
||||
if (rule.action == CustomShortcutAction::OpenUrl)
|
||||
{
|
||||
if (!validShortcutUrl(rule.url)) throw std::runtime_error("Enter a valid HTTP or HTTPS URL.");
|
||||
if (rule.browser != ShortcutBrowser::Default && rule.browser != ShortcutBrowser::Chrome && rule.browser != ShortcutBrowser::Other)
|
||||
throw std::runtime_error("Choose a browser for the URL shortcut.");
|
||||
if (rule.browser == ShortcutBrowser::Chrome && !rule.chromeProfile.empty() && !validChromeProfileName(rule.chromeProfile))
|
||||
throw std::runtime_error("Choose a valid Chrome profile.");
|
||||
}
|
||||
if (rule.action == CustomShortcutAction::SendText &&
|
||||
(rule.controlClass.empty() || rule.controlClass.size() > 255 || rule.text.empty() ||
|
||||
rule.text.size() > 32768 || rule.text.find(L'\0') != std::wstring::npos))
|
||||
@@ -399,7 +410,6 @@ Settings decodeSettings(const Bytes &bytes, const std::vector<Layout> &layouts)
|
||||
for (const auto &rule : rules)
|
||||
{
|
||||
const auto action = rule.value("action", "launchApp");
|
||||
if (action != "launchApp" && action != "sendText") throw std::runtime_error("Unknown custom shortcut action.");
|
||||
CustomShortcut shortcut{str(rule, "name", L""), str(rule, "shortcut", L""),
|
||||
str(rule, "executable", L""), rule.value("enabled", true)};
|
||||
if (action == "sendText")
|
||||
@@ -409,7 +419,21 @@ Settings decodeSettings(const Bytes &bytes, const std::vector<Layout> &layouts)
|
||||
shortcut.text = str(rule, "text", L"");
|
||||
shortcut.controlId = rule.value("controlId", 0);
|
||||
}
|
||||
else shortcut.newInstance = rule.value("newInstance", false);
|
||||
else if (action == "openUrl")
|
||||
{
|
||||
shortcut.action = CustomShortcutAction::OpenUrl;
|
||||
shortcut.url = str(rule, "url", L"");
|
||||
const auto browser = rule.value("browser", "default");
|
||||
if (browser == "chrome")
|
||||
{
|
||||
shortcut.browser = ShortcutBrowser::Chrome;
|
||||
shortcut.chromeProfile = str(rule, "chromeProfile", L"");
|
||||
}
|
||||
else if (browser == "other") shortcut.browser = ShortcutBrowser::Other;
|
||||
else if (browser != "default") throw std::runtime_error("Unknown shortcut browser.");
|
||||
}
|
||||
else if (action == "launchApp") shortcut.newInstance = rule.value("newInstance", false);
|
||||
else throw std::runtime_error("Unknown custom shortcut action.");
|
||||
s.customShortcuts.push_back(std::move(shortcut));
|
||||
}
|
||||
}
|
||||
@@ -588,6 +612,15 @@ Bytes encodeSettings(const Settings &s)
|
||||
item["controlId"] = rule.controlId;
|
||||
item["text"] = utf8(rule.text);
|
||||
}
|
||||
else if (rule.action == CustomShortcutAction::OpenUrl)
|
||||
{
|
||||
item["action"] = "openUrl";
|
||||
item["url"] = utf8(rule.url);
|
||||
item["browser"] = rule.browser == ShortcutBrowser::Chrome ? "chrome" :
|
||||
rule.browser == ShortcutBrowser::Other ? "other" : "default";
|
||||
if (rule.browser == ShortcutBrowser::Chrome && !rule.chromeProfile.empty())
|
||||
item["chromeProfile"] = utf8(rule.chromeProfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
item["action"] = "launchApp";
|
||||
|
||||
+56
@@ -481,6 +481,62 @@ HWND makeWindow(App &app, const wchar_t *cls, const wchar_t *title, WNDPROC proc
|
||||
SetPropW(w, L"Dpi", (HANDLE)(UINT_PTR)GetDpiForWindow(w));
|
||||
return w;
|
||||
}
|
||||
#ifndef KS_RESIDENT_APP
|
||||
constexpr int ModalFooterHeight = 50;
|
||||
|
||||
LRESULT CALLBACK settingsModalPaletteProc(HWND w, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR id, DWORD_PTR data)
|
||||
{
|
||||
auto *palette = reinterpret_cast<WindowPalette *>(data);
|
||||
if (msg == WM_ERASEBKGND)
|
||||
{
|
||||
const auto dc = reinterpret_cast<HDC>(wp);
|
||||
RECT area{};
|
||||
GetClientRect(w, &area);
|
||||
FillRect(dc, &area, GetSysColorBrush(COLOR_WINDOW));
|
||||
area.top = std::max(0L, area.bottom - scale(w, ModalFooterHeight));
|
||||
FillRect(dc, &area, palette->brush());
|
||||
fillSurface(dc, {area.left, area.top, area.right, area.top + 1}, palette->edge());
|
||||
return 1;
|
||||
}
|
||||
if (msg == WM_CTLCOLORSTATIC)
|
||||
{
|
||||
const auto dc = reinterpret_cast<HDC>(wp);
|
||||
SetBkColor(dc, GetSysColor(COLOR_WINDOW));
|
||||
return reinterpret_cast<LRESULT>(GetSysColorBrush(COLOR_WINDOW));
|
||||
}
|
||||
if (msg == WM_SYSCOLORCHANGE || msg == WM_THEMECHANGED || msg == WM_SETTINGCHANGE || msg == WM_DWMCOLORIZATIONCOLORCHANGED)
|
||||
{
|
||||
palette->refresh();
|
||||
RedrawWindow(w, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
|
||||
}
|
||||
if (msg == WM_NCDESTROY)
|
||||
{
|
||||
RemoveWindowSubclass(w, settingsModalPaletteProc, id);
|
||||
delete palette;
|
||||
}
|
||||
return DefSubclassProc(w, msg, wp, lp);
|
||||
}
|
||||
|
||||
HWND makeSettingsModal(App &app, HWND owner, const wchar_t *cls, const wchar_t *title, WNDPROC proc, int width, int height)
|
||||
{
|
||||
auto palette = std::make_unique<WindowPalette>();
|
||||
palette->refresh();
|
||||
const auto w = makeWindow(app, cls, title, proc, width, height, 0, false, owner);
|
||||
windowLayoutState(w)->fixedClient = true;
|
||||
if (SetWindowSubclass(w, settingsModalPaletteProc, 1, reinterpret_cast<DWORD_PTR>(palette.get()))) palette.release();
|
||||
return w;
|
||||
}
|
||||
|
||||
void settingsModalActions(HWND w, int width, int height, const wchar_t *accept, int extraId = 0, const wchar_t *extra = nullptr)
|
||||
{
|
||||
constexpr int margin = 22, acceptWidth = 120, cancelWidth = 90, gap = 12;
|
||||
const int y = height - (ModalFooterHeight + 28) / 2;
|
||||
const int x = width - margin - acceptWidth;
|
||||
if (extra) button(w, extra, extraId, margin, y, cancelWidth);
|
||||
button(w, L"Cancel", IDCANCEL, x - gap - cancelWidth, y, cancelWidth);
|
||||
control(w, L"BUTTON", accept, WS_TABSTOP | WS_GROUP | BS_DEFPUSHBUTTON, IDOK, x, y, acceptWidth, 28);
|
||||
}
|
||||
#endif
|
||||
void resizeForDpi(HWND w, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
// Creation may send WM_DPICHANGED before controls and the original font exist.
|
||||
|
||||
+109
-25
@@ -2,6 +2,10 @@ constexpr int RuleName = 783, RuleHotkey = 784, RuleExecutable = 785, RuleBrowse
|
||||
constexpr int RuleReuseWindow = 787, RuleNewInstance = 788, RuleRemove = 789;
|
||||
constexpr int RuleAction = 790, RuleControl = 791, RuleText = 792, RuleModeLabel = 793, RuleTextLabel = 794;
|
||||
constexpr int RulePickerHelp = 795;
|
||||
constexpr int RuleProgramLabel = 796, RuleUrl = 797, RuleUrlLabel = 798, RuleBrowser = 799, RuleBrowserLabel = 800;
|
||||
constexpr int RuleChromeProfile = 801, RuleChromeProfileLabel = 802, RuleBrowserPath = 803,
|
||||
RuleBrowserBrowse = 804, RuleBrowserPathLabel = 805;
|
||||
constexpr int ShortcutDialogWidth = 620, ShortcutDialogHeight = 425;
|
||||
|
||||
void fillCustomShortcuts(SettingsView &view, int selected = -1)
|
||||
{
|
||||
@@ -15,7 +19,8 @@ void fillCustomShortcuts(SettingsView &view, int selected = -1)
|
||||
item.iItem = row;
|
||||
item.pszText = const_cast<wchar_t *>(rule.name.c_str());
|
||||
ListView_InsertItem(list, &item);
|
||||
const wchar_t *action = rule.action == CustomShortcutAction::SendText ? L"Send text to app" :
|
||||
const wchar_t *action = rule.action == CustomShortcutAction::OpenUrl ? L"Open URL" :
|
||||
rule.action == CustomShortcutAction::SendText ? L"Send text to app" :
|
||||
rule.newInstance ? L"Launch new instance" : L"Activate last used or launch";
|
||||
ListView_SetItemText(list, row, 1, const_cast<wchar_t *>(action));
|
||||
ListView_SetItemText(list, row, 2, const_cast<wchar_t *>(rule.shortcut.c_str()));
|
||||
@@ -41,6 +46,9 @@ struct CustomShortcutEditor
|
||||
std::wstring targetExecutable;
|
||||
std::wstring launchExecutable;
|
||||
int controlId = 0;
|
||||
CustomShortcutAction action = CustomShortcutAction::LaunchApp;
|
||||
std::vector<std::pair<std::wstring, std::wstring>> chromeProfiles;
|
||||
bool profilesLoaded = false;
|
||||
};
|
||||
|
||||
void stageCustomShortcuts(SettingsView &view, std::vector<CustomShortcut> rules)
|
||||
@@ -49,20 +57,60 @@ void stageCustomShortcuts(SettingsView &view, std::vector<CustomShortcut> rules)
|
||||
view.draft.customShortcuts = std::move(proposed.customShortcuts);
|
||||
}
|
||||
|
||||
bool shortcutSendsText(HWND w)
|
||||
CustomShortcutAction selectedShortcutAction(HWND w)
|
||||
{
|
||||
return SendDlgItemMessageW(w, RuleAction, CB_GETCURSEL, 0, 0) == 1;
|
||||
return static_cast<CustomShortcutAction>(SendDlgItemMessageW(w, RuleAction, CB_GETCURSEL, 0, 0));
|
||||
}
|
||||
|
||||
void refreshCustomShortcutEditor(HWND w)
|
||||
ShortcutBrowser selectedShortcutBrowser(HWND w)
|
||||
{
|
||||
const bool sendsText = shortcutSendsText(w);
|
||||
return static_cast<ShortcutBrowser>(SendDlgItemMessageW(w, RuleBrowser, CB_GETCURSEL, 0, 0));
|
||||
}
|
||||
|
||||
void refreshCustomShortcutEditor(HWND w, CustomShortcutEditor &editor)
|
||||
{
|
||||
const bool sendsText = editor.action == CustomShortcutAction::SendText;
|
||||
const bool opensUrl = editor.action == CustomShortcutAction::OpenUrl;
|
||||
const bool chrome = opensUrl && selectedShortcutBrowser(w) == ShortcutBrowser::Chrome;
|
||||
const bool other = opensUrl && selectedShortcutBrowser(w) == ShortcutBrowser::Other;
|
||||
const auto picker = GetDlgItem(w, AppWindowPickerIcon);
|
||||
if (sendsText) SetPropW(picker, L"PickShortcutControl", reinterpret_cast<HANDLE>(1));
|
||||
else RemovePropW(picker, L"PickShortcutControl");
|
||||
for (const int id : {RuleProgramLabel, RuleExecutable, AppWindowPickerIcon, RulePickerHelp})
|
||||
ShowWindow(GetDlgItem(w, id), opensUrl ? SW_HIDE : SW_SHOWNA);
|
||||
for (const int id : {RuleControl, RuleTextLabel, RuleText}) ShowWindow(GetDlgItem(w, id), sendsText ? SW_SHOWNA : SW_HIDE);
|
||||
for (const int id : {RuleBrowse, RuleModeLabel, RuleReuseWindow, RuleNewInstance})
|
||||
ShowWindow(GetDlgItem(w, id), sendsText ? SW_HIDE : SW_SHOWNA);
|
||||
ShowWindow(GetDlgItem(w, id), sendsText || opensUrl ? SW_HIDE : SW_SHOWNA);
|
||||
for (const int id : {RuleUrl, RuleUrlLabel, RuleBrowser, RuleBrowserLabel})
|
||||
ShowWindow(GetDlgItem(w, id), opensUrl ? SW_SHOWNA : SW_HIDE);
|
||||
for (const int id : {RuleChromeProfile, RuleChromeProfileLabel})
|
||||
ShowWindow(GetDlgItem(w, id), chrome ? SW_SHOWNA : SW_HIDE);
|
||||
for (const int id : {RuleBrowserPath, RuleBrowserBrowse, RuleBrowserPathLabel})
|
||||
ShowWindow(GetDlgItem(w, id), other ? SW_SHOWNA : SW_HIDE);
|
||||
const auto browser = GetDlgItem(w, RuleBrowser);
|
||||
for (auto &[control, bounds] : windowLayoutState(w)->controls)
|
||||
if (control == browser) bounds.right = chrome ? 298 : 598;
|
||||
arrangeWindow(w);
|
||||
if (chrome && !editor.profilesLoaded)
|
||||
{
|
||||
editor.profilesLoaded = true;
|
||||
editor.chromeProfiles = chromeShortcutProfiles();
|
||||
const auto saved = editor.previous ? editor.previous->chromeProfile : std::wstring{};
|
||||
if (!saved.empty() && std::none_of(editor.chromeProfiles.begin(), editor.chromeProfiles.end(),
|
||||
[&](const auto &profile) { return profile.first == saved; }))
|
||||
editor.chromeProfiles.emplace_back(saved, saved + L" (unavailable)");
|
||||
int selected = 0, index = 0;
|
||||
for (const auto &[directory, name] : editor.chromeProfiles)
|
||||
{
|
||||
const bool duplicate = std::count_if(editor.chromeProfiles.begin(), editor.chromeProfiles.end(),
|
||||
[&](const auto &profile) { return profile.second == name; }) > 1;
|
||||
const auto caption = duplicate ? name + L" (" + directory + L")" : name;
|
||||
SendDlgItemMessageW(w, RuleChromeProfile, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(caption.c_str()));
|
||||
++index;
|
||||
if (directory == saved) selected = index;
|
||||
}
|
||||
SendDlgItemMessageW(w, RuleChromeProfile, CB_SETCURSEL, selected, 0);
|
||||
}
|
||||
SendDlgItemMessageW(w, RuleExecutable, EM_SETREADONLY, sendsText, 0);
|
||||
value(w, RulePickerHelp, sendsText ? L"Drag the crosshair onto the text field you want to fill." :
|
||||
L"Drag the crosshair to an open window to select its program.");
|
||||
@@ -82,7 +130,7 @@ LRESULT CALLBACK customShortcutProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
const auto picked = reinterpret_cast<HWND>(wp);
|
||||
const auto root = GetAncestor(picked, GA_ROOT);
|
||||
const auto path = processImagePath(root);
|
||||
if (shortcutSendsText(w))
|
||||
if (editor->action == CustomShortcutAction::SendText)
|
||||
{
|
||||
const auto kind = shortcutTextControlClass(picked);
|
||||
const auto id = GetDlgCtrlID(picked);
|
||||
@@ -108,15 +156,21 @@ LRESULT CALLBACK customShortcutProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
const auto id = LOWORD(wp);
|
||||
if (id == RuleAction && HIWORD(wp) == CBN_SELCHANGE)
|
||||
{
|
||||
if (shortcutSendsText(w)) editor->launchExecutable = value(w, RuleExecutable);
|
||||
refreshCustomShortcutEditor(w);
|
||||
value(w, RuleExecutable, shortcutSendsText(w) ? editor->targetExecutable : editor->launchExecutable);
|
||||
if (editor->action == CustomShortcutAction::LaunchApp) editor->launchExecutable = value(w, RuleExecutable);
|
||||
editor->action = selectedShortcutAction(w);
|
||||
refreshCustomShortcutEditor(w, *editor);
|
||||
value(w, RuleExecutable, editor->action == CustomShortcutAction::SendText ? editor->targetExecutable : editor->launchExecutable);
|
||||
return 0;
|
||||
}
|
||||
if (id == RuleBrowse)
|
||||
if (id == RuleBrowser && HIWORD(wp) == CBN_SELCHANGE)
|
||||
{
|
||||
refreshCustomShortcutEditor(w, *editor);
|
||||
return 0;
|
||||
}
|
||||
if (id == RuleBrowse || id == RuleBrowserBrowse)
|
||||
{
|
||||
const auto path = chooseApplicationFile(w, L"Programs (*.exe)\0*.exe\0");
|
||||
if (!path.empty()) value(w, RuleExecutable, path);
|
||||
if (!path.empty()) value(w, id == RuleBrowse ? RuleExecutable : RuleBrowserPath, path);
|
||||
return 0;
|
||||
}
|
||||
if (id == IDOK || id == RuleRemove)
|
||||
@@ -131,7 +185,7 @@ LRESULT CALLBACK customShortcutProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
CustomShortcut rule{value(w, RuleName), value(w, RuleHotkey), value(w, RuleExecutable),
|
||||
row < 0 || rules[row].enabled, checked(w, RuleNewInstance)};
|
||||
if (shortcutSendsText(w))
|
||||
if (editor->action == CustomShortcutAction::SendText)
|
||||
{
|
||||
rule.action = CustomShortcutAction::SendText;
|
||||
rule.controlClass = editor->controlClass;
|
||||
@@ -142,6 +196,20 @@ LRESULT CALLBACK customShortcutProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if (rule.controlClass.empty() || rule.text.empty())
|
||||
throw std::runtime_error("Choose a target text field and enter the text to insert.");
|
||||
}
|
||||
else if (editor->action == CustomShortcutAction::OpenUrl)
|
||||
{
|
||||
rule.action = CustomShortcutAction::OpenUrl;
|
||||
rule.url = trimApplicationText(value(w, RuleUrl));
|
||||
rule.browser = selectedShortcutBrowser(w);
|
||||
rule.executable = rule.browser == ShortcutBrowser::Other ? trimApplicationText(value(w, RuleBrowserPath)) : L"";
|
||||
rule.newInstance = false;
|
||||
if (rule.browser == ShortcutBrowser::Chrome)
|
||||
{
|
||||
const auto profile = SendDlgItemMessageW(w, RuleChromeProfile, CB_GETCURSEL, 0, 0);
|
||||
if (profile > 0 && static_cast<size_t>(profile) <= editor->chromeProfiles.size())
|
||||
rule.chromeProfile = editor->chromeProfiles[profile - 1].first;
|
||||
}
|
||||
}
|
||||
if (row < 0) rules.push_back(std::move(rule));
|
||||
else rules[row] = std::move(rule);
|
||||
}
|
||||
@@ -182,12 +250,12 @@ void showCustomShortcut(HWND owner, SettingsView &view, bool editing)
|
||||
const int row = editing ? ListView_GetNextItem(list, -1, LVNI_SELECTED) : -1;
|
||||
if (editing && row < 0) return;
|
||||
const auto rule = editing ? view.draft.customShortcuts.at(row) : CustomShortcut{};
|
||||
const HWND w = makeWindow(*view.app, L"KSwitcher.CustomShortcut", editing ? L"Edit shortcut" : L"Add shortcut",
|
||||
customShortcutProc, 620, 425, 0, false, owner);
|
||||
windowLayoutState(w)->fixedClient = true;
|
||||
const HWND w = makeSettingsModal(*view.app, owner, L"KSwitcher.CustomShortcut", editing ? L"Edit shortcut" : L"Add shortcut",
|
||||
customShortcutProc, ShortcutDialogWidth, ShortcutDialogHeight);
|
||||
const bool sendsText = rule.action == CustomShortcutAction::SendText;
|
||||
auto *editor = new CustomShortcutEditor{view, row, editing ? std::optional(rule) : std::nullopt, nullptr, rule.controlClass,
|
||||
sendsText ? rule.executable : L"", sendsText ? L"" : rule.executable, rule.controlId};
|
||||
sendsText ? rule.executable : L"", rule.action == CustomShortcutAction::LaunchApp ? rule.executable : L"",
|
||||
rule.controlId, rule.action};
|
||||
SetWindowLongPtrW(w, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(editor));
|
||||
label(w, L"&Name", 22, 16, 340);
|
||||
edit(w, RuleName, 22, 40, 340);
|
||||
@@ -195,10 +263,10 @@ void showCustomShortcut(HWND owner, SettingsView &view, bool editing)
|
||||
hotkeyEdit(*view.app, w, RuleHotkey, 378, 40, 220);
|
||||
label(w, L"&Action", 22, 80, 576);
|
||||
control(w, WC_COMBOBOXW, L"", WS_TABSTOP | CBS_DROPDOWNLIST, RuleAction, 22, 101, 576, 110);
|
||||
for (const auto *action : {L"Launch app", L"Send text to app"})
|
||||
for (const auto *action : {L"Launch app", L"Send text to app", L"Open URL"})
|
||||
SendDlgItemMessageW(w, RuleAction, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(action));
|
||||
SendDlgItemMessageW(w, RuleAction, CB_SETCURSEL, sendsText, 0);
|
||||
label(w, L"&Program", 22, 137, 576);
|
||||
SendDlgItemMessageW(w, RuleAction, CB_SETCURSEL, static_cast<WPARAM>(rule.action), 0);
|
||||
control(w, L"STATIC", L"&Program", 0, RuleProgramLabel, 22, 137, 576, 22);
|
||||
edit(w, RuleExecutable, 22, 160, 440);
|
||||
button(w, L"&Browse...", RuleBrowse, 472, 158, 84);
|
||||
createAppWindowPicker(w, AppWindowPickerIcon, 566, 158, 32, editor->pickerOutline, createButtonTooltips(w));
|
||||
@@ -211,18 +279,34 @@ void showCustomShortcut(HWND owner, SettingsView &view, bool editing)
|
||||
control(w, L"BUTTON", L"Activate the last-used window, or launch the app if it is closed",
|
||||
WS_TABSTOP | WS_GROUP | BS_AUTORADIOBUTTON, RuleReuseWindow, 22, 252, 576, 24);
|
||||
control(w, L"BUTTON", L"Always launch a new instance", BS_AUTORADIOBUTTON, RuleNewInstance, 22, 281, 576, 24);
|
||||
if (editing) button(w, L"&Remove", RuleRemove, 22, 370, 90);
|
||||
control(w, L"BUTTON", editing ? L"Save shortcut" : L"Add shortcut", WS_TABSTOP | WS_GROUP | BS_DEFPUSHBUTTON,
|
||||
IDOK, 478, 370, 120, 28);
|
||||
button(w, L"Cancel", IDCANCEL, 376, 370, 90);
|
||||
control(w, L"STATIC", L"&URL", 0, RuleUrlLabel, 22, 137, 576, 22);
|
||||
edit(w, RuleUrl, 22, 160, 576);
|
||||
SendDlgItemMessageW(w, RuleUrl, EM_SETLIMITTEXT, 16384, 0);
|
||||
control(w, L"STATIC", L"&Browser", 0, RuleBrowserLabel, 22, 201, 276, 22);
|
||||
control(w, WC_COMBOBOXW, L"", WS_TABSTOP | CBS_DROPDOWNLIST, RuleBrowser, 22, 224, 576, 115);
|
||||
for (const auto *browser : {L"Default browser", L"Google Chrome", L"Other browser"})
|
||||
SendDlgItemMessageW(w, RuleBrowser, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(browser));
|
||||
SendDlgItemMessageW(w, RuleBrowser, CB_SETCURSEL, static_cast<WPARAM>(rule.browser), 0);
|
||||
control(w, L"STATIC", L"Chrome &profile", 0, RuleChromeProfileLabel, 319, 201, 279, 22);
|
||||
control(w, WC_COMBOBOXW, L"", WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST, RuleChromeProfile, 319, 224, 279, 122);
|
||||
SendDlgItemMessageW(w, RuleChromeProfile, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"Use Chrome's default profile"));
|
||||
SendDlgItemMessageW(w, RuleChromeProfile, CB_SETCURSEL, 0, 0);
|
||||
control(w, L"STATIC", L"Browser executable", 0, RuleBrowserPathLabel, 22, 265, 576, 22);
|
||||
edit(w, RuleBrowserPath, 22, 288, 478);
|
||||
button(w, L"Browse...", RuleBrowserBrowse, 510, 286, 88);
|
||||
settingsModalActions(w, ShortcutDialogWidth, ShortcutDialogHeight, editing ? L"Save shortcut" : L"Add shortcut",
|
||||
RuleRemove, editing ? L"&Remove" : nullptr);
|
||||
value(w, RuleName, rule.name);
|
||||
value(w, RuleHotkey, rule.shortcut);
|
||||
value(w, RuleExecutable, rule.executable);
|
||||
value(w, RuleControl, rule.controlClass.empty() ? L"No target field selected" :
|
||||
L"Target control: " + rule.controlClass + L" (ID " + std::to_wstring(rule.controlId) + L")");
|
||||
value(w, RuleText, rule.text);
|
||||
value(w, RuleUrl, rule.url);
|
||||
if (rule.action == CustomShortcutAction::OpenUrl && rule.browser == ShortcutBrowser::Other)
|
||||
value(w, RuleBrowserPath, rule.executable);
|
||||
CheckRadioButton(w, RuleReuseWindow, RuleNewInstance, rule.newInstance ? RuleNewInstance : RuleReuseWindow);
|
||||
refreshCustomShortcutEditor(w);
|
||||
refreshCustomShortcutEditor(w, *editor);
|
||||
EnableWindow(owner, FALSE);
|
||||
showRequestedWindow(w);
|
||||
SetFocus(GetDlgItem(w, RuleName));
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
#include "platform.h"
|
||||
namespace ks
|
||||
{
|
||||
inline constexpr wchar_t AppVersion[] = L"0.8.10";
|
||||
inline constexpr wchar_t AppVersion[] = L"0.8.11";
|
||||
inline constexpr UINT UpdateMessage = WM_APP + 7;
|
||||
inline constexpr UINT UpdateCheckIntervalMs = 6 * 60 * 60 * 1000;
|
||||
inline constexpr UINT UpdateNotificationRetryMs = 5 * 60 * 1000;
|
||||
|
||||
@@ -23,10 +23,14 @@ int wmain(int argc,wchar_t **argv)
|
||||
wchar_t executable[32768]{};
|
||||
const auto length=GetModuleFileNameW(nullptr,executable,static_cast<DWORD>(std::size(executable)));
|
||||
if(!length || length>=std::size(executable)) return 1;
|
||||
const std::filesystem::path target=argc==2?argv[1]:executable;
|
||||
const bool browserFixture=argc==2 && std::filesystem::path(executable).filename()==L"browser-fixture.exe";
|
||||
const std::filesystem::path target=argc==2 && !browserFixture?argv[1]:executable;
|
||||
auto report=target;
|
||||
report+=L".opened";
|
||||
std::ofstream result(report,std::ios::binary);
|
||||
result<<"opened";
|
||||
if(browserFixture) {
|
||||
const std::wstring_view url(argv[1]);
|
||||
for(const auto ch:url) result.put(static_cast<char>(ch));
|
||||
} else result<<"opened";
|
||||
return result?0:1;
|
||||
}
|
||||
+40
-1
@@ -423,7 +423,30 @@ int main(int argc, char **argv) {
|
||||
require(IsWindowVisible(GetDlgItem(dialog, 753)) && IsWindowVisible(GetDlgItem(dialog, 792)) &&
|
||||
!IsWindowVisible(GetDlgItem(dialog, 787)),
|
||||
"text insertion uses the crosshair and shows a multiline text editor");
|
||||
DestroyWindow(dialog);
|
||||
auto select = [&](int id, int row) {
|
||||
SendDlgItemMessageW(dialog, id, CB_SETCURSEL, row, 0);
|
||||
SendMessageW(dialog, WM_COMMAND, MAKEWPARAM(id, CBN_SELCHANGE), 0);
|
||||
};
|
||||
select(790, 2);
|
||||
require(IsWindowVisible(GetDlgItem(dialog, 797)) && IsWindowVisible(GetDlgItem(dialog, 799)) &&
|
||||
!IsWindowVisible(GetDlgItem(dialog, 753)) && !IsWindowVisible(GetDlgItem(dialog, 801)),
|
||||
"Open URL shows an address and browser without an unrelated crosshair or profile picker");
|
||||
select(799, 2);
|
||||
require(IsWindowVisible(GetDlgItem(dialog, 803)), "choosing another browser exposes the browser executable");
|
||||
select(799, 1);
|
||||
require(IsWindowVisible(GetDlgItem(dialog, 801)) && !IsWindowVisible(GetDlgItem(dialog, 803)),
|
||||
"choosing Chrome exposes the profile picker");
|
||||
SetDlgItemTextW(dialog, 783, L"Open project board");
|
||||
SetDlgItemTextW(dialog, 784, L"Ctrl+Alt+F10");
|
||||
SetDlgItemTextW(dialog, 797, L"https://example.com/board");
|
||||
SendMessageW(dialog, WM_COMMAND, IDOK, 0);
|
||||
require(!IsWindow(dialog) && ListView_GetItemCount(list) == 2, "adding Open URL updates the shortcut list");
|
||||
ListView_SetCheckState(list, 1, FALSE);
|
||||
SendMessageW(settings, WM_COMMAND, 272, 0);
|
||||
const auto persisted = ks::loadSettings(temp / L"settings.json", app.layouts).customShortcuts;
|
||||
require(persisted.size() == 2 && persisted[1].action == ks::CustomShortcutAction::OpenUrl &&
|
||||
persisted[1].url == L"https://example.com/board" && persisted[1].browser == ks::ShortcutBrowser::Chrome,
|
||||
"Apply persists the Open URL action and browser from the editor");
|
||||
DestroyWindow(settings);
|
||||
|
||||
const auto target = CreateWindowExW(0, L"STATIC", L"Shortcut target", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||
@@ -468,6 +491,22 @@ int main(int argc, char **argv) {
|
||||
require(std::filesystem::exists(marker), newInstance ? "new-instance mode starts the program" :
|
||||
"activate mode starts the program if there is no matching window");
|
||||
}
|
||||
const auto browser = temp / L"browser-fixture.exe";
|
||||
std::filesystem::copy_file(std::filesystem::path(argv[2]), browser);
|
||||
const std::wstring url = L"https://example.com/board?view=a%20b&filter=active#notes";
|
||||
app.settings.customShortcuts[0] = {L"Open board", L"Ctrl+Alt+F9", browser.wstring(), true, false,
|
||||
ks::CustomShortcutAction::OpenUrl, L"", L"", 0, url, ks::ShortcutBrowser::Other};
|
||||
ks::InputRegressionAccess::invokeCustomShortcut(app, 0, VK_F9);
|
||||
const auto marker = temp / L"browser-fixture.exe.opened";
|
||||
for (const auto deadline = GetTickCount64() + 5000; GetTickCount64() < deadline;)
|
||||
{
|
||||
std::error_code ec;
|
||||
if (std::filesystem::file_size(marker, ec) == url.size()) break;
|
||||
Sleep(25);
|
||||
}
|
||||
const auto recorded = ks::readFile(marker, 1024);
|
||||
require(std::string(recorded.begin(), recorded.end()) == ks::utf8(url),
|
||||
"URL shortcut starts the chosen browser with the complete address as one argument");
|
||||
}
|
||||
std::filesystem::remove_all(temp);
|
||||
std::cout << "Passed " << checks << " custom shortcuts layout checks\n";
|
||||
|
||||
@@ -884,6 +884,8 @@ int main(int argc, char **argv)
|
||||
{L"New editor", L"Ctrl+Alt+F10", L"C:\\Apps\\Editor.exe", false, true},
|
||||
{L"Insert note", L"Ctrl+Alt+F11", L"C:\\Apps\\Editor.exe", true, false,
|
||||
ks::CustomShortcutAction::SendText, L"Edit", L"First line\r\nSecond line", 101},
|
||||
{L"Open board", L"Ctrl+Alt+F12", L"", true, false, ks::CustomShortcutAction::OpenUrl,
|
||||
L"", L"", 0, L"https://example.com/board", ks::ShortcutBrowser::Chrome, L"Profile 1"},
|
||||
};
|
||||
require(ks::decodeSettings(ks::encodeSettings(custom), {}).customShortcuts == custom.customShortcuts,
|
||||
"custom shortcut actions, launch modes, text and enabled state roundtrip");
|
||||
@@ -891,6 +893,18 @@ int main(int argc, char **argv)
|
||||
rejects([&] { ks::validateSettings(custom); }, "custom shortcuts cannot shadow built-in shortcuts");
|
||||
custom.customShortcuts[0].enabled = false;
|
||||
ks::validateSettings(custom);
|
||||
auto &web = custom.customShortcuts.back();
|
||||
web.url = L"file:///C:/Windows/notepad.exe";
|
||||
rejects([&] { ks::validateSettings(custom); }, "URL shortcut requires HTTP or HTTPS");
|
||||
web.url = L"https://example.com/a%20b?q=one%20two#result";
|
||||
web.chromeProfile = L"..\\Other";
|
||||
rejects([&] { ks::validateSettings(custom); }, "Chrome profile must be a single directory name");
|
||||
web.chromeProfile.clear();
|
||||
web.browser = ks::ShortcutBrowser::Other;
|
||||
rejects([&] { ks::validateSettings(custom); }, "specific browser requires an executable");
|
||||
web.executable = L"C:\\Apps\\Browser.exe";
|
||||
require(ks::decodeSettings(ks::encodeSettings(custom), {}).customShortcuts == custom.customShortcuts,
|
||||
"URL shortcut and specific browser roundtrip");
|
||||
custom.customShortcuts[2].controlClass.clear();
|
||||
rejects([&] { ks::validateSettings(custom); }, "text shortcuts require a target control");
|
||||
require(ks::loadSettings(temp / L"defaults.json", {}).screenshot == L"Win+Shift+S",
|
||||
|
||||
Reference in new issue
Block a user