Compare commits

...
Author SHA1 Message Date
agrynco c285505d79 Record the package manifest for KSwitcher v0.6.105
Refs #8, #38
2026-11-16 17:50:53 +02:00
agrynco 2e1b0446bc Separate the Files editor and viewer icons for v0.6.105
Publish the generated Windows ZIP as a Gitea release asset without adding a copy to Git.

Refs #38
2026-11-16 17:50:10 +02:00
agrynco 5ac3735db3 Fix LAN PowerShell startup from an elevated resident
Refs #8
2026-11-16 17:50:10 +02:00
agrynco 03984705fe Merge pull request 'Release KSwitcher v0.6.104 with rendered Markdown search' (#49) from codex/release-v0.6.104 into main 2026-11-16 15:07:14 +02:00
18 changed files with 278 additions and 93 deletions

No files matched your search

+1
View File
@@ -4,5 +4,6 @@
/.vs/
/.idea/
/dist/
/Release/KSwitcher-win-x64.zip
/build-output.txt
*.user
+2 -2
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.24)
project(KSwitcher VERSION 0.6.104 LANGUAGES CXX RC)
project(KSwitcher VERSION 0.6.105 LANGUAGES CXX RC)
if(NOT WIN32)
message(FATAL_ERROR "KSwitcher uses native Windows APIs")
endif()
@@ -164,7 +164,7 @@ if(KSWITCHER_NODE)
-TerminalOnly -Node "${KSWITCHER_NODE}")
set_tests_properties(files-terminal-enter PROPERTIES RUN_SERIAL TRUE TIMEOUT 90)
add_executable(KSwitcherFilesMarkdownLanFixture WIN32 tests/files_markdown_lan.cpp
src/files_text_window.cpp src/files_text_document.cpp src/files_text_language.cpp)
src/files_text_window.cpp src/files_text_document.cpp src/files_text_language.cpp resources/files.rc)
target_include_directories(KSwitcherFilesMarkdownLanFixture PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/build/terminal-deps/sdk/build/native/include")
target_link_libraries(KSwitcherFilesMarkdownLanFixture PRIVATE kscore KSwitcherFilesText)
+4 -2
View File
@@ -150,8 +150,10 @@ Warning і початковий фокус на No.
відкриває файл у програмі, призначеній Windows для цього типу, а Alt+F4
викликає зареєстровану дію Edit. Ці команди також є в меню Commands.
F10 або × закривають головне вікно Files. Вбудовані Viewer та Editor
відкриваються в окремих немодальних вікнах із власними кнопками на панелі
завдань Windows. При повторному відкритті Files пропонує перейти до вже
відкриваються в окремих немодальних вікнах. Редактор має іконку олівця,
переглядач — іконку ока. Ці іконки видно в заголовку, в Alt+Tab і в окремих
групах на панелі завдань Windows. F6 змінює іконку й групу поточного вікна.
При повторному відкритті Files пропонує перейти до вже
відкритого вікна. Закриття менеджера залишає вікна файлів відкритими.
- У цьому вікні F6 перемикає перегляд і редагування для поточного файла.
За наявності змін перехід у перегляд пропонує Save, Discard або Cancel.
+4 -2
View File
@@ -921,8 +921,10 @@ CC BY-SA 4.0; attribution, pinned source revision and license are in `dictionari
## Latest compiled release
The [Release folder](Release/README.md) contains the latest portable Windows x64 ZIP and SHA-256 checksum.
Run `./package.ps1 -PublishRelease` after building and testing to refresh the tracked release archive.
Download the portable Windows x64 ZIP from [Gitea Releases](https://gitea.hrynco.com/hrynco/hrynco-kswitcher/releases).
The [Release folder](Release/README.md) tracks the release notes, manifest and SHA-256 checksum.
Run `./package.ps1 -PublishRelease` after building and testing, then upload the generated ZIP,
manifest and checksum as release assets.
## Verification
+6
View File
@@ -1,5 +1,11 @@
# Latest Windows release
## v0.6.105 — 2026-11-16
KSwitcher Files gives the Editor a pencil icon and the Viewer an eye icon. The two modes have separate taskbar groups, and **F6** switches the icon and group in the same window. On a PC running KSwitcher as administrator, LAN PowerShell commands such as `dir` now start with standard user rights. This fixes the `0xC0000142` startup failure on that path. This release replaces v0.6.104.
**Українською.** Редактор KSwitcher Files має іконку олівця, а переглядач — іконку ока. Режими мають окремі групи на панелі завдань Windows, і **F6** перемикає іконку й групу в тому самому вікні. Якщо KSwitcher на ПК-отримувачі запущено від адміністратора, команди PowerShell через LAN, зокрема `dir`, запускаються з правами звичайного користувача. Виправлено помилку запуску `0xC0000142` у цьому сценарії. Цей реліз замінює v0.6.104.
## v0.6.104 — 2026-11-16
**Ctrl+F** or the search icon opens search in the rendered KSwitcher Files Markdown preview. Search ignores case and highlights the current match. **Enter** or **F3** moves to the next match, and **Shift+Enter** or **Shift+F3** moves back. **Escape** closes the search first. This release includes the HTML, Markdown appearance, Options and terminal copy updates from v0.6.103.
+1 -1
View File
@@ -1 +1 @@
53b30b2610b66b0d40e28b7fcb0b5e7e10c8a2415f38226059c9c239b2f7b58e KSwitcher-win-x64.zip
41b5353f049d7c6da5e664dda316e1308c5e996cdbd5a7a9b51689c02dda8674 KSwitcher-win-x64.zip
+66 -66
View File
@@ -1,166 +1,166 @@
{
"files": [
{
"sha256": "176319fec5bfb3714bd31a2fdb8c256297d1d683de50a7f8dda319c40672cd83",
"path": "KSwitcher.exe",
"size": 2361856
"size": 2362368,
"sha256": "87a61d636e941adc8b37385dd72fa0e15248368867adc301df5f3af894938e24"
},
{
"sha256": "e80a1d11a129f9a00a1698cd6830ac13f335f74f16dd6f407aa2fe6a3ea2bea8",
"path": "KSwitcher.Config.exe",
"size": 2359296
"size": 2360320,
"sha256": "ea5640173dd0c0338d0b6843f737595b2c67793cceb1202e7e293ca42fe835b8"
},
{
"sha256": "e7925cbaaf39645cb8a582f29bd32628c5fbb73be6b60f5f0f870ec9e936d648",
"path": "KSwitcher.Screenshot.exe",
"size": 3337216
"size": 3337728,
"sha256": "c785ed267aeb3e1c1c27a8aa8fe296a98283553af3d67a9ee171fc873f4dd58c"
},
{
"sha256": "ca59044cbb358ff99a6e9badbf5c9bc6b6ca5e41d3673ab063a29e03c297590b",
"path": "KSwitcher.Files.exe",
"size": 3747840
"size": 3801088,
"sha256": "6cbb9cf16e251f618e543d0af3a014932123f455ed9a2c04f86c948a5852987e"
},
{
"sha256": "d3fce90bdeecb08596e377dea6a316354dd8949e32ff09b89d51be00c14e21b6",
"path": "WebView2Loader.dll",
"size": 194912
"size": 194912,
"sha256": "d3fce90bdeecb08596e377dea6a316354dd8949e32ff09b89d51be00c14e21b6"
},
{
"sha256": "e256f01188af527e4d06d21d06fbf785ae9c50d4b328bf03cbe0ba7f0aa4228f",
"path": "terminal/addon-fit-LICENSE.txt",
"size": 1103
"size": 1103,
"sha256": "e256f01188af527e4d06d21d06fbf785ae9c50d4b328bf03cbe0ba7f0aa4228f"
},
{
"sha256": "ba3ea256ce0620a0992a197d6c9baea64823fc93d8da07a9e366ca9943c18527",
"path": "terminal/addon-fit.js",
"size": 1521
"size": 1521,
"sha256": "ba3ea256ce0620a0992a197d6c9baea64823fc93d8da07a9e366ca9943c18527"
},
{
"sha256": "084d97a727b778fb10d31adcd557ee7840a38377ed60e0ef0f3ece93b349b1ef",
"path": "terminal/index.html",
"size": 527
"size": 527,
"sha256": "084d97a727b778fb10d31adcd557ee7840a38377ed60e0ef0f3ece93b349b1ef"
},
{
"sha256": "792c48c5a849a15fdf9e37e8bcf9e6d1dd13b32b46c642a748a0a46a9919d473",
"path": "terminal/markdown-it-LICENSE.txt",
"size": 1073
"size": 1073,
"sha256": "792c48c5a849a15fdf9e37e8bcf9e6d1dd13b32b46c642a748a0a46a9919d473"
},
{
"sha256": "391f2aa638e75e6c7859d0a5c5650ef0956722a45998f17e05b83bc655778e1e",
"path": "terminal/markdown-it.js",
"size": 100786
"size": 100786,
"sha256": "391f2aa638e75e6c7859d0a5c5650ef0956722a45998f17e05b83bc655778e1e"
},
{
"sha256": "e5381c35fb254b558c8b869746e2e575c8ed53600611ac90597ed2dd80fa321c",
"path": "terminal/markdown.html",
"size": 3530
"size": 3530,
"sha256": "e5381c35fb254b558c8b869746e2e575c8ed53600611ac90597ed2dd80fa321c"
},
{
"sha256": "fe202fa3d3c362aff2ab9028b40bd2aee61240bf9bd4a44af55e45d1a4081cf0",
"path": "terminal/markdown.js",
"size": 14660
"size": 14660,
"sha256": "fe202fa3d3c362aff2ab9028b40bd2aee61240bf9bd4a44af55e45d1a4081cf0"
},
{
"sha256": "ec9fb67dcb25eccc416ed56e1aab819222c805a2a4bfe4cb19e7556bf2ffde80",
"path": "terminal/mermaid-LICENSE.txt",
"size": 1089
"size": 1089,
"sha256": "ec9fb67dcb25eccc416ed56e1aab819222c805a2a4bfe4cb19e7556bf2ffde80"
},
{
"sha256": "336df803d87a38b70a01e736e666c8f7601d2ce42f5e47c8fafe5d721074b9a3",
"path": "terminal/mermaid.js",
"size": 5537838
"size": 5537838,
"sha256": "336df803d87a38b70a01e736e666c8f7601d2ce42f5e47c8fafe5d721074b9a3"
},
{
"sha256": "0557d251962301940785690a3fc49475dd166bb7d0bd0417dc3279d1f1b3a98a",
"path": "terminal/terminal.js",
"size": 5033
"size": 5033,
"sha256": "0557d251962301940785690a3fc49475dd166bb7d0bd0417dc3279d1f1b3a98a"
},
{
"sha256": "b569f629d00f2626a8100df2a1798210535621e42164dfd426a6fe5aac7b0ccd",
"path": "terminal/xterm-LICENSE.txt",
"size": 1261
"size": 1261,
"sha256": "b569f629d00f2626a8100df2a1798210535621e42164dfd426a6fe5aac7b0ccd"
},
{
"sha256": "854a7c0fb70e8b1a083c16797ab827299fb18744f5ad34f227b48337e33293c6",
"path": "terminal/xterm.css",
"size": 7112
"size": 7112,
"sha256": "854a7c0fb70e8b1a083c16797ab827299fb18744f5ad34f227b48337e33293c6"
},
{
"sha256": "14903579ff54664cd72f8e8699e6961a6272c21863ec1c3b118cdc8af5d4a972",
"path": "terminal/xterm.js",
"size": 488663
"size": 488663,
"sha256": "14903579ff54664cd72f8e8699e6961a6272c21863ec1c3b118cdc8af5d4a972"
},
{
"sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c",
"path": "LICENSE",
"size": 4401
"size": 4401,
"sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c"
},
{
"sha256": "c0d068392ea65358b798b8c165103560f06e9e3b38c4ab4e2d8810a7b931af86",
"path": "json-LICENSE.txt",
"size": 1075
"size": 1075,
"sha256": "c0d068392ea65358b798b8c165103560f06e9e3b38c4ab4e2d8810a7b931af86"
},
{
"sha256": "185c5a37521316e940ead89cbf0b1ba5862d810c7c966e6c6a14a4a515b23625",
"path": "files-text-license.txt",
"size": 883
"size": 883,
"sha256": "185c5a37521316e940ead89cbf0b1ba5862d810c7c966e6c6a14a4a515b23625"
},
{
"sha256": "fca41227e9b38bf061298d69806ea66fb00086ae03aec49665e4f68ed2c3f8e9",
"path": "README.md",
"size": 94357
"size": 94502,
"sha256": "b4b561d2bdf1ef80291c3abcadb625407b94279185fd33fd9dc113658ab9b486"
},
{
"sha256": "1233d6a0ed76564dd034f178a9f65db076244a819137f74dc9f2c27df9d3c930",
"path": "LAN-PREVIEW.md",
"size": 11577
"size": 11577,
"sha256": "1233d6a0ed76564dd034f178a9f65db076244a819137f74dc9f2c27df9d3c930"
},
{
"sha256": "5f267c141c3d6837870e1c098f86b89a113ba300343119432644ead88f720c21",
"path": "dictionaries/en.txt",
"size": 682867
"size": 682867,
"sha256": "5f267c141c3d6837870e1c098f86b89a113ba300343119432644ead88f720c21"
},
{
"sha256": "28a9529c7d0bb4dc51f4bf5c116a3d16ef247a052f7591466768ddf563fd1cf5",
"path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt",
"size": 20138
"size": 20138,
"sha256": "28a9529c7d0bb4dc51f4bf5c116a3d16ef247a052f7591466768ddf563fd1cf5"
},
{
"sha256": "3017bf44d3be9d9dfab21bd6778aa52b7947e61acf9ce2bc86b41d6e949ac311",
"path": "dictionaries/README.md",
"size": 2265
"size": 2265,
"sha256": "3017bf44d3be9d9dfab21bd6778aa52b7947e61acf9ce2bc86b41d6e949ac311"
},
{
"sha256": "9ef922c7699569304a428f6aba0fd13a21341c0d0cb9561f37ef83c41577a28b",
"path": "dictionaries/ru.txt",
"size": 1060364
"size": 1060364,
"sha256": "9ef922c7699569304a428f6aba0fd13a21341c0d0cb9561f37ef83c41577a28b"
},
{
"sha256": "98e5b3fe7304e37705c9e5ff48b0b399ccb16e806736d21f09921b99e5f2a408",
"path": "dictionaries/sources.json",
"size": 1280
"size": 1280,
"sha256": "98e5b3fe7304e37705c9e5ff48b0b399ccb16e806736d21f09921b99e5f2a408"
},
{
"sha256": "d30e990d6ec2983c04f3644a3c61c6c668e8c542323f5931916fdd55b916eebf",
"path": "dictionaries/uk.txt",
"size": 940799
"size": 940799,
"sha256": "d30e990d6ec2983c04f3644a3c61c6c668e8c542323f5931916fdd55b916eebf"
},
{
"sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a",
"path": "tools/README.txt",
"size": 993
"size": 993,
"sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a"
},
{
"sha256": "6ef5cf64708d62b7fc63c3c793cc99188a513433ff4774cae01dc014f6664376",
"path": "tools/StayHere.exe",
"size": 134656
"size": 134656,
"sha256": "6ef5cf64708d62b7fc63c3c793cc99188a513433ff4774cae01dc014f6664376"
},
{
"sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413",
"path": "tools/StayHere-README.md",
"size": 2796
"size": 2796,
"sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413"
}
],
"schema": 1,
"version": "0.6.104"
"version": "0.6.105",
"schema": 1
}
+3 -3
View File
@@ -9,8 +9,8 @@ IDC_SCREENSHOT_PENCIL CURSOR "icons/lucide/pencil.cur"
1 RT_MANIFEST "app.manifest"
201 RCDATA "update.ps1"
1 VERSIONINFO
FILEVERSION 0,6,104,0
PRODUCTVERSION 0,6,104,0
FILEVERSION 0,6,105,0
PRODUCTVERSION 0,6,105,0
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
BEGIN
@@ -20,7 +20,7 @@ BEGIN
BEGIN
VALUE "FileDescription", "KSwitcher — native keyboard and clipboard utility"
VALUE "ProductName", "KSwitcher"
VALUE "FileVersion", "0.6.104"
VALUE "FileVersion", "0.6.105"
END
END
BLOCK "VarFileInfo"
+3
View File
@@ -1,11 +1,14 @@
#pragma code_page(65001)
#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#define FAR_EDIT(id, mode, x, y, width, height) \
CONTROL "", id, "KSwitcher.Files.FarEdit", ES_MULTILINE | ES_AUTOHSCROLL | WS_TABSTOP | mode, x, y, width, height
1 ICON "kswitcher-files.ico"
IDI_FILES_VIEWER ICON "kswitcher-files-viewer.ico"
IDI_FILES_EDITOR ICON "kswitcher-files-editor.ico"
1 RT_MANIFEST "app.manifest"
601 RCDATA "files-text-license.txt"
Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

+2
View File
@@ -1,4 +1,6 @@
#pragma once
#define IDI_KSWITCHER 101
#define IDI_SCREENSHOT_QUESTION 102
#define IDI_FILES_VIEWER 103
#define IDI_FILES_EDITOR 104
#define IDC_SCREENSHOT_PENCIL 500
+50 -13
View File
@@ -8,6 +8,7 @@
#include "files_terminal_view.h"
#include "platform.h"
#include "lan_files.h"
#include "../resources/resource.h"
#include <commctrl.h>
#include <shellapi.h>
@@ -742,6 +743,11 @@ public:
}
static LRESULT CALLBACK procedure(HWND window, UINT message, WPARAM wparam, LPARAM lparam);
~TextWindow()
{
if(smallIcon) DestroyIcon(smallIcon);
if(largeIcon) DestroyIcon(largeIcon);
}
HWND window{}, editor{};
bool handleKey(const MSG &message);
void goToFragment(std::string_view fragment);
@@ -753,6 +759,7 @@ private:
std::unique_ptr<TextDocument> document;
std::wstring filename;
bool edit{}, loading{}, stagedDirty{}, closeAfterSave{}, insertRejected{};
HICON smallIcon{},largeIcon{};
TextPreferences prefs;
TextWindowFont filesFont;
TextLanguage automatic, language;
@@ -884,6 +891,8 @@ private:
void showLocation(std::unique_ptr<RemoteTextFile> fetched);
void syncNavigation();
void updateTitle();
void updateIcons(UINT dpi);
void updateTaskbarGroup(bool closing=false);
void pollImages();
void focusContent();
void layout();
@@ -1452,6 +1461,8 @@ void TextWindow::changeMode()
loadPage(std::min(page, document->pages() - 1));
send(SCI_GOTOPOS, std::min(caret, send(SCI_GETLENGTH)));
updateTitle();
updateIcons(GetDpiForWindow(window));
updateTaskbarGroup();
updatePreview();
layout();
focusContent();
@@ -1464,6 +1475,41 @@ void TextWindow::updateTitle()
SetWindowTextW(window,title.c_str());
}
void TextWindow::updateIcons(UINT dpi)
{
const auto instance=GetModuleHandleW(nullptr);
const auto resource=MAKEINTRESOURCEW(edit?IDI_FILES_EDITOR:IDI_FILES_VIEWER);
const auto set=[&](HICON &current,WPARAM kind,int width,int height)
{
const auto icon=static_cast<HICON>(LoadImageW(instance,resource,IMAGE_ICON,
GetSystemMetricsForDpi(width,dpi),GetSystemMetricsForDpi(height,dpi),0));
if(!icon) return;
SendMessageW(window,WM_SETICON,kind,reinterpret_cast<LPARAM>(icon));
if(const auto previous=std::exchange(current,icon)) DestroyIcon(previous);
};
set(smallIcon,ICON_SMALL,SM_CXSMICON,SM_CYSMICON);
set(largeIcon,ICON_BIG,SM_CXICON,SM_CYICON);
}
void TextWindow::updateTaskbarGroup(bool closing)
{
auto icon=closing?std::wstring{}:executable()+L",-"+std::to_wstring(edit?IDI_FILES_EDITOR:IDI_FILES_VIEWER);
auto identity=std::wstring(edit?L"HrynCo.KSwitcher.Files.Editor":L"HrynCo.KSwitcher.Files.Viewer");
IPropertyStore *properties{};
if(FAILED(SHGetPropertyStoreForWindow(window,IID_PPV_ARGS(&properties)))) return;
PROPVARIANT value{};
if(!closing)
{
value.vt=VT_LPWSTR;
value.pwszVal=icon.data();
}
properties->SetValue(PKEY_AppUserModel_RelaunchIconResource,value);
if(!closing) value.pwszVal=identity.data();
// Setting the group ID tells Explorer to refresh the taskbar button.
properties->SetValue(PKEY_AppUserModel_ID,value);
properties->Release();
}
bool TextWindow::canPreview() const
{
return !edit && automatic.lexer=="markdown" && document && document->size()<=TextDocument::editLimit;
@@ -2144,6 +2190,8 @@ LRESULT CALLBACK TextWindow::procedure(HWND window, UINT message, WPARAM wparam,
});
}
else self->initializeDocument();
self->updateIcons(GetDpiForWindow(window));
self->updateTaskbarGroup();
self->layout();
return 0;
case WM_ERASEBKGND: return 1;
@@ -2155,6 +2203,7 @@ LRESULT CALLBACK TextWindow::procedure(HWND window, UINT message, WPARAM wparam,
SetWindowPos(window, nullptr, area->left, area->top, area->right - area->left,
area->bottom - area->top, SWP_NOZORDER | SWP_NOACTIVATE);
self->updateLineNumberMargin();
self->updateIcons(LOWORD(wparam));
self->layout();
return 0;
}
@@ -2230,6 +2279,7 @@ LRESULT CALLBACK TextWindow::procedure(HWND window, UINT message, WPARAM wparam,
return 0;
case WM_DESTROY:
if(self->cancelNavigation) *self->cancelNavigation=true;
self->updateTaskbarGroup(true);
self->stopPreview(false);
self->releaseMenu();
return 0;
@@ -2443,19 +2493,6 @@ void openTextWindow(HWND owner,const std::filesystem::path &path,bool edit,TextD
WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,bounds.left,bounds.top,bounds.right-bounds.left,
bounds.bottom-bounds.top,nullptr,nullptr,instance,&state);
if(!window) return;
IPropertyStore *properties{};
if(SUCCEEDED(SHGetPropertyStoreForWindow(window,IID_PPV_ARGS(&properties))))
{
static unsigned sequence{};
auto identity=L"HrynCo.KSwitcher.Files.Text."+std::to_wstring(GetCurrentProcessId())+
L"."+std::to_wstring(++sequence);
PROPVARIANT value{};
value.vt=VT_LPWSTR;
value.pwszVal=identity.data();
properties->SetValue(PKEY_AppUserModel_ID,value);
properties->Commit();
properties->Release();
}
ShowWindow(window,IsZoomed(owner)?SW_MAXIMIZE:SW_SHOW);
SendMessageW(window,WM_SETFOCUS,0,0);
}
+46 -3
View File
@@ -7,6 +7,7 @@
#include <bcrypt.h>
#include <wincrypt.h>
#include <sddl.h>
#include <winsafer.h>
#include <cstring>
#include <mutex>
#include <thread>
@@ -257,6 +258,40 @@ DWORD requestSystemHibernate()
return GetExitCodeProcess(process.value,&exitCode)?exitCode:GetLastError();
}
DWORD restrictElevatedCommandToken(HANDLE token,FileHandle &restricted)
{
// A synthetic LUA token made directly from an elevated token can fail to
// initialize KernelBase when the child starts without a console window.
SAFER_LEVEL_HANDLE level{};
if(!SaferCreateLevel(SAFER_SCOPEID_USER,SAFER_LEVELID_NORMALUSER,SAFER_LEVEL_OPEN,&level,nullptr))
return GetLastError();
const auto filtered=SaferComputeTokenFromLevel(level,token,&restricted.value,0,nullptr);
const auto filterError=GetLastError();
SaferCloseLevel(level);
if(!filtered) return filterError;
// Preserve DISABLE_MAX_PRIVILEGE without creating a second filtered token.
LUID changeNotify{};
if(!LookupPrivilegeValueW(nullptr,SE_CHANGE_NOTIFY_NAME,&changeNotify)) return GetLastError();
DWORD size{};
if(!GetTokenInformation(restricted.value,TokenPrivileges,nullptr,0,&size) &&
GetLastError()!=ERROR_INSUFFICIENT_BUFFER) return GetLastError();
std::vector<BYTE> storage(size);
const auto privileges=reinterpret_cast<TOKEN_PRIVILEGES *>(storage.data());
if(!GetTokenInformation(restricted.value,TokenPrivileges,privileges,size,&size)) return GetLastError();
DWORD removed{};
for(DWORD i=0;i<privileges->PrivilegeCount;++i)
{
const auto &luid=privileges->Privileges[i].Luid;
if(luid.LowPart!=changeNotify.LowPart || luid.HighPart!=changeNotify.HighPart)
privileges->Privileges[removed++]={luid,SE_PRIVILEGE_REMOVED};
}
if(!removed) return ERROR_SUCCESS;
privileges->PrivilegeCount=removed;
AdjustTokenPrivileges(restricted.value,FALSE,privileges,0,nullptr,nullptr);
return GetLastError();
}
struct RemoteCommand
{
FileHandle job,process,output;
@@ -294,9 +329,17 @@ struct RemoteCommand
FileHandle token,restricted,read,write,input,processJob;
if(!OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_ASSIGN_PRIMARY|
TOKEN_ADJUST_DEFAULT,&token.value) ||
!CreateRestrictedToken(token.value,DISABLE_MAX_PRIVILEGE|LUA_TOKEN,0,nullptr,0,nullptr,0,nullptr,
&restricted.value)) return GetLastError();
TOKEN_ADJUST_DEFAULT,&token.value)) return GetLastError();
TOKEN_ELEVATION elevation{};
DWORD elevationSize{};
if(!GetTokenInformation(token.value,TokenElevation,&elevation,sizeof(elevation),&elevationSize))
return GetLastError();
if(elevation.TokenIsElevated)
{
if(const auto error=restrictElevatedCommandToken(token.value,restricted)) return error;
}
else if(!CreateRestrictedToken(token.value,DISABLE_MAX_PRIVILEGE|LUA_TOKEN,0,nullptr,0,nullptr,0,nullptr,
&restricted.value)) return GetLastError();
PSID medium{};
if(!ConvertStringSidToSidW(L"S-1-16-8192",&medium)) return GetLastError();
TOKEN_MANDATORY_LABEL label{{medium,SE_GROUP_INTEGRITY}};
+1 -1
View File
@@ -2,7 +2,7 @@
#include "platform.h"
namespace ks
{
inline constexpr wchar_t AppVersion[] = L"0.6.104";
inline constexpr wchar_t AppVersion[] = L"0.6.105";
inline constexpr UINT UpdateMessage = WM_APP + 7;
inline constexpr UINT UpdateCheckIntervalMs = 6 * 60 * 60 * 1000;
inline constexpr UINT UpdateNotificationRetryMs = 5 * 60 * 1000;
+61
View File
@@ -11,6 +11,37 @@ using System;
using System.Text;
using System.Runtime.InteropServices;
public static class MarkdownUi {
[StructLayout(LayoutKind.Sequential)]
struct PropertyKey {
public Guid Format;
public uint Id;
}
[StructLayout(LayoutKind.Explicit, Size = 24)]
struct PropertyValue {
[FieldOffset(0)] public ushort Type;
[FieldOffset(8)] public IntPtr Text;
}
[ComImport, Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IPropertyStore {
void GetCount(out uint count);
void GetAt(uint index, out PropertyKey key);
void GetValue(ref PropertyKey key, out PropertyValue value);
}
[DllImport("shell32.dll", PreserveSig = false)]
static extern void SHGetPropertyStoreForWindow(IntPtr window, ref Guid iid, out IPropertyStore store);
[DllImport("ole32.dll")] static extern int PropVariantClear(ref PropertyValue value);
public static string TaskbarProperty(IntPtr window, uint property) {
var iid = typeof(IPropertyStore).GUID;
var key = new PropertyKey { Format = new Guid("9f4c2855-9f79-4b39-a8d0-e1d42de1d5f3"), Id = property };
SHGetPropertyStoreForWindow(window, ref iid, out var store);
try {
store.GetValue(ref key, out var value);
try { return value.Type == 31 ? Marshal.PtrToStringUni(value.Text) : null; }
finally { PropVariantClear(ref value); }
} finally { Marshal.ReleaseComObject(store); }
}
[DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr after, string type, string title);
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr window, out uint pid);
[DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr window);
@@ -84,6 +115,22 @@ function Scintilla($Window) {
[MarkdownUi]::FindWindowEx($Window,0,'Scintilla',[NullString]::Value)
}
function Assert-TextWindowAppearance($Window, [string]$Mode) {
$identity = "HrynCo.KSwitcher.Files.$Mode"
$resource = if($Mode -eq 'Editor') { ',-104' } else { ',-103' }
[void](Wait-For "the $Mode taskbar group" { [MarkdownUi]::TaskbarProperty($Window,5) -ceq $identity })
$taskbarIcon = [MarkdownUi]::TaskbarProperty($Window,3)
if (!$taskbarIcon -or !$taskbarIcon.EndsWith($resource)) {
throw "$Mode taskbar icon was '$taskbarIcon'."
}
$small = [MarkdownUi]::Send($Window,0x7f,0,0)
$large = [MarkdownUi]::Send($Window,0x7f,1,0)
if (!$small.ToInt64() -or !$large.ToInt64() -or $small -eq $large) {
throw "$Mode must expose both a small title-bar icon and a large switcher icon."
}
@{ Small = $small; Large = $large }
}
function Append-Character($Control, [char]$Character) {
[void][MarkdownUi]::Send($Control,2318,0,0)
[void][MarkdownUi]::Send($Control,0x102,[int]$Character,0)
@@ -188,6 +235,7 @@ const value = 42;
Open-File 'Preview.md' 0x72
$window = Wait-For 'the Markdown viewer' { Find-Window 'KSwitcher.Files.Text' 'Viewer' }
$viewerIcons = Assert-TextWindowAppearance $window 'Viewer'
if ([MarkdownUi]::IsWindowVisible((Scintilla $window))) {
throw 'F3 showed the source text while starting the Markdown preview.'
}
@@ -237,6 +285,10 @@ const value = 42;
Browser 'edit'
$editor = Wait-For 'F6 in WebView2 to open the editor' { Find-Window 'KSwitcher.Files.Text' 'Editor' }
if ($editor -ne $window) { throw 'F6 changed windows.' }
$editorIcons = Assert-TextWindowAppearance $window 'Editor'
if ($editorIcons.Small -eq $viewerIcons.Small -or $editorIcons.Large -eq $viewerIcons.Large) {
throw 'F6 did not replace both viewer icons with editor icons.'
}
[MarkdownUi]::Activate($window)
Wait-Foreground $window
[MarkdownUi]::CycleWindow()
@@ -255,6 +307,10 @@ const value = 42;
Post $control 0x100 0x75
Answer-Save 7
Browser 'Перегляд Markdown'
$viewerIcons = Assert-TextWindowAppearance $window 'Viewer'
if ($viewerIcons.Small -eq $editorIcons.Small -or $viewerIcons.Large -eq $editorIcons.Large) {
throw 'F6 did not restore both viewer icons.'
}
if ([IO.File]::ReadAllText($original) -cne $fixture) { throw 'Discard changed the Markdown file.' }
Browser 'ctrl-follow'
if ((Find-Window 'KSwitcher.Files.Text' 'Preview.md') -ne $window -or (Find-Window 'KSwitcher.Files.Text' 'Other.md')) {
@@ -262,6 +318,7 @@ const value = 42;
}
Browser 'shift-follow'
$child = Wait-For 'the Shift+click Markdown window' { Find-Window 'KSwitcher.Files.Text' 'Other.md' $window }
[void](Assert-TextWindowAppearance $child 'Viewer')
Browser 'Linked Markdown' '' 'Other.md'
[MarkdownUi]::Activate($child)
Wait-Foreground $child
@@ -291,6 +348,8 @@ const value = 42;
Open-File 'Preview.md' 0x73
$window = Wait-For 'F4 to open the Markdown editor' { Find-Window 'KSwitcher.Files.Text' 'Editor' }
[void](Assert-TextWindowAppearance $window 'Editor')
Write-Output 'Verified F3/F4 icons, separate taskbar groups and regrouping when the same window switches modes with F6.'
$control = Scintilla $window
Append-Character $control 'Y'
Post $control 0x100 0x75
@@ -363,12 +422,14 @@ const value = 42;
$env:WEBVIEW2_USER_DATA_FOLDER = Join-Path $root 'lan-webview'
$process = Start-Process -FilePath $lanExe -ArgumentList ('"{0}"' -f $original) -PassThru -WindowStyle Normal
$window = Wait-For 'the LAN Markdown viewer' { Find-Window 'KSwitcher.Files.Text' 'Loopback peer' }
[void](Assert-TextWindowAppearance $window 'Viewer')
Browser 'render'
Browser 'search'
Browser 'edit'
if ((Wait-For 'LAN F6 editor' { Find-Window 'KSwitcher.Files.Text' 'Editor' }) -ne $window) {
throw 'LAN F6 changed windows.'
}
[void](Assert-TextWindowAppearance $window 'Editor')
$control = Scintilla $window
Append-Character $control 'L'
Post $control 0x100 0x75
+12
View File
@@ -211,6 +211,18 @@ int main()
require(console.find("PowerShell error")!=console.npos && console.find("CLIXML")==console.npos,
"remote PowerShell errors were not returned as text");
console.clear();
const auto restrictionsExit=runRemoteCommand(host,root,
L"$principal=[Security.Principal.WindowsPrincipal]::new([Security.Principal.WindowsIdentity]::GetCurrent()); "
L"if ($principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) -or "
L"$principal.IsInRole([Security.Principal.WindowsBuiltInRole]::PowerUser)) { exit 8 }; "
L"$privileges=& (Join-Path $env:SystemRoot 'System32\\whoami.exe') /priv /fo csv /nh; "
L"if ($LASTEXITCODE -or ($privileges | ConvertFrom-Csv -Header Name,Description,State | "
L"Where-Object { $_.Name -like 'Se*Privilege' -and $_.Name -ne 'SeChangeNotifyPrivilege' })) { exit 9 }; "
L"Write-Output 'LAN shell is restricted'",
[&](std::string_view part){console+=part;});
require(restrictionsExit==0 && console.find("LAN shell is restricted")!=console.npos,
"remote PowerShell must run with standard user rights and without extra token privileges");
console.clear();
const auto directoryExit=runRemoteCommand(host,root,
L"Write-Progress -Activity 'Hidden progress probe' -Status 'Working'; dir",
[&](std::string_view part){console+=part;});
+16
View File
@@ -21,3 +21,19 @@ for color, points in polygons:
im = im.resize((256,256),Image.Resampling.LANCZOS)
im.save(root / 'kswitcher.png')
im.save(root / 'kswitcher.ico', sizes=[(s,s) for s in (16,20,24,32,40,48,64,128,256)])
for mode, color in [('editor', '#4F46E5'), ('viewer', '#087C73')]:
image = Image.new('RGBA', (32*scale, 32*scale))
draw = ImageDraw.Draw(image)
draw.rounded_rectangle((scale, scale, 31*scale, 31*scale), radius=7*scale, fill=color)
if mode == 'editor':
draw.polygon([(x*scale, y*scale) for x, y in
[(7, 25), (8, 19), (20, 7), (23, 7), (26, 10), (26, 12), (14, 24)]], fill='white')
draw.line([(18*scale, 9*scale), (24*scale, 15*scale)], fill=color, width=2*scale)
else:
draw.polygon([(x*scale, y*scale) for x, y in
[(5, 16), (8, 12), (12, 9), (16, 8), (20, 9), (24, 12),
(27, 16), (24, 20), (20, 23), (16, 24), (12, 23), (8, 20)]], fill='white')
draw.ellipse((12*scale, 12*scale, 20*scale, 20*scale), fill=color)
image.resize((256, 256), Image.Resampling.LANCZOS).save(root / f'kswitcher-files-{mode}.ico',
sizes=[(s, s) for s in (16, 20, 24, 32, 40, 48, 64, 128, 256)])