Skip to content

Commit

Permalink
fix #616; Integrate commands into Windows Terminal improve #615
Browse files Browse the repository at this point in the history
  • Loading branch information
VShawn committed Feb 21, 2024
1 parent 0d35db1 commit c2e47b7
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 80 deletions.
11 changes: 5 additions & 6 deletions Ui/Model/Protocol/AppArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Shawn.Utils;
using Shawn.Utils.Interface;
using Shawn.Utils.Wpf;
using Shawn.Utils.Wpf.FileSystem;

Expand Down Expand Up @@ -227,10 +226,10 @@ public string GetArgumentString(bool forDemo = false, LocalApp? app = null)
value = forDemo ? "******" : UnSafeStringEncipher.DecryptOrReturnOriginalString(Value);
}

if (value.IndexOf(" ", StringComparison.Ordinal) > 0)
{
value = $"\"{value}\"";
}
//if (value.IndexOf(" ", StringComparison.Ordinal) > 0)
//{
// value = $"\"{value}\"";
//}

value = $"{value}{(AddBlankAfterValue ? " " : "")}";

Expand Down Expand Up @@ -342,7 +341,7 @@ public bool IsDefaultValue()
}
if (string.IsNullOrEmpty(value) && type != AppArgumentType.Selection)
{
if (!isNullable || type == AppArgumentType.Const)
if (!isNullable && type != AppArgumentType.Const)
return new Tuple<bool, string>(false, IoC.Translate(LanguageService.CAN_NOT_BE_EMPTY));
else
return new Tuple<bool, string>(true, "");
Expand Down
102 changes: 100 additions & 2 deletions Ui/Model/Protocol/AppArgumentHelper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Documents;
using _1RM.Model.Protocol.Base;
using _1RM.Utils.KiTTY;

namespace _1RM.Model.Protocol;

Expand Down Expand Up @@ -278,6 +276,105 @@ public static class AppArgumentHelper
return null;
}


private static LocalApp? GetWindowsTerminalArgumentList(string path)
{
if (path.ToLower() == "wt"
|| path.IndexOf("wt.exe", StringComparison.OrdinalIgnoreCase) >= 0)
{
var argumentList = new List<AppArgument>
{
new AppArgument()
{
Type = AppArgumentType.Const,
Name = "misc1",
Key = "",
IsNullable = true,
Value = @$"-w 1 new-tab --title ""{ProtocolBaseWithAddressPort.MACRO_HOST_NAME}"" --suppressApplicationTitle plink",
AddBlankAfterKey = false,
AddBlankAfterValue = true,
},
new AppArgument()
{
Type = AppArgumentType.Const,
Name = "Host",
Key = "-ssh",
IsNullable = false,
Description = "The host name or IP address to connect to.",
Value = ProtocolBaseWithAddressPort.MACRO_HOST_NAME,
AddBlankAfterKey = true,
AddBlankAfterValue = true,
},
new AppArgument()
{
Type = AppArgumentType.Const,
Name = "Port",
Key = "-P",
IsNullable = false,
Description = "The port number to connect to.",
Value = ProtocolBaseWithAddressPort.MACRO_PORT,
AddBlankAfterKey = true,
AddBlankAfterValue = true,
},
new AppArgument()
{
Type = AppArgumentType.Const,
Name = "misc2",
Key = "",
IsNullable = true,
Value = "-C -X -no-antispoof",
AddBlankAfterKey = true,
AddBlankAfterValue = true,
},
new AppArgument()
{
Type = AppArgumentType.Const,
Name = "User Name",
Key = "-l",
IsNullable = true,
Description = "The user name to log in as on the remote machine.",
Value = ProtocolBaseWithAddressPortUserPwd.MACRO_USERNAME,
AddBlankAfterKey = true,
AddBlankAfterValue = true,
},
new AppArgument()
{
Type = AppArgumentType.Const,
Name = "Password",
Key = "-pw",
IsNullable = true,
Description = "The password to use for authentication.",
Value = ProtocolBaseWithAddressPortUserPwd.MACRO_PASSWORD,
AddBlankAfterKey = true,
AddBlankAfterValue = true,
},
};
// add auto cmd if kitty
if (path.IndexOf("kitty", StringComparison.OrdinalIgnoreCase) >= 0)
{
argumentList.Add(new AppArgument()
{
Type = AppArgumentType.Normal,
Name = "Auto Command",
Key = "-cmd",
IsNullable = true,
Description = "Run command after connected.",
AddBlankAfterKey = true,
AddBlankAfterValue = true,
});
}
var app = new LocalApp()
{
DisplayName = "Windows Terminal",
RunWithHosting = false,
ArgumentList = new ObservableCollection<AppArgument>(argumentList),
};
return app;
}
return null;
}


