Skip to content

Commit

Permalink
Feature/powershell improvements (#1505)
Browse files Browse the repository at this point in the history
* Feature: PowerShell resize added

* Fix: Override host doesn't work

* Update changelog
  • Loading branch information
BornToBeRoot authored Aug 17, 2022
1 parent acff0f2 commit 6f67e90
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This file was generated by cswinrt.exe version 1.6.4.220527.1
// This file was generated by cswinrt.exe version 2.0.0.220816.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager.Profiles/Application/PowerShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static PowerShellSessionInfo CreateSessionInfo(ProfileInfo profile)
return new PowerShellSessionInfo
{
EnableRemoteConsole = profile.PowerShell_EnableRemoteConsole,
Host = profile.Host,
Host = profile.PowerShell_Host,

AdditionalCommandLine = profile.PowerShell_OverrideAdditionalCommandLine ? profile.PowerShell_AdditionalCommandLine : (group.PowerShell_OverrideAdditionalCommandLine ? group.PowerShell_AdditionalCommandLine : SettingsManager.Current.PowerShell_AdditionalCommandLine),
ExecutionPolicy = profile.PowerShell_OverrideExecutionPolicy ? profile.PowerShell_ExecutionPolicy : (group.PowerShell_OverrideExecutionPolicy ? group.PowerShell_ExecutionPolicy : SettingsManager.Current.PowerShell_ExecutionPolicy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static RemoteDesktopSessionInfo CreateSessionInfo(ProfileInfo profile)
GroupInfo group = ProfileManager.GetGroup(profile.Group);

// Override hostname
info.Hostname = profile.Host;
info.Hostname = profile.RemoteDesktop_Host;

// Network
if (profile.RemoteDesktop_OverridePort)
Expand Down
10 changes: 10 additions & 0 deletions Source/NETworkManager/Controls/DragablzTabHostWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@
</Rectangle>
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="{x:Static localization:Strings.Resize}" Command="{Binding Data.PuTTY_ResizeWindowCommand, Source={StaticResource BindingProxy}}" CommandParameter="{Binding View}">
<MenuItem.Icon>
<Rectangle Width="16" Height="16" Fill="{DynamicResource MahApps.Brushes.Gray3}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Modern Kind=ArrowExpand}" />
</Rectangle.OpacityMask>
</Rectangle>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Grid.ContextMenu>
<Grid.InputBindings>
Expand Down
21 changes: 14 additions & 7 deletions Source/NETworkManager/Controls/DragablzTabHostWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ private async void RemoteDesktop_SendCtrlAltDelAction(object view)
#endregion

#region PowerShell Commands
private bool PowerShell_Disconnected_CanExecute(object view)
{
if (view is PowerShellControl control)
return !control.IsConnected;

return false;
}

public ICommand PowerShell_ReconnectCommand => new RelayCommand(PowerShell_ReconnectAction);

private void PowerShell_ReconnectAction(object view)
Expand All @@ -198,17 +206,16 @@ private void PowerShell_ReconnectAction(object view)
}
}

#endregion
public ICommand PowerShell_ResizeWindowCommand => new RelayCommand(PowerShell_ResizeWindowAction, PowerShell_Disconnected_CanExecute);

#region PuTTY Commands
private bool PuTTY_Disconnected_CanExecute(object view)
private void PowerShell_ResizeWindowAction(object view)
{
if (view is PuTTYControl control)
return !control.IsConnected;

return false;
if (view is PowerShellControl control)
control.ResizeEmbeddedWindow();
}
#endregion

#region PuTTY Commands
private bool PuTTY_Connected_CanExecute(object view)
{
if (view is PuTTYControl control)
Expand Down
14 changes: 1 addition & 13 deletions Source/NETworkManager/Controls/PowerShellControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,6 @@ private async Task Connect()

while ((DateTime.Now - startTime).TotalSeconds < 10)
{
// Fix for netcore3.1 https://stackoverflow.com/questions/60342879/process-mainwindowhandle-is-non-zero-in-net-framework-but-zero-in-net-core-unl
/*
try
{
_process = Process.GetProcessById(_process.Id);
}
catch
{
break; // Process has exited
}
*/

_process.Refresh();

if (_process.HasExited)
Expand Down Expand Up @@ -221,7 +209,7 @@ private void Process_Exited(object sender, EventArgs e)
IsConnected = false;
}

private void ResizeEmbeddedWindow()
public void ResizeEmbeddedWindow()
{
if (IsConnected)
NativeMethods.SetWindowPos(_process.MainWindowHandle, IntPtr.Zero, 0, 0, WindowHost.ClientSize.Width, WindowHost.ClientSize.Height, NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOACTIVATE);
Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager/Generated Files/WinRTEventHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This file was generated by cswinrt.exe version 1.6.4.220527.1
// This file was generated by cswinrt.exe version 2.0.0.220816.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down
16 changes: 16 additions & 0 deletions Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ private void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)
((args.DragablzItem.Content as DragablzTabItem)?.View as PowerShellControl)?.CloseTab();
}

private bool PowerShell_Connected_CanExecute(object view)
{
if (view is PowerShellControl control)
return control.IsConnected;

return false;
}

public ICommand PowerShell_ReconnectCommand => new RelayCommand(PowerShell_ReconnectAction);

private void PowerShell_ReconnectAction(object view)
Expand All @@ -244,6 +252,14 @@ private void PowerShell_ReconnectAction(object view)
}
}

