Skip to content

Commit

Permalink
WinGet prep
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingpie committed Feb 11, 2024
1 parent 319cbe8 commit e2e5536
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 216 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
indent_style=tab
indent_size=4

dotnet_diagnostic.CS1591.severity = none # CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.S1135.severity = none # S1135: Track uses of "TODO" tags
dotnet_diagnostic.SA1600.severity = none # SA1600: Elements should be documented
dotnet_diagnostic.SA1633.severity = none # SA1633: File should have header
2 changes: 1 addition & 1 deletion .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
- name: 'Run: PublishAll'
run: ./build.cmd PublishAll
run: ./src/build.cmd PublishAll
- name: 'Publish: win-x64_framework-dependent.zip'
uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion src/01-Build/NukeBuild/NukeBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006</NoWarn>
<NukeRootDirectory>..\..\..</NukeRootDirectory>
<NukeScriptDirectory>..\..\..</NukeScriptDirectory>
<NukeScriptDirectory>..\..</NukeScriptDirectory>
<NukeTelemetryVersion>1</NukeTelemetryVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
38 changes: 38 additions & 0 deletions src/10-Core/Wtq.Core/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.IO;
using Wtq.Core.Exceptions;

namespace Wtq.Core;

public static class App
{
private static string? _pathToAppDir;

public static string PathToAppDir
{
get
{
if (_pathToAppDir == null)
{
_pathToAppDir = Path.GetDirectoryName(PathToAppExe);
}

return _pathToAppDir;
}
}

private static string? _pathToAppExe;

public static string PathToAppExe
{
get
{
if (_pathToAppExe == null)
{
_pathToAppExe = Environment.ProcessPath
?? throw new WtqException("Could not find path to wtq exe.");
}

return _pathToAppExe;
}
}
}
62 changes: 0 additions & 62 deletions src/10-Core/Wtq.Core/Program.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/10-Core/Wtq.Core/Utils/Log.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Extensions.Configuration;
using Serilog;
using Serilog.Extensions.Logging;
using System.IO;
using Wtq.Core;

namespace Wtq.Utils;

Expand All @@ -16,7 +18,7 @@ public static void Configure(IConfiguration configuration)
.WriteTo.Console()

.WriteTo.File(
path: "logs/.txt",
path: Path.Combine(App.PathToAppDir, "logs", ".txt"),
fileSizeLimitBytes: 10_000_000,
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 3)
Expand Down
6 changes: 0 additions & 6 deletions src/10-Core/Wtq.Core/Wtq.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
<PackageReference Include="System.Resources.Extensions" />
</ItemGroup>

<ItemGroup>
<None Update="*.jsonc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\icon.ico" />
</ItemGroup>
Expand Down
120 changes: 2 additions & 118 deletions src/10-Core/Wtq.Core/WtqService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using System.Threading;
using Wtq.Configuration;
using Wtq.Core.Data;
using Wtq.Core.Events;

//using Wtq.Core.Service;
using Wtq.Core.Services;
using Wtq.Services;

