Skip to content

Commit

Permalink
Allowed AppSpecific shortcut and fixed backup/restore shortcut dups
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflord committed Dec 16, 2023
1 parent 56c82e7 commit bf49d2f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s
}
else if (shortcutType == ShortcutControl::ShortcutType::RunProgram)
{
targetAppTextBox.IsEnabled(false);
//targetAppTextBox.IsEnabled(false);
grid.Visibility(Visibility::Collapsed);
shortcutButton.Visibility(Visibility::Collapsed);
textInput.Visibility(Visibility::Collapsed);
Expand All @@ -219,7 +219,7 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s
}
else
{
targetAppTextBox.IsEnabled(false);
//targetAppTextBox.IsEnabled(false);
grid.Visibility(Visibility::Collapsed);
shortcutButton.Visibility(Visibility::Collapsed);
textInput.Visibility(Visibility::Collapsed);
Expand Down
67 changes: 65 additions & 2 deletions src/modules/keyboardmanager/common/MappingConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,44 @@ bool MappingConfiguration::LoadAppSpecificShortcutRemaps(const json::JsonObject&
auto newRemapKeys = it.GetObjectW().GetNamedString(KeyboardManagerConstants::NewRemapKeysSettingName, {});
auto newRemapText = it.GetObjectW().GetNamedString(KeyboardManagerConstants::NewTextSettingName, {});
auto targetApp = it.GetObjectW().GetNamedString(KeyboardManagerConstants::TargetAppSettingName);
auto operationType = it.GetObjectW().GetNamedNumber(KeyboardManagerConstants::ShortcutOperationType, 0);

if (operationType == 1)
{
auto runProgramFilePath = it.GetObjectW().GetNamedString(KeyboardManagerConstants::RunProgramFilePathSettingName, L"");
auto runProgramArgs = it.GetObjectW().GetNamedString(KeyboardManagerConstants::RunProgramArgsSettingName, L"");
auto runProgramStartInDir = it.GetObjectW().GetNamedString(KeyboardManagerConstants::RunProgramStartInDirSettingName, L"");
auto runProgramElevationLevel = it.GetObjectW().GetNamedNumber(KeyboardManagerConstants::RunProgramElevationLevelSettingName, 0);
auto secondKeyOfChord = it.GetObjectW().GetNamedNumber(KeyboardManagerConstants::ShortcutSecondKeyOfChordSettingName, 0);

auto elevationLevel = Shortcut::ElevationLevel::NonElevated;
if (runProgramElevationLevel == 1)
{
elevationLevel = Shortcut::ElevationLevel::Elevated;
}
else if (runProgramElevationLevel == 2)
{
elevationLevel = Shortcut::ElevationLevel::DifferentUser;
}

auto tempShortcut = Shortcut(newRemapKeys.c_str());
tempShortcut.operationType = Shortcut::OperationType::RunProgram;
tempShortcut.runProgramFilePath = runProgramFilePath;
tempShortcut.elevationLevel = elevationLevel;
tempShortcut.runProgramArgs = runProgramArgs;
tempShortcut.runProgramStartInDir = runProgramStartInDir;

AddAppSpecificShortcut(targetApp.c_str(), Shortcut(originalKeys.c_str(), static_cast<DWORD>(secondKeyOfChord)), tempShortcut);
}
else if (operationType == 2)
{
auto secondKeyOfChord = it.GetObjectW().GetNamedNumber(KeyboardManagerConstants::ShortcutSecondKeyOfChordSettingName, 0);
auto tempShortcut = Shortcut(newRemapKeys.c_str());
tempShortcut.operationType = Shortcut::OperationType::OpenURI;
tempShortcut.uriToOpen = it.GetObjectW().GetNamedString(KeyboardManagerConstants::ShortcutOpenURI, L"");

AddAppSpecificShortcut(targetApp.c_str(), Shortcut(originalKeys.c_str(), static_cast<DWORD>(secondKeyOfChord)), tempShortcut);
}

if (!newRemapKeys.empty())
{
Expand Down Expand Up @@ -268,7 +306,6 @@ bool MappingConfiguration::LoadShortcutRemaps(const json::JsonObject& jsonData,
auto originalKeys = it.GetObjectW().GetNamedString(KeyboardManagerConstants::OriginalKeysSettingName);
auto newRemapKeys = it.GetObjectW().GetNamedString(KeyboardManagerConstants::NewRemapKeysSettingName, {});
auto newRemapText = it.GetObjectW().GetNamedString(KeyboardManagerConstants::NewTextSettingName, {});
//auto isRunProgram = it.GetObjectW().GetNamedBoolean(KeyboardManagerConstants::IsRunProgramSettingName, false);
auto operationType = it.GetObjectW().GetNamedNumber(KeyboardManagerConstants::ShortcutOperationType, 0);

if (operationType == 1)
Expand Down Expand Up @@ -515,7 +552,33 @@ bool MappingConfiguration::SaveSettingsToFile()
// For shortcut to shortcut remapping
else if (itKeys.second.targetShortcut.index() == 1)
{
keys.SetNamedValue(KeyboardManagerConstants::NewRemapKeysSettingName, json::value(std::get<Shortcut>(itKeys.second.targetShortcut).ToHstringVK()));
auto targetShortcut = std::get<Shortcut>(itKeys.second.targetShortcut);

//keys.SetNamedValue(KeyboardManagerConstants::IsRunProgramSettingName, json::value(targetShortcut.isRunProgram));

if (targetShortcut.operationType == Shortcut::OperationType::RunProgram)
{
keys.SetNamedValue(KeyboardManagerConstants::RunProgramElevationLevelSettingName, json::value(static_cast<unsigned int>(targetShortcut.elevationLevel)));
keys.SetNamedValue(KeyboardManagerConstants::ShortcutSecondKeyOfChordSettingName, json::value(static_cast<unsigned int>(itKeys.first.secondKey)));
keys.SetNamedValue(KeyboardManagerConstants::ShortcutOperationType, json::value(static_cast<unsigned int>(targetShortcut.operationType)));

keys.SetNamedValue(KeyboardManagerConstants::RunProgramFilePathSettingName, json::value(targetShortcut.runProgramFilePath));
keys.SetNamedValue(KeyboardManagerConstants::RunProgramArgsSettingName, json::value(targetShortcut.runProgramArgs));
keys.SetNamedValue(KeyboardManagerConstants::RunProgramStartInDirSettingName, json::value(targetShortcut.runProgramStartInDir));
}
else if (targetShortcut.operationType == Shortcut::OperationType::OpenURI)
{
keys.SetNamedValue(KeyboardManagerConstants::RunProgramElevationLevelSettingName, json::value(static_cast<unsigned int>(targetShortcut.elevationLevel)));
keys.SetNamedValue(KeyboardManagerConstants::ShortcutSecondKeyOfChordSettingName, json::value(static_cast<unsigned int>(itKeys.first.secondKey)));
keys.SetNamedValue(KeyboardManagerConstants::ShortcutOperationType, json::value(static_cast<unsigned int>(targetShortcut.operationType)));

keys.SetNamedValue(KeyboardManagerConstants::ShortcutOpenURI, json::value(targetShortcut.uriToOpen));
}
else
{
keys.SetNamedValue(KeyboardManagerConstants::ShortcutOperationType, json::value(static_cast<unsigned int>(targetShortcut.operationType)));
keys.SetNamedValue(KeyboardManagerConstants::NewRemapKeysSettingName, json::value(std::get<Shortcut>(itKeys.second.targetShortcut).ToHstringVK()));
}
}
else if (itKeys.second.targetShortcut.index() == 2)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,23 @@ public static string GetRegSettingsBackupAndRestoreRegItem(string itemName)
// the settings file needs to be updated, update the real one with non-excluded stuff...
Logger.LogInfo($"Settings file {currentFile.Key} is different and is getting updated from backup");

var newCurrentSettingsFile = JsonMergeHelper.Merge(File.ReadAllText(currentSettingsFiles[currentFile.Key]), settingsToRestoreJson);
File.WriteAllText(currentSettingsFiles[currentFile.Key], newCurrentSettingsFile);
var overwrite = false;
if (backupRestoreSettings["CustomRestoreSettings"] != null && backupRestoreSettings["CustomRestoreSettings"][currentFile.Key] != null)
{
var customRestoreSettings = backupRestoreSettings["CustomRestoreSettings"][currentFile.Key];
overwrite = customRestoreSettings["overwrite"] != null && (bool)customRestoreSettings["overwrite"];
}

if (overwrite)
{
File.WriteAllText(currentSettingsFiles[currentFile.Key], settingsToRestoreJson);
}
else
{
var newCurrentSettingsFile = JsonMergeHelper.Merge(File.ReadAllText(currentSettingsFiles[currentFile.Key]), settingsToRestoreJson);
File.WriteAllText(currentSettingsFiles[currentFile.Key], newCurrentSettingsFile);
}

anyFilesUpdated = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
]
}
],
"CustomRestoreSettings": {
"\\Keyboard Manager\\default.json": {
"overwrite": true
}
},
"IgnoredSettings": {
"backup-restore_settings.json": [
"RestartAfterRestore"
Expand Down

1 comment on commit bf49d2f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (30)
ALLOWCHORDS
ARGSFORPROGRAM
BIF
BROWSEINFO
CKBH
cmdow
commdlg
CRTL
ELEVATIONTYPEDIFFERENTUSER
ELEVATIONTYPEELEVATED
ELEVATIONTYPENORMAL
FILEMUSTEXIST
Lencode
LPITEMIDLIST
lpstr
NEWDIALOGSTYLE
ofn
OPENFILENAME
PATHMUSTEXIST
PATHTOPROGRAM
PROCESSENTRY
RETURNONLYFSDIRS
ritchielawrence
runasuser
SNAPPROCESS
STARTINDIRFORPROGRAM
tlhelp
Toolhelp
urlmon
wcsicmp
Previously acknowledged words that are now absent CHT constexpr DEU hashcode HEB JPN LAlt Lambson langword nodiscard pcs qps roundf RUS RValue SVE tonos weakme wifi 🫥
To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the git@github.com:jefflord/PowerToys.git repository
on the launch-apps-3350 branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https://github.com/jefflord/PowerToys/actions/runs/7228878848/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (1857) from .github/actions/spell-check/expect.txt and unrecognized words (30)

Dictionary Entries Covers Uniquely
cspell:r/src/r.txt 543 1 1
cspell:cpp/src/people.txt 23 1
cspell:cpp/src/ecosystem.txt 51 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/check-spelling@v0.0.22 in its with:

      with:
        extra_dictionaries:
          cspell:r/src/r.txt
          cspell:cpp/src/people.txt
          cspell:cpp/src/ecosystem.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/check-spelling@v0.0.22 in its with:

check_extra_dictionaries: ''
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.