private static LocalApp? GetWinScp(string path)
{
if (path.IndexOf("winSCP.exe", StringComparison.OrdinalIgnoreCase) >= 0)
Expand Down Expand Up @@ -574,6 +671,7 @@ public static class AppArgumentHelper
{
exePath = exePath.ToLower();
return GetPuttyArgumentList(exePath)
?? GetWindowsTerminalArgumentList(exePath)
?? GetChrome(exePath)
?? GetFreeRdp(exePath)
?? GetWinScp(exePath)
Expand Down
1 change: 1 addition & 0 deletions Ui/Model/ProtocolRunner/ExternalRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public bool RunWithHosting
[JsonIgnore]
public List<string> MarcoNames { get; set; } = new();

[Obsolete]
public Dictionary<string, string> Params = new Dictionary<string, string>();
}
}
22 changes: 11 additions & 11 deletions Ui/Model/ProtocolRunner/ExternalRunnerForSSH.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using Newtonsoft.Json;
using _1RM.Model.Protocol;
using _1RM.Service;
using Shawn.Utils;

namespace _1RM.Model.ProtocolRunner
namespace _1RM.Model.ProtocolRunner
{
public class ExternalRunnerForSSH : ExternalRunner
{
Expand All @@ -16,11 +7,20 @@ public ExternalRunnerForSSH(string runnerName, string ownerProtocolName) : base(
}


private string _argumentsForPrivateKey = "";
public string ArgumentsForPrivateKey
{
get => Params.ContainsKey(nameof(ArgumentsForPrivateKey)) ? Params[nameof(ArgumentsForPrivateKey)] : "";
get
{
if (string.IsNullOrEmpty(_argumentsForPrivateKey) && Params.ContainsKey(nameof(ArgumentsForPrivateKey)))

Check warning on line 15 in Ui/Model/ProtocolRunner/ExternalRunnerForSSH.cs

View workflow job for this annotation

GitHub Actions / build_and_release

'ExternalRunner.Params' is obsolete
{
_argumentsForPrivateKey = Params[nameof(ArgumentsForPrivateKey)];
}
return _argumentsForPrivateKey;
}
set
{
_argumentsForPrivateKey = value;
if (Params.ContainsKey(nameof(ArgumentsForPrivateKey)) == false)
{
Params.Add(nameof(ArgumentsForPrivateKey), value);
Expand Down
8 changes: 0 additions & 8 deletions Ui/Service/ProtocolConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,6 @@ public void Save()
{
var protocolName = kv.Key;
var config = kv.Value;
foreach (var runner in config.Runners.Where(x => x is ExternalRunner))
{
var externalRunner = (ExternalRunner)runner;
foreach (var ev in externalRunner.EnvironmentVariables.ToArray().Where(x => string.IsNullOrWhiteSpace(x.Key)))
{
externalRunner.EnvironmentVariables.Remove(ev);
}
}
var file = Path.Combine(AppPathHelper.Instance.ProtocolRunnerDirPath, $"{protocolName}.json");
RetryHelper.Try(() =>
{
Expand Down
2 changes: 1 addition & 1 deletion Ui/Ui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</PropertyGroup>

<PropertyGroup>
<AssemblyVersion>1.0.0.40220</AssemblyVersion>
<AssemblyVersion>1.0.0.40221</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<Version>$(AssemblyVersion)</Version>
<Authors>Shawn</Authors>
Expand Down
Loading

0 comments on commit c2e47b7

Please sign in to comment.