Skip to content

Commit bb5af05

Browse files
committed
Implement Debug Point, basically a console log that only outputs while in debug mode. Also updated README.md
1 parent dd2bb16 commit bb5af05

File tree

7 files changed

+55
-34
lines changed

7 files changed

+55
-34
lines changed

Classes/pveAPI/ApiClient.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Net.Http.Headers;
55
using System.Security.Policy;
66
using System.Text;
7+
using System.Threading;
78
using System.Threading.Tasks;
89
using System.Windows.Forms;
910
using Newtonsoft.Json;
@@ -47,22 +48,30 @@ public ApiClient(string server, string port, bool skipSSL)
4748

4849
public async Task<List<RealmData>> GetRealmsAsync()
4950
{
50-
try
51+
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)))
5152
{
52-
var response = await _httpClient.GetAsync("access/domains").ConfigureAwait(false);
53-
Console.WriteLine(response);
54-
response.EnsureSuccessStatusCode();
53+
try
54+
{
55+
var response = await _httpClient.GetAsync("access/domains", cts.Token).ConfigureAwait(false);
56+
response.EnsureSuccessStatusCode();
5557

56-
var jsonData = JsonConvert.DeserializeObject<Dictionary<string, List<RealmData>>>(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
57-
return jsonData?["data"] ?? new List<RealmData>();
58-
}
59-
catch (Exception ex)
60-
{
61-
// Log or handle the exception as needed
62-
return new List<RealmData>();
58+
var jsonData = JsonConvert.DeserializeObject<Dictionary<string, List<RealmData>>>(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
59+
return jsonData?["data"] ?? new List<RealmData>();
60+
}
61+
catch (TaskCanceledException)
62+
{
63+
MessageBox.Show("Could not reach the Proxmox API.\n\rPlease check your settings and try again.", "Server Error");
64+
return new List<RealmData>();
65+
}
66+
catch (Exception)
67+
{
68+
MessageBox.Show("The server information provided doesn't lead to the Proxmox API.\n\rPlease check your settings and try again.", "Server Error");
69+
return new List<RealmData>();
70+
}
6371
}
6472
}
6573

74+
6675
public async Task<bool> LoginAsync(string username, string password, string realm, string otp = null)
6776
{
6877

Panels/ClientLogin.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Windows.Forms;
34
using Proxmox_Desktop_Client.Classes;
45
using Proxmox_Desktop_Client.Classes.pveAPI;
@@ -33,35 +34,44 @@ private async void ClickCheckServer(object sender = null, EventArgs e = null)
3334
string port = textBox_port.Text;
3435
bool validateSsl = checkBox_ssl.Checked;
3536

36-
Console.WriteLine("Checking Server");
37+
this.panel_credentials.Enabled = false;
38+
this.panel_server.Enabled = false;
39+
this.Width = 290;
40+
CenterToScreen();
3741

42+
Program.DebugPoint($"Connecting to server: {server}:{port}, SSL:{validateSsl}");
3843
_api = new ApiClient(server, port, validateSsl);
39-
Console.WriteLine("Connected Server");
4044

45+
Program.DebugPoint($"Collecting Realm Data...");
4146
var realms = await _api.GetRealmsAsync();
42-
Console.WriteLine("Realms");
4347

48+
Program.DebugPoint($"Validating Realm Data...");
4449
if (realms != null && realms.Count > 0)
4550
{
4651
comboBox_realm.DataSource = realms;
4752
comboBox_realm.DisplayMember = "Comment";
4853
comboBox_realm.ValueMember = "Realm";
49-
54+
5055
string savedRealm = (string)Program._Config.GetSetting("Login_Realm");
5156
if (!string.IsNullOrEmpty(savedRealm))
5257
{
5358
comboBox_realm.SelectedValue = savedRealm;
5459
}
55-
60+
61+
Program.DebugPoint($"Has Realm Data...");
5662
panel_credentials.Visible = true;
5763
Width = 570;
58-
CenterToScreen();
5964
}
6065
else
61-
{
66+
{
67+
Program.DebugPoint($"No Realm Data/Connection Error...");
6268
comboBox_realm.DataSource = null;
6369
Width = 290;
6470
}
71+
72+
CenterToScreen();
73+
this.panel_credentials.Enabled = true;
74+
this.panel_server.Enabled = true;
6575
}
6676

6777
private async void ValidateLogin(object sender, EventArgs e)

Panels/MainPanel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ private void xTermJS_Client(MachineData machineData)
153153
new NoVNCClient(_api, machineData);
154154
}
155155

156-
private void Spice_Client(int vmid)
156+
private async void Spice_Client(int vmid)
157157
{
158158
var spiceClient = new SpiceClient(_api, _api.Machines.FirstOrDefault(m => m.Vmid == vmid));
159-
spiceClient.RequestSpiceConnection();
159+
await spiceClient.RequestSpiceConnection();
160160
}
161161

162162
private async Task<bool> CheckSpiceAble(MachineData Machine)

Program.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,15 @@ static void Main()
2828
Application.Run(new ClientLogin());
2929
}
3030