Expand All @@ -15,31 +12,21 @@ public sealed class WtqService(
ILogger<WtqService> log,
IOptions<WtqOptions> opts,
WtqAppMonitorService appMon,
//IWtqHotkeyService hkService,
IWtqAppToggleService toggler,
IWtqAppRepo appRepo,
IWtqBus bus)
: IHostedService
{
private readonly ILogger<WtqService> _log = log ?? throw new ArgumentNullException(nameof(log));
private readonly IOptions<WtqOptions> _opts = opts ?? throw new ArgumentNullException(nameof(opts));
//private readonly IWtqHotkeyService _hkService = hkService ?? throw new ArgumentNullException(nameof(hkService));

private readonly WtqAppMonitorService _appMon = appMon ?? throw new ArgumentNullException(nameof(appMon));
private readonly IWtqAppToggleService _toggler = toggler ?? throw new ArgumentNullException(nameof(toggler));
private readonly IWtqAppRepo _appRepo = appRepo ?? throw new ArgumentNullException(nameof(appRepo));
private readonly IWtqBus _bus = bus ?? throw new ArgumentNullException(nameof(bus));

//private Plexiglass _gl;

public Task StartAsync(CancellationToken cancellationToken)
{
_log.LogInformation("Starting");

//_gl = new Plexiglass();

//HotkeyManager.HotKeyPressed += async (s, args) => await ToggleStuffAsync(args);
//_hkService.OnHotkey(ToggleStuffAsync);
_bus.OnAsync(e => e is WtqToggleAppEvent, ToggleStuffAsync);

_bus.OnAsync(
Expand All @@ -48,31 +35,13 @@ public Task StartAsync(CancellationToken cancellationToken)
{
var ev = (WtqAppFocusEvent)e;

if(ev.App != null && ev.App == open && !ev.GainedFocus)
if (ev.App != null && ev.App == open && !ev.GainedFocus)
{
await open.CloseAsync();
open = null;
}

});

// Global hotkeys.
foreach (var hk in _opts.Value.Hotkeys)
{
_log.LogInformation("Registering global hotkey '{Hotkey}'", hk);
//HotkeyManager.RegisterHotKey(hk.Key, hk.Modifiers);
}

// Per-app hotkeys.
foreach (var app in _opts.Value.Apps)
{
foreach (var hk in app.Hotkeys)
{
_log.LogInformation("Registering hotkey '{Hotkey}' for app '{App}'", hk, app);
//HotkeyManager.RegisterHotKey(hk.Key, hk.Modifiers);
}
}

return Task.CompletedTask;
}

Expand All @@ -81,24 +50,13 @@ public Task StartAsync(CancellationToken cancellationToken)

private async Task ToggleStuffAsync(IWtqEvent ev)
{
const int openTimeMs = 100;
const int switchTimeMs = 50;

//_log.LogInformation("Pressed hot key ['{Modifiers}'] + '{HotKey}'", args.Modifiers, args.Key);

//var app = _opts.Value.Apps.FirstOrDefault(a => a.HasHotkey(args.Key, args.Modifiers));
//var app = _opts.Value.Apps.FirstOrDefault(a => a.);

var wasOpen = open != null;

var app = ev.App;

// If the action does not point to a single app, toggle the most recent one.
if (app == null)
{
if (open != null)
{
//await _toggler.ToggleAsync(open.Process, false, openTimeMs);
await open.CloseAsync();
_lastOpen = open;
open = null;
Expand All @@ -121,23 +79,13 @@ private async Task ToggleStuffAsync(IWtqEvent ev)
}

open = _lastOpen;
//await _toggler.ToggleAsync(open.Process, true, openTimeMs);
await open.OpenAsync();
return;
}

//_log.LogWarning("No app found with assigned hotkeys ['{Modifiers}'] + '{HotKey}'", args.Modifiers, args.Key);
return;
}

//var process = _appMon.GetProcessForApp(ev.App);

//if (!ev.App.IsActive)
//{
// _log.LogWarning("No process found for app '{App}'", ev.App);
// return;
//}

// We can't toggle apps that are not active.
if (!app.IsActive)
{
Expand All @@ -150,15 +98,12 @@ private async Task ToggleStuffAsync(IWtqEvent ev)
if (open == app)
{
await app.CloseAsync();
//await _toggler.ToggleAsync(open.Process, false, openTimeMs);
_lastOpen = open;
open = null;
_appMon.DropFocus();
}
else
{
//await _toggler.ToggleAsync(open.Process, false, switchTimeMs);
//await _toggler.ToggleAsync(process.Process, true, switchTimeMs);
await open.CloseAsync(ToggleModifiers.SwitchingApps);
await app.OpenAsync(ToggleModifiers.SwitchingApps);

Expand All @@ -180,65 +125,4 @@ public Task StopAsync(CancellationToken cancellationToken)

return Task.CompletedTask;
}
}

//internal class Plexiglass : Form
//{
// public Plexiglass()
// {
// this.BackColor = Color.DarkGray;
// this.Opacity = 0.30; // Tweak as desired
// this.FormBorderStyle = FormBorderStyle.None;
// this.ControlBox = false;
// this.ShowInTaskbar = false;
// this.StartPosition = FormStartPosition.Manual;
// this.AutoScaleMode = AutoScaleMode.None;
// //this.Location = tocover.PointToScreen(Point.Empty);
// //this.ClientSize = tocover.ClientSize;
// this.Location = new Point(100, 800);
// this.Size = new Size(3000, 200);
// //tocover.LocationChanged += Cover_LocationChanged;
// //tocover.ClientSizeChanged += Cover_ClientSizeChanged;
// this.Show();
// // tocover.Focus();
// // Disable Aero transitions, the plexiglass gets too visible
// if (Environment.OSVersion.Version.Major >= 6)
// {
// int value = 1;
// // DwmSetWindowAttribute(tocover.Handle, DWMWA_TRANSITIONS_FORCEDISABLED, ref value, 4);
// }
// }

// //private void Cover_LocationChanged(object sender, EventArgs e)
// //{
// // // Ensure the plexiglass follows the owner
// // this.Location = this.Owner.PointToScreen(Point.Empty);
// //}
// //private void Cover_ClientSizeChanged(object sender, EventArgs e)
// //{
// // // Ensure the plexiglass keeps the owner covered
// // this.ClientSize = this.Owner.ClientSize;
// //}
// //protected override void OnFormClosing(FormClosingEventArgs e)
// //{
// // // Restore owner
// // this.Owner.LocationChanged -= Cover_LocationChanged;
// // this.Owner.ClientSizeChanged -= Cover_ClientSizeChanged;
// // if (!this.Owner.IsDisposed && Environment.OSVersion.Version.Major >= 6)
// // {
// // int value = 1;
// // DwmSetWindowAttribute(this.Owner.Handle, DWMWA_TRANSITIONS_FORCEDISABLED, ref value, 4);
// // }
// // base.OnFormClosing(e);
// //}
// protected override void OnActivated(EventArgs e)
// {
// // Always keep the owner activated instead
// this.BeginInvoke(new Action(() => this.Owner.Activate()));
// }

// private const int DWMWA_TRANSITIONS_FORCEDISABLED = 3;

// [DllImport("dwmapi.dll")]
// private static extern int DwmSetWindowAttribute(IntPtr hWnd, int attr, ref int value, int attrLen);
//}
}
Loading

0 comments on commit e2e5536

Please sign in to comment.