Skip to content

Commit

Permalink
feat: custom actions (preliminary)
Browse files Browse the repository at this point in the history
  • Loading branch information
flexits committed Jan 6, 2024
1 parent 60a78ca commit d64abf7
Show file tree
Hide file tree
Showing 20 changed files with 1,074 additions and 115 deletions.
Binary file added publish/Gma.System.MouseKeyHook.dll
Binary file not shown.
42 changes: 42 additions & 0 deletions publish/HotCornersWin.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v7.0/win-x64",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v7.0": {},
".NETCoreApp,Version=v7.0/win-x64": {
"HotCornersWin/1.0.0": {
"dependencies": {
"MouseKeyHook": "5.7.1"
},
"runtime": {
"HotCornersWin.dll": {}
}
},
"MouseKeyHook/5.7.1": {
"runtime": {
"lib/net7.0-windows7.0/Gma.System.MouseKeyHook.dll": {
"assemblyVersion": "5.7.1.0",
"fileVersion": "5.7.1.0"
}
}
}
}
},
"libraries": {
"HotCornersWin/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"MouseKeyHook/5.7.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-c0VhB6cbcOpMOcoCQmvPMVqxaH76S4IPHwpbCIY7XKUNimdj9+81rX+Evnu5O53xYgUvdD7g0qmlVeZP2wGCnA==",
"path": "mousekeyhook/5.7.1",
"hashPath": "mousekeyhook.5.7.1.nupkg.sha512"
}
}
}
Binary file added publish/HotCornersWin.dll
Binary file not shown.
54 changes: 54 additions & 0 deletions publish/HotCornersWin.dll.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="HotCornersWin.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<HotCornersWin.Properties.Settings>
<setting name="IsEnabled" serializeAs="String">
<value>True</value>
</setting>
<setting name="LeftTop" serializeAs="String">
<value>none</value>
</setting>
<setting name="RightTop" serializeAs="String">
<value>none</value>
</setting>
<setting name="LeftBottom" serializeAs="String">
<value />
</setting>
<setting name="RightBottom" serializeAs="String">
<value />
</setting>
<setting name="MultiMonCfg" serializeAs="String">
<value>0</value>
</setting>
<setting name="AreaSize" serializeAs="String">
<value>5</value>
</setting>
<setting name="PollInterval" serializeAs="String">
<value>75</value>
</setting>
<setting name="AutoFullscreen" serializeAs="String">
<value>True</value>
</setting>
<setting name="DelayLT" serializeAs="String">
<value>0</value>
</setting>
<setting name="DelayRT" serializeAs="String">
<value>0</value>
</setting>
<setting name="DelayLB" serializeAs="String">
<value>0</value>
</setting>
<setting name="DelayRB" serializeAs="String">
<value>0</value>
</setting>
<setting name="CustomActions" serializeAs="String">
<value>"{\"Calculator\":\"calc.exe\",\"GitHub\":\"https://github.com/flexits/\",\"All Tasks\":\"Shell:::{ED7BA470-8E54-465E-825C-99712043E01C}\"}"</value>
</setting>
</HotCornersWin.Properties.Settings>
</userSettings>
</configuration>
Binary file added publish/HotCornersWin.exe
Binary file not shown.
18 changes: 18 additions & 0 deletions publish/HotCornersWin.runtimeconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"runtimeOptions": {
"tfm": "net7.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "7.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "7.0.0"
}
],
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false
}
}
}
4 changes: 2 additions & 2 deletions src/HotCornersWin.Installer/HotCornersWin.Installer.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:HotCornersWin"
"ProductCode" = "8:{C77DB6CC-290E-4B8F-9CB4-8F56B09C3B6E}"
"PackageCode" = "8:{6082511D-1A44-422E-9582-8583522D3D60}"
"PackageCode" = "8:{74B5A9B5-8109-4082-80E1-B0BAB828D915}"
"UpgradeCode" = "8:{EB9819AE-B33C-412C-AC3A-FFF208CFFC44}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:FALSE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:0.7.0"
"ProductVersion" = "8:0.8.0"
"Manufacturer" = "8:HotCornersWin"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down
3 changes: 3 additions & 0 deletions src/HotCornersWin/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<setting name="DelayRB" serializeAs="String">
<value>0</value>
</setting>
<setting name="CustomActions" serializeAs="String">
<value>"{\"Calculator\":\"calc.exe\",\"GitHub\":\"https://github.com/flexits/\",\"All Tasks\":\"Shell:::{ED7BA470-8E54-465E-825C-99712043E01C}\"}"</value>
</setting>
</HotCornersWin.Properties.Settings>
</userSettings>
</configuration>
84 changes: 77 additions & 7 deletions src/HotCornersWin/CornersSettingsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace HotCornersWin
using System.Diagnostics;
using System.Text.Json;