public ICommand PowerShell_ResizeWindowCommand => new RelayCommand(PowerShell_ResizeWindowAction, PowerShell_Connected_CanExecute);

private void PowerShell_ResizeWindowAction(object view)
{
if (view is PowerShellControl control)
control.ResizeEmbeddedWindow();
}

public ICommand ConnectCommand => new RelayCommand(p => ConnectAction(), Connect_CanExecute);

private bool Connect_CanExecute(object obj) => IsConfigured;
Expand Down
8 changes: 0 additions & 8 deletions Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,6 @@ private void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)
((args.DragablzItem.Content as DragablzTabItem)?.View as PuTTYControl)?.CloseTab();
}

private bool PuTTY_Disconnected_CanExecute(object view)
{
if (view is PuTTYControl control)
return !control.IsConnected;

return false;
}

private bool PuTTY_Connected_CanExecute(object view)
{
if (view is PuTTYControl control)
Expand Down
10 changes: 10 additions & 0 deletions Source/NETworkManager/Views/PowerShellHostView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@
</Rectangle>
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="{x:Static localization:Strings.Resize}" Command="{Binding Data.PowerShell_ResizeWindowCommand, Source={StaticResource BindingProxy}}" CommandParameter="{Binding View}">
<MenuItem.Icon>
<Rectangle Width="16" Height="16" Fill="{DynamicResource MahApps.Brushes.Gray3}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Modern Kind=ArrowExpand}" />
</Rectangle.OpacityMask>
</Rectangle>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Grid.ContextMenu>
<Grid.InputBindings>
Expand Down
10 changes: 7 additions & 3 deletions docs/Changelog/next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ permalink: /Changelog/next-release
## Improvements
- Profiles
- Migration dialog improved [#1393](https://github.com/BornToBeRoot/NETworkManager/pull/1393){:target="_blank"}
- Select app when creating a profile (#1466)(https://github.com/BornToBeRoot/NETworkManager/pull/1466){:target="_blank"}
- Select app when creating a profile [#1466](https://github.com/BornToBeRoot/NETworkManager/pull/1466){:target="_blank"}
- Port Scanner
- Generate Port list at first run [#1464](https://github.com/BornToBeRoot/NETworkManager/pull/1464){:target="_blank"}
- DNS Lookup
- Generate DNS server list at first run [#1464](https://github.com/BornToBeRoot/NETworkManager/pull/1464){:target="_blank"}
- PowerShell
- Resize PowerShell window [#1505](https://github.com/BornToBeRoot/NETworkManager/pull/1505){:target="_blank"}

## Bugfixes
- Dashboard / Status Window
- Dashboard & Status Window
- Detect local ipv6 address fixed [#1423](https://github.com/BornToBeRoot/NETworkManager/pull/1423){:target="_blank"}
- IP Scanner / OUI Lookup
- IP Scanner & OUI Lookup
- Use ieee.org instead of linuxnet.ca to generate the oui.txt [#1463](https://github.com/BornToBeRoot/NETworkManager/pull/1463){:target="_blank"}
- Remote Desktop & PuTTY
- Override host doesn't set the correct hostname [#1505](https://github.com/BornToBeRoot/NETworkManager/pull/1505){:target="_blank"}
- Profiles
- Fixed some rare cases where the profile file was overwritten [#1449](https://github.com/BornToBeRoot/NETworkManager/pull/1449){:target="_blank"}
- Header in add group dialog fixed [#1461](https://github.com/BornToBeRoot/NETworkManager/pull/1461){:target="_blank"}
Expand Down

0 comments on commit 6f67e90

Please sign in to comment.