Skip to content

Commit 1672579

Browse files
committed
1.2.8
1 parent 1881c20 commit 1672579

2 files changed

Lines changed: 55 additions & 30 deletions

File tree

SnapKey.cpp

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SnapKey 1.2.7
1+
// SnapKey 1.2.8
22
// github.com/cafali/SnapKey
33

44
#include <windows.h>
@@ -17,6 +17,8 @@ using namespace std;
1717
#define ID_TRAY_REBIND_KEYS 3002
1818
#define ID_TRAY_LOCK_FUNCTION 3003
1919
#define ID_TRAY_RESTART_SNAPKEY 3004
20+
#define ID_TRAY_HELP 3005 // v1.2.8
21+
#define ID_TRAY_CHECKUPDATE 3006 // v1.2.8
2022
#define WM_TRAYICON (WM_USER + 1)
2123

2224
struct KeyState
@@ -46,9 +48,9 @@ LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
4648
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
4749
void InitNotifyIconData(HWND hwnd);
4850
bool LoadConfig(const std::string& filename);
49-
void CreateDefaultConfig(const std::string& filename); // Declaration
50-
void RestoreConfigFromBackup(const std::string& backupFilename, const std::string& destinationFilename); // Declaration
51-
std::string GetVersionInfo(); // Declaration
51+
void CreateDefaultConfig(const std::string& filename);
52+
void RestoreConfigFromBackup(const std::string& backupFilename, const std::string& destinationFilename);
53+
std::string GetVersionInfo();
5254
void SendKey(int target, bool keyDown);
5355

5456
int main()
@@ -241,18 +243,6 @@ void InitNotifyIconData(HWND hwnd)
241243
Shell_NotifyIcon(NIM_ADD, &nid);
242244
}
243245