31+
public static void DebugPoint(string content)
32+
{
33+
bool debugMode = false;
34+
#if DEBUG
35+
debugMode = true;
36+
#endif
37+
38+
Console.WriteLine(content);
39+
}
40+
3141
}
3242
}

Proxmox Desktop Client.csproj

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
</PropertyGroup>
2828
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2929
<PlatformTarget>AnyCPU</PlatformTarget>
30-
<DebugType>pdbonly</DebugType>
30+
<DebugType>none</DebugType>
3131
<Optimize>true</Optimize>
3232
<OutputPath>bin\Release\</OutputPath>
3333
<DefineConstants>TRACE</DefineConstants>
3434
<ErrorReport>prompt</ErrorReport>
35-
<WarningLevel>4</WarningLevel>
35+
<WarningLevel>3</WarningLevel>
3636
</PropertyGroup>
3737
<ItemGroup>
3838
<Reference Include="FubarCoder.RestSharp.Portable.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=be81bb0f53eab22f, processorArchitecture=MSIL">
@@ -139,7 +139,6 @@
139139
<Compile Include="Classes\pveAPI\objects\dataServerUser.cs" />
140140
<Compile Include="Classes\pveAPI\UserPermissions.cs" />
141141
<Compile Include="Classes\Ticker.cs" />
142-
<Compile Include="obj\Debug\.NETFramework,Version=v4.8.1.AssemblyAttributes.cs" />
143142
<Compile Include="Panels\ClientLogin.cs">
144143
<SubType>Form</SubType>
145144
</Compile>
@@ -193,16 +192,6 @@
193192
<None Include="App.config" />
194193
</ItemGroup>
195194
<ItemGroup>
196-
<Content Include="obj\Debug\Proxmox .1D3D995B.Up2Date" />
197-
<Content Include="obj\Debug\Proxmox Desktop Client.csproj.AssemblyReference.cache" />
198-
<Content Include="obj\Debug\Proxmox Desktop Client.csproj.CoreCompileInputs.cache" />
199-
<Content Include="obj\Debug\Proxmox Desktop Client.csproj.FileListAbsolute.txt" />
200-
<Content Include="obj\Debug\Proxmox Desktop Client.csproj.GenerateResource.cache" />
201-
<Content Include="obj\Debug\Proxmox_Desktop_Client.ClientLogin.resources" />
202-
<Content Include="obj\Debug\Proxmox_Desktop_Client.exe" />
203-
<Content Include="obj\Debug\Proxmox_Desktop_Client.MainPanel.resources" />
204-
<Content Include="obj\Debug\Proxmox_Desktop_Client.pdb" />
205-
<Content Include="obj\Debug\Proxmox_Desktop_Client.Properties.Resources.resources" />
206195
<Content Include="Resources\Icons\default-icon.ico" />
207196
<Content Include="Resources\Icons\default.png" />
208197
<Content Include="Resources\icons_dots.png" />
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeEditing/Localization/Localizable/@EntryValue">No</s:String></wpf:ResourceDictionary>

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ A Windows Desktop Client for Proxmox VE.
44
It's purpose is as designed. A way to remote virtual machines in my homelab without having to log in to Proxmox WebGUI.
55
The intent mostly was for the use of SPICE (virt-viewer) connectivity as some of my remote needs I can't use RDP but console view.
66
## Requirements for SPICE
7-
- Virt-viewer && UsbDk (https://www.spice-space.org/download.html).
7+
- Virt-viewer && UsbDk (https://www.spice-space.org/download.html).
8+
- .Net 4.8.1 or Newer
89
## Functionality
910
- Plain & TOTP Login
1011
- Remote (NoVNC/SPICE/xtermJS)

0 commit comments

Comments
 (0)