Skip to content

Commit 6f67e90

Browse files
authored
Feature/powershell improvements (#1505)
* Feature: PowerShell resize added * Fix: Override host doesn't work * Update changelog
1 parent acff0f2 commit 6f67e90

File tree

11 files changed

+62
-35
lines changed

11 files changed

+62
-35
lines changed

Source/NETworkManager.Models/Generated Files/WinRTEventHelpers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
3-
// This file was generated by cswinrt.exe version 1.6.4.220527.1
3+
// This file was generated by cswinrt.exe version 2.0.0.220816.1
44
//
55
// Changes to this file may cause incorrect behavior and will be lost if
66
// the code is regenerated.

Source/NETworkManager.Profiles/Application/PowerShell.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static PowerShellSessionInfo CreateSessionInfo(ProfileInfo profile)
1313
return new PowerShellSessionInfo
1414
{
1515
EnableRemoteConsole = profile.PowerShell_EnableRemoteConsole,
16-
Host = profile.Host,
16+
Host = profile.PowerShell_Host,
1717

1818
AdditionalCommandLine = profile.PowerShell_OverrideAdditionalCommandLine ? profile.PowerShell_AdditionalCommandLine : (group.PowerShell_OverrideAdditionalCommandLine ? group.PowerShell_AdditionalCommandLine : SettingsManager.Current.PowerShell_AdditionalCommandLine),
1919
ExecutionPolicy = profile.PowerShell_OverrideExecutionPolicy ? profile.PowerShell_ExecutionPolicy : (group.PowerShell_OverrideExecutionPolicy ? group.PowerShell_ExecutionPolicy : SettingsManager.Current.PowerShell_ExecutionPolicy)

Source/NETworkManager.Profiles/Application/RemoteDesktop.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static RemoteDesktopSessionInfo CreateSessionInfo(ProfileInfo profile)
6464
GroupInfo group = ProfileManager.GetGroup(profile.Group);
6565

6666
// Override hostname
67-
info.Hostname = profile.Host;
67+
info.Hostname = profile.RemoteDesktop_Host;
6868

6969
// Network
7070
if (profile.RemoteDesktop_OverridePort)

Source/NETworkManager/Controls/DragablzTabHostWindow.xaml

+10
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@
162162
</Rectangle>
163163
</MenuItem.Icon>
164164
</MenuItem>
165+
<Separator />
166+
<MenuItem Header="{x:Static localization:Strings.Resize}" Command="{Binding Data.PuTTY_ResizeWindowCommand, Source={StaticResource BindingProxy}}" CommandParameter="{Binding View}">
167+
<MenuItem.Icon>
168+
<Rectangle Width="16" Height="16" Fill="{DynamicResource MahApps.Brushes.Gray3}">
169+
<Rectangle.OpacityMask>
170+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Modern Kind=ArrowExpand}" />
171+
</Rectangle.OpacityMask>
172+
</Rectangle>
173+
</MenuItem.Icon>
174+
</MenuItem>
165175
</ContextMenu>
166176
</Grid.ContextMenu>
167177
<Grid.InputBindings>

Source/NETworkManager/Controls/DragablzTabHostWindow.xaml.cs

+14-7
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ private async void RemoteDesktop_SendCtrlAltDelAction(object view)
187187
#endregion
188188

189189
#region PowerShell Commands
190+
private bool PowerShell_Disconnected_CanExecute(object view)
191+
{
192+
if (view is PowerShellControl control)
193+
return !control.IsConnected;
194+
195+
return false;
196+
}
197+
190198
public ICommand PowerShell_ReconnectCommand => new RelayCommand(PowerShell_ReconnectAction);
191199

192200
private void PowerShell_ReconnectAction(object view)
@@ -198,17 +206,16 @@ private void PowerShell_ReconnectAction(object view)
198206
}
199207
}
200208

201-
#endregion
209+
public ICommand PowerShell_ResizeWindowCommand => new RelayCommand(PowerShell_ResizeWindowAction, PowerShell_Disconnected_CanExecute);
202210

203-
#region PuTTY Commands
204-
private bool PuTTY_Disconnected_CanExecute(object view)
211+
private void PowerShell_ResizeWindowAction(object view)
205212
{
206-
if (view is PuTTYControl control)
207-
return !control.IsConnected;
208-
209-
return false;
213+
if (view is PowerShellControl control)
214+
control.ResizeEmbeddedWindow();
210215
}
216+
#endregion
211217

