Skip to content

Commit

Permalink
feat: v1.3.11 extension add
Browse files Browse the repository at this point in the history
  • Loading branch information
minkostaev committed Jan 7, 2025
1 parent cbe03c6 commit 2089f18
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 72 deletions.
4 changes: 2 additions & 2 deletions ShortcutsGrid.Tests/ShortcutsGrid.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<PackageReference Include="JustMock" Version="2024.4.1203.350" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NUnit" Version="4.3.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
61 changes: 61 additions & 0 deletions ShortcutsGrid/Extensions/WindowRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace ShortcutsGrid.Extensions;

using Forms.Wpf.Mls.Tools.Models;
using Forms.Wpf.Mls.Tools.Models.TheMachine;
using Forms.Wpf.Mls.Tools.Services;
using ShortcutsGrid.Models;
using System;
using System.ComponentModel;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Threading;

public static class WindowRequest
{

public static void AttachRequest(this MainWindow window)
{
var closeTime = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 250) };
closeTime.Tick += delegate { window.Exit(); };

RequestResponse? response = null;
var worker = new BackgroundWorker();
worker.DoWork += async delegate
{
response = await SendToApi(true);
};

bool started = false;
window.Closing += (sender, e) =>
{
if (!started)
{
worker.RunWorkerAsync();
started = true;
closeTime.Start();
e.Cancel = true;
}
if (response == null)
{
e.Cancel = true;
}
};
}

public static async Task<RequestResponse?> SendToApi(bool exitRequest = false)
{
if (AppValues.LastExecuted == null)
return null;
var machine = new TheMachine();
var headers = new System.Collections.Generic.Dictionary<string, string?>
{
{ exitRequest ? "null" : "Desktop-Machine", machine.Hash },
{ "Desktop-Value", AppValues.LastExecuted },
{ "Desktop-Version", $"ShortcutsGrid|{AppValues.AppVersion}" }
};
var requestManager = new RequestManager(headers!);
string jsonString = JsonSerializer.Serialize(machine);
return await requestManager.SendRequest(AppValues.RequestPath, RequestMethod.POST, jsonString);
}

}
5 changes: 3 additions & 2 deletions ShortcutsGrid/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Models;
using Services;
using ShortcutsGrid.Extensions;
using System.Windows;
using System.Windows.Input;

Expand All @@ -15,9 +16,9 @@ public MainWindow()
///var startTimer = Stopwatch.StartNew();
///var endTimer = Stopwatch.StartNew();
InitializeComponent();

ShowShortcuts.WaitForResponseOnClose(this);

this.AttachRequest();

ContentRendered += delegate
{
///startTimer.Stop();
Expand Down
2 changes: 1 addition & 1 deletion ShortcutsGrid/Resources/ListCsv/Browsers.csv

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ShortcutsGrid/Resources/ListCsv/Utils.csv

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions ShortcutsGrid/Services/Run/RunProcess.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace ShortcutsGrid.Services.Run;

using ShortcutsGrid.Extensions;
using ShortcutsGrid.Models;
using System;
using System.Diagnostics;
Expand All @@ -8,6 +9,15 @@
public static class RunProcess
{

public static void OpenLink(string uri)
{
Process.Start(new ProcessStartInfo
{
FileName = uri,
UseShellExecute = true
});
}

public static string Run(string commandOrPath, bool admin = false)
{
if (string.IsNullOrWhiteSpace(commandOrPath))
Expand Down Expand Up @@ -67,16 +77,7 @@ private static void ProcessStart(string commandOrPath, bool admin, string args =
process.StartInfo.UseShellExecute = true;
process.Start();
AppValues.LastExecuted = commandOrPath;
_ = ShowShortcuts.SendToApi();
}

public static void OpenLink(string uri)
{
Process.Start(new ProcessStartInfo
{
FileName = uri,
UseShellExecute = true
});
_ = WindowRequest.SendToApi();
}

}
54 changes: 1 addition & 53 deletions ShortcutsGrid/Services/ShowShortcuts.cs
Original file line number Diff line number Diff line change
@@ -1,63 +1,11 @@
namespace ShortcutsGrid.Services;

using Forms.Wpf.Mls.Tools.Models;
using Forms.Wpf.Mls.Tools.Models.TheMachine;
using Forms.Wpf.Mls.Tools.Services;
using ShortcutsGrid.Models;
using ShortcutsGrid.Windows;
using System;
using System.ComponentModel;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Threading;

public static class ShowShortcuts
{
public static void WaitForResponseOnClose(MainWindow window)
{
var closeTime = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 250) };
closeTime.Tick += delegate { window.Exit(); };

RequestResponse? response = null;
var worker = new BackgroundWorker();
worker.DoWork += async delegate
{
response = await SendToApi(true);
};

bool started = false;
window.Closing += (sender, e) =>
{
if (!started)
{
worker.RunWorkerAsync();
started = true;
closeTime.Start();
e.Cancel = true;
}
if (response == null)
{
e.Cancel = true;
}
};
}

public static async Task<RequestResponse?> SendToApi(bool exitRequest = false)
{
if (AppValues.LastExecuted == null)
return null;
var machine = new TheMachine();
var headers = new System.Collections.Generic.Dictionary<string, string?>
{
{ exitRequest ? "null" : "Desktop-Machine", machine.Hash },
{ "Desktop-Value", AppValues.LastExecuted },
{ "Desktop-Version", $"ShortcutsGrid|{AppValues.AppVersion}" }
};
var requestManager = new RequestManager(headers!);
string jsonString = JsonSerializer.Serialize(machine);
return await requestManager.SendRequest(AppValues.RequestPath, RequestMethod.POST, jsonString);
}


public static void Load(MainWindow window)
{
window.stkPnl1.Children.Clear();
Expand Down
6 changes: 3 additions & 3 deletions ShortcutsGrid/ShortcutsGrid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<UseWPF>true</UseWPF>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<ApplicationIcon>Resources\web-browser-128.ico</ApplicationIcon>
<AssemblyVersion>1.3.10.0</AssemblyVersion>
<FileVersion>1.3.10.0</FileVersion>
<VersionPrefix>1.3.10</VersionPrefix>
<AssemblyVersion>1.3.11.0</AssemblyVersion>
<FileVersion>1.3.11.0</FileVersion>
<VersionPrefix>1.3.11</VersionPrefix>
<VersionSuffix>$([System.DateTime]::UtcNow.ToString(yyyy-MM-dd))</VersionSuffix>
</PropertyGroup>

Expand Down

0 comments on commit 2089f18

Please sign in to comment.