Skip to content

Commit 1b46d35

Browse files
authored
Merge pull request #36 from scottchiefbaker/master
Feature: Make the refresh menu show a status if it worked or not
2 parents 1d8a10c + 5abd11a commit 1b46d35

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

OpenKeys/OpenKeys.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,10 @@ void CloseWindowAndExit() {
386386
PostQuitMessage(0);
387387
}
388388

389-
void LoadShortcuts() {
389+
int8_t LoadShortcuts() {
390390
shortcuts.clear();
391391
nlohmann::json jsonFILE = LoadJsonFromFile(json_path);
392+
uint8_t ret = 0; // Default return value
392393

393394
// If there is no local JSON file, we download the default one from github
394395
if (jsonFILE.empty()) {
@@ -409,7 +410,7 @@ void LoadShortcuts() {
409410
if (!file.good() || !std::filesystem::exists(json_path)) {
410411
log_line("Failed to create shortcuts.json file.");
411412
ErrorMessage(12, L"Failed to create shortcuts.json file. Please check permissions.");
412-
return;
413+
return -8;
413414
}
414415

415416
jsonFILE = LoadJsonFromFile(json_path);
@@ -422,7 +423,7 @@ void LoadShortcuts() {
422423
if (jsonURL.empty()) {
423424
log_line("Failed to load JSON from URL: " + jsonFILE["external_url"].get<std::string>());
424425
WarningMessage(L"Warning", L"The URL you provided does not contain valid JSON. URL ignored.");
425-
return;
426+
return -9;
426427
}
427428

428429
// The local version and remote versions are different
@@ -448,19 +449,31 @@ void LoadShortcuts() {
448449
log_line("Overwrote local JSON with the one from the URL");
449450

450451
jsonFILE = LoadJsonFromFile(json_path); // Reload the JSON from the file
452+
453+
ret = 1; // We got a new JSON file from the URL
451454
}
452455
// If the user chooses not to overwrite, we use the local JSON
453456
else {
454457
log_line("Did not overwrite local JSON, using local data");
458+
459+
ret = -1; // No need to overwrite, user chose not to
455460
}
456461
}
457462
else if (jsonURL["version"] == jsonFILE["version"]) {
458463
log_line("Local and remote versions are the same");
464+
465+
ret = -2; // No need to overwrite, versions match
459466
}
460467

461468
}
469+
else {
470+
ret = -3; // No external URL, so we just use the local data
471+
}
472+
462473
LoadDataFromJson(jsonFILE);
463474
UpdateDisplayedTextFromShortcuts();
475+
476+
return ret;
464477
}
465478
// Forward declarations of functions included in this code module:
466479
ATOM MyRegisterClass(HINSTANCE hInstance);
@@ -793,10 +806,20 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
793806
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
794807
break;
795808
case IDM_REFRESH_BUTTON:
796-
log_line("Reloaded JSON file");
797-
LoadShortcuts();
798-
UpdateDisplayedTextFromShortcuts();
799-
break;
809+
{
810+
log_line("Reloaded JSON file");
811+
int8_t status = LoadShortcuts();
812+
813+
if (status == 1) {
814+
InfoMessage(L"Loaded new shortcuts from server");
815+
}
816+
else if (status == -2) {
817+
InfoMessage(L"Remote server does not have new shortcuts file");
818+
}
819+
820+
UpdateDisplayedTextFromShortcuts();
821+
break;
822+
}
800823
case IDM_FILE_OPENDATA:
801824
// Open the OpenKeys %APPDATA% directory in Windows Explorer
802825
if (!DirectoryExists(appDataDir)) {

0 commit comments

Comments
 (0)