218+
#region PuTTY Commands
212219
private bool PuTTY_Connected_CanExecute(object view)
213220
{
214221
if (view is PuTTYControl control)

Source/NETworkManager/Controls/PowerShellControl.xaml.cs

+1-13
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,6 @@ private async Task Connect()
146146

147147
while ((DateTime.Now - startTime).TotalSeconds < 10)
148148
{
149-
// Fix for netcore3.1 https://stackoverflow.com/questions/60342879/process-mainwindowhandle-is-non-zero-in-net-framework-but-zero-in-net-core-unl
150-
/*
151-
try
152-
{
153-
_process = Process.GetProcessById(_process.Id);
154-
}
155-
catch
156-
{
157-
break; // Process has exited
158-
}
159-
*/
160-
161149
_process.Refresh();
162150

163151
if (_process.HasExited)
@@ -221,7 +209,7 @@ private void Process_Exited(object sender, EventArgs e)
221209
IsConnected = false;
222210
}
223211

224-
private void ResizeEmbeddedWindow()
212+
public void ResizeEmbeddedWindow()
225213
{
226214
if (IsConnected)
227215
NativeMethods.SetWindowPos(_process.MainWindowHandle, IntPtr.Zero, 0, 0, WindowHost.ClientSize.Width, WindowHost.ClientSize.Height, NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOACTIVATE);

Source/NETworkManager/Generated Files/WinRTEventHelpers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
3-
// This file was generated by cswinrt.exe version 1.6.4.220527.1
3+
// This file was generated by cswinrt.exe version 2.0.0.220816.1
44
//
55
// Changes to this file may cause incorrect behavior and will be lost if
66
// the code is regenerated.

Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs

+16
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ private void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)
233233
((args.DragablzItem.Content as DragablzTabItem)?.View as PowerShellControl)?.CloseTab();
234234
}
235235

236+
private bool PowerShell_Connected_CanExecute(object view)
237+
{
238+
if (view is PowerShellControl control)
239+
return control.IsConnected;
240+
241+
return false;
242+
}
243+
236244
public ICommand PowerShell_ReconnectCommand => new RelayCommand(PowerShell_ReconnectAction);
237245

238246
private void PowerShell_ReconnectAction(object view)
@@ -244,6 +252,14 @@ private void PowerShell_ReconnectAction(object view)
244252
}
245253
}
246254

255+
public ICommand PowerShell_ResizeWindowCommand => new RelayCommand(PowerShell_ResizeWindowAction, PowerShell_Connected_CanExecute);
256+
257+
private void PowerShell_ResizeWindowAction(object view)
258+
{
259+
if (view is PowerShellControl control)
260+
control.ResizeEmbeddedWindow();
261+
}
262+
247263
public ICommand ConnectCommand => new RelayCommand(p => ConnectAction(), Connect_CanExecute);
248264

249265
private bool Connect_CanExecute(object obj) => IsConfigured;

Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs

-8
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,6 @@ private void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)
238238
((args.DragablzItem.Content as DragablzTabItem)?.View as PuTTYControl)?.CloseTab();
239239
}
240240

241-
private bool PuTTY_Disconnected_CanExecute(object view)
242-
{
243-
if (view is PuTTYControl control)
244-
return !control.IsConnected;
245-
246-
return false;
247-
}
248-
249241
private bool PuTTY_Connected_CanExecute(object view)
250242
{
251243
if (view is PuTTYControl control)

Source/NETworkManager/Views/PowerShellHostView.xaml

+10
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@
8484
</Rectangle>
8585
</MenuItem.Icon>
8686
</MenuItem>
87+
<Separator />
88+
<MenuItem Header="{x:Static localization:Strings.Resize}" Command="{Binding Data.PowerShell_ResizeWindowCommand, Source={StaticResource BindingProxy}}" CommandParameter="{Binding View}">
89+
<MenuItem.Icon>
90+
<Rectangle Width="16" Height="16" Fill="{DynamicResource MahApps.Brushes.Gray3}">
91+
<Rectangle.OpacityMask>
92+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Modern Kind=ArrowExpand}" />
93+
</Rectangle.OpacityMask>
94+
</Rectangle>
95+
</MenuItem.Icon>
96+
</MenuItem>
8797
</ContextMenu>
8898
</Grid.ContextMenu>
8999
<Grid.InputBindings>

docs/Changelog/next-release.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,21 @@ permalink: /Changelog/next-release
2222
## Improvements
2323
- Profiles
2424
- Migration dialog improved [#1393](https://github.com/BornToBeRoot/NETworkManager/pull/1393){:target="_blank"}
25-
- Select app when creating a profile (#1466)(https://github.com/BornToBeRoot/NETworkManager/pull/1466){:target="_blank"}
25+
- Select app when creating a profile [#1466](https://github.com/BornToBeRoot/NETworkManager/pull/1466){:target="_blank"}
2626
- Port Scanner
2727
- Generate Port list at first run [#1464](https://github.com/BornToBeRoot/NETworkManager/pull/1464){:target="_blank"}
2828
- DNS Lookup
2929
- Generate DNS server list at first run [#1464](https://github.com/BornToBeRoot/NETworkManager/pull/1464){:target="_blank"}
30+
- PowerShell
31+
- Resize PowerShell window [#1505](https://github.com/BornToBeRoot/NETworkManager/pull/1505){:target="_blank"}
3032

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

0 commit comments

Comments
 (0)