namespace HotCornersWin
{
/// <summary>
/// Wrapper around the app's settings providing access
Expand All @@ -7,9 +10,47 @@
public static class CornersSettingsHelper
{
/// <summary>
/// All available actions and their human-readable names.
/// User-adjustable actions.
/// Dictionary key is the action name,
/// dictionary value is the Windows shell command.
/// </summary>
private static Dictionary<string, Action> _allActions = new()
public static Dictionary<string, string> CustomActionCommands
{
get
{
try
{
var actions = JsonSerializer.
Deserialize<Dictionary<string, string>>(Properties.Settings.Default.CustomActions);
if (actions is null)
{
return new Dictionary<string, string>();
}
else
{
return actions;
}
}
catch
{
return new Dictionary<string, string>();
}
}
set
{
try
{
Properties.Settings.Default.CustomActions = JsonSerializer.Serialize(value);
Properties.Settings.Default.Save();
}
catch { }
}
}

/// <summary>
/// Predefined actions and their human-readable names.
/// </summary>
private static readonly Dictionary<string, Action> _predefinedActions = new()
{
{Properties.Resources.saNone, () => { } },
{Properties.Resources.saStartMenu, () => {SendKeys.SendWait("^{ESC}"); } },
Expand Down Expand Up @@ -92,6 +133,11 @@ public static class CornersSettingsHelper
},
};

/// <summary>
/// All available actions and their human-readable names.
/// </summary>
private static Dictionary<string, Action> _allActions = new();

/// <summary>
/// Hot corners and their correspondent actions as configured in the settings.
/// </summary>
Expand Down Expand Up @@ -124,6 +170,34 @@ static CornersSettingsHelper()
/// </summary>
public static void ReloadSettings()
{
_cornerDelays[Corners.LeftTop] = Properties.Settings.Default.DelayLT;
_cornerDelays[Corners.LeftBottom] = Properties.Settings.Default.DelayLB;
_cornerDelays[Corners.RightTop] = Properties.Settings.Default.DelayRT;
_cornerDelays[Corners.RightBottom] = Properties.Settings.Default.DelayRB;

_allActions.Clear();
foreach (var action in _predefinedActions)
{
_ = _allActions.TryAdd(action.Key, action.Value);
}
foreach (var command in CustomActionCommands)
{
if (string.IsNullOrEmpty(command.Value))
{
continue;
}
_ = _allActions.TryAdd(command.Key, () =>
{
_ = new Process
{
StartInfo = new ProcessStartInfo(command.Value)
{
UseShellExecute = true
}
}.Start();
});
}

_cornerActions[Corners.LeftTop] = _allActions
.TryGetValue(Properties.Settings.Default.LeftTop, out Action? actionLT) ? actionLT : (() => { });
_cornerActions[Corners.LeftBottom] = _allActions
Expand All @@ -132,10 +206,6 @@ public static void ReloadSettings()
.TryGetValue(Properties.Settings.Default.RightTop, out Action? actionRT) ? actionRT : (() => { });
_cornerActions[Corners.RightBottom] = _allActions
.TryGetValue(Properties.Settings.Default.RightBottom, out Action? actionRB) ? actionRB : (() => { });
_cornerDelays[Corners.LeftTop] = Properties.Settings.Default.DelayLT;
_cornerDelays[Corners.LeftBottom] = Properties.Settings.Default.DelayLB;
_cornerDelays[Corners.RightTop] = Properties.Settings.Default.DelayRT;
_cornerDelays[Corners.RightBottom] = Properties.Settings.Default.DelayRB;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/HotCornersWin/FormAbout.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d64abf7

Please sign in to comment.