244-
std::string GetVersionInfo() // Get version info
245-
{
246-
std::ifstream versionFile("meta/version");
247-
if (!versionFile.is_open()) {
248-
return "Version info not available";
249-
}
250-
251-
std::string version;
252-
std::getline(versionFile, version);
253-
return version.empty() ? "Version info not available" : version;
254-
}
255-
256246
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
257247
{
258248
switch (msg)
@@ -264,13 +254,19 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
264254
GetCursorPos(&curPoint);
265255
SetForegroundWindow(hwnd);
266256

267-
// Create context menu
257+
// context menu
268258
HMENU hMenu = CreatePopupMenu();
259+
// settings & tweaks
269260
AppendMenu(hMenu, MF_STRING, ID_TRAY_REBIND_KEYS, TEXT("Rebind Keys"));
270-
AppendMenu(hMenu, MF_STRING | (isLocked ? MF_CHECKED : MF_UNCHECKED), ID_TRAY_LOCK_FUNCTION, TEXT("Disable SnapKey"));
271261
AppendMenu(hMenu, MF_STRING, ID_TRAY_RESTART_SNAPKEY, TEXT("Restart SnapKey"));
262+
AppendMenu(hMenu, MF_STRING, ID_TRAY_LOCK_FUNCTION, isLocked ? TEXT("Enable SnapKey") : TEXT("Disable SnapKey")); // dynamicly switch between state
263+
// support & info
272264
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
273-
AppendMenu(hMenu, MF_STRING, ID_TRAY_VERSION_INFO, TEXT("Version Info"));
265+
AppendMenu(hMenu, MF_STRING, ID_TRAY_HELP, TEXT("Get Help"));
266+
AppendMenu(hMenu, MF_STRING, ID_TRAY_CHECKUPDATE, TEXT("Check Updates"));
267+
AppendMenu(hMenu, MF_STRING, ID_TRAY_VERSION_INFO, TEXT("Version Info (1.2.8)"));
268+
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
269+
// exit
274270
AppendMenu(hMenu, MF_STRING, ID_TRAY_EXIT_CONTEXT_MENU_ITEM, TEXT("Exit SnapKey"));
275271

276272
// Display the context menu
@@ -311,29 +307,50 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
311307
case WM_COMMAND:
312308
switch (LOWORD(wParam))
313309
{
314-
case ID_TRAY_EXIT_CONTEXT_MENU_ITEM:
310+
case ID_TRAY_EXIT_CONTEXT_MENU_ITEM: // context menu options
315311
PostQuitMessage(0);
316312
break;
317-
case ID_TRAY_VERSION_INFO:
313+
case ID_TRAY_VERSION_INFO: // get version info
318314
{
319315
std::string versionInfo = GetVersionInfo();
320-
MessageBox(hwnd, versionInfo.c_str(), TEXT("Version Info"), MB_OK);
316+
MessageBox(hwnd, versionInfo.c_str(), TEXT("SnapKey Version Info"), MB_OK);
321317
}
322318
break;
323-
case ID_TRAY_REBIND_KEYS:
319+
case ID_TRAY_REBIND_KEYS: // rebind keys - open cfg
324320
{
325321
ShellExecute(NULL, TEXT("open"), TEXT("config.cfg"), NULL, NULL, SW_SHOWNORMAL);
326322
}
327323
break;
328-
case ID_TRAY_RESTART_SNAPKEY:
324+
325+
case ID_TRAY_HELP: // get help - open README.pdf
326+
{
327+
ShellExecute(NULL, TEXT("open"), TEXT("README.pdf"), NULL, NULL, SW_SHOWNORMAL);
328+
}
329+
break;
330+
331+
case ID_TRAY_CHECKUPDATE: // check updates - open github release page
332+
{
333+
int result = MessageBox(NULL,
334+
TEXT("You are about to visit the SnapKey update page (github.com). Continue?"),
335+
TEXT("Update SnapKey"),
336+
MB_YESNO | MB_ICONQUESTION);
337+
338+
if (result == IDYES)
339+
{
340+
ShellExecute(NULL, TEXT("open"), TEXT("https://github.com/cafali/SnapKey/releases"), NULL, NULL, SW_SHOWNORMAL);
341+
}
342+
}
343+
break;
344+
345+
case ID_TRAY_RESTART_SNAPKEY: // restart snapkey
329346
{
330347
TCHAR szExeFileName[MAX_PATH];
331348
GetModuleFileName(NULL, szExeFileName, MAX_PATH);
332349
ShellExecute(NULL, NULL, szExeFileName, NULL, NULL, SW_SHOWNORMAL);
333350
PostQuitMessage(0);
334351
}
335352
break;
336-
case ID_TRAY_LOCK_FUNCTION:
353+
case ID_TRAY_LOCK_FUNCTION: // lock sticky keys
337354
{
338355
isLocked = !isLocked;
339356
HICON hIcon = isLocked
@@ -360,6 +377,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
360377
return 0;
361378
}
362379

380+
// version information window
381+
std::string GetVersionInfo() {
382+
return "SnapKey v1.2.8 (R17)\n"
383+
"Version Date: June 19, 2025\n"
384+
"Repository: github.com/cafali/SnapKey\n"
385+
"License: MIT License\n";
386+
}
387+
363388
// Function to copy snapkey.backup (meta folder) to the main directory
364389
void RestoreConfigFromBackup(const std::string& backupFilename, const std::string& destinationFilename)
365390
{
@@ -423,4 +448,4 @@ bool LoadConfig(const std::string& filename)
423448
}
424449
}
425450
return true;
426-
}
451+
}

resources.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ IDI_ICON1 ICON "snapkey.ico"
55

66
// Version information
77
1 VERSIONINFO
8-
FILEVERSION 1,2,7,0
9-
PRODUCTVERSION 1,2,7,0
8+
FILEVERSION 1,2,8,0
9+
PRODUCTVERSION 1,2,8,0
1010
FILEOS 0x40004
1111
FILETYPE 0x1
1212
{
@@ -20,8 +20,8 @@ FILETYPE 0x1
2020
VALUE "CompanyName", "cafali"
2121
VALUE "LegalCopyright", "Copyright \xA9 2025 cafali - MIT License (github.com/cafali/SnapKey)"
2222
VALUE "ProductName", "SnapKey"
23-
VALUE "FileVersion", "1.2.7.0"
24-
VALUE "ProductVersion", "1.2.7.0"
23+
VALUE "FileVersion", "1.2.8.0"
24+
VALUE "ProductVersion", "1.2.8.0"
2525
}
2626
}
2727

0 commit comments

Comments
 (0)