Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

# build and test the code
- run: dotnet build
- run: dotnet test
# - run: dotnet test

# publish and archive the different executables
- name: Build executables
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:

# build and test the code
- run: dotnet build
- run: dotnet test
# - run: dotnet test
36 changes: 36 additions & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Website

on:
push:
branches: [master]
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/configure-pages@v3
- uses: actions/upload-pages-artifact@v3
with:
path: Website/

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion BuildScripts/BuildAll.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. .\BuildScripts\Utilities.ps1

$configuration = "Release"
$dotnetVersion = "net8.0-windows"
$dotnetVersion = Get-DotnetVersion

# create a releases folder
if (-not(Test-Path "Releases")) { New-Item -ItemType "directory" -Path "Releases" -Force }
Expand Down
7 changes: 7 additions & 0 deletions BuildScripts/Utilities.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ function Get-ProjectVersion () {
$_.Node.InnerXML
}
}

function Get-DotnetVersion () {
Select-Xml -Path SuperSize/SuperSize.csproj -XPath "/Project/PropertyGroup/TargetFramework" |
ForEach-Object {
$_.Node.InnerText
}
}
17 changes: 0 additions & 17 deletions SuperSize.Test/SuperSize.Test.csproj

This file was deleted.

22 changes: 0 additions & 22 deletions SuperSize.Test/UnitTest1.cs

This file was deleted.

34 changes: 0 additions & 34 deletions SuperSize.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,28 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SuperSize.Test", "SuperSize.Test\SuperSize.Test.csproj", "{0756A4D4-A83E-4062-8527-70092B7284E3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM = Release|ARM
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Debug|ARM.ActiveCfg = Debug|Any CPU
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Debug|ARM.Build.0 = Debug|Any CPU
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Debug|ARM64.ActiveCfg = Debug|ARM64
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Debug|ARM64.Build.0 = Debug|ARM64
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Debug|x64.ActiveCfg = Debug|x64
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Debug|x64.Build.0 = Debug|x64
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Debug|x86.ActiveCfg = Debug|Any CPU
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Debug|x86.Build.0 = Debug|Any CPU
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Release|Any CPU.Build.0 = Release|Any CPU
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Release|ARM.ActiveCfg = Release|Any CPU
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Release|ARM.Build.0 = Release|Any CPU
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Release|ARM64.ActiveCfg = Release|ARM64
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Release|ARM64.Build.0 = Release|ARM64
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Release|x64.ActiveCfg = Release|x64
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Release|x64.Build.0 = Release|x64
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Release|x86.ActiveCfg = Release|Any CPU
{57EB3C49-9ADC-4F67-A355-9C067ADC4CBF}.Release|x86.Build.0 = Release|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Debug|ARM.ActiveCfg = Debug|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Debug|ARM.Build.0 = Debug|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Debug|ARM64.ActiveCfg = Debug|ARM64
{0756A4D4-A83E-4062-8527-70092B7284E3}.Debug|ARM64.Build.0 = Debug|ARM64
{0756A4D4-A83E-4062-8527-70092B7284E3}.Debug|x64.ActiveCfg = Debug|x64
{0756A4D4-A83E-4062-8527-70092B7284E3}.Debug|x64.Build.0 = Debug|x64
{0756A4D4-A83E-4062-8527-70092B7284E3}.Debug|x86.ActiveCfg = Debug|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Debug|x86.Build.0 = Debug|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Release|Any CPU.Build.0 = Release|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Release|ARM.ActiveCfg = Release|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Release|ARM.Build.0 = Release|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Release|ARM64.ActiveCfg = Release|ARM64
{0756A4D4-A83E-4062-8527-70092B7284E3}.Release|ARM64.Build.0 = Release|ARM64
{0756A4D4-A83E-4062-8527-70092B7284E3}.Release|x64.ActiveCfg = Release|x64
{0756A4D4-A83E-4062-8527-70092B7284E3}.Release|x64.Build.0 = Release|x64
{0756A4D4-A83E-4062-8527-70092B7284E3}.Release|x86.ActiveCfg = Release|Any CPU
{0756A4D4-A83E-4062-8527-70092B7284E3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
13 changes: 6 additions & 7 deletions SuperSize/CoreLogic/ExpandFromCentre.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
{
public override string DisplayName { get; } = "Expand from centre";

public override Task<Rectangle> CalculateWindowSize(Settings config)
public override Task<LogicResult> CalculateWindowSize(Settings config)
{
var primary = Screen.PrimaryScreen.Bounds;

Check warning on line 17 in SuperSize/CoreLogic/ExpandFromCentre.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 17 in SuperSize/CoreLogic/ExpandFromCentre.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 17 in SuperSize/CoreLogic/ExpandFromCentre.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 17 in SuperSize/CoreLogic/ExpandFromCentre.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
var centre = new Point(primary.Left + primary.Width / 2, primary.Height/ 2);
var centre = new Point(primary.Left + primary.Width / 2, primary.Height / 2);

var allBounds = OS.Utilities.GetAllScreenBounds();
var targetTop = Math.Abs(centre.Y - allBounds.Top);
Expand All @@ -26,13 +26,12 @@
var targetWidth = Math.Min(targetLeft, targetRight);
var targetHeight = Math.Min(targetTop, targetBottom);

return Task.FromResult(
return Task.FromResult(LogicResult.OK(
Rectangle.FromLTRB(
centre.X - targetWidth,
centre.Y - targetHeight,
2 * targetWidth,
centre.Y - targetHeight,
2 * targetWidth,
2 * targetHeight
)
);
)));
}
}
65 changes: 18 additions & 47 deletions SuperSize/CoreLogic/PythonScript.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using SuperSize.Model;
using SuperSize.Model;
using SuperSize.Scripting.Python;
using SuperSize.UI.Dialogs;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand All @@ -17,53 +14,27 @@ internal sealed class PythonScript : Logic
{
public override string DisplayName => "Scripting: Python";

private ScriptRuntime _scriptRuntime;
private ScriptScope _scriptScope;
private ScriptEngine _scriptEngine;

public PythonScript()
{
_scriptRuntime = Python.CreateRuntime();
_scriptScope = _scriptRuntime.CreateScope();
_scriptEngine = _scriptRuntime.GetEngine("Python");
PythonSetup();
}

public override Task<Rectangle> CalculateWindowSize(Settings settings)
{
return Task.FromResult(new Rectangle(0, 0, 0, 0));
}

public override void ShowSettings(Settings settings)
{
new ScriptEditorDialog().ShowDialog();
}

private void PythonSetup()
{
_scriptRuntime.LoadAssembly(Assembly.GetExecutingAssembly());
_scriptRuntime.LoadAssembly(Assembly.Load("System.Drawing"));
_scriptRuntime.LoadAssembly(Assembly.Load("System.Windows.Forms"));

PopulatePythonScope(new()
public override Task<LogicResult> CalculateWindowSize(Settings settings) => Task.Run(() =>
{
{ "alert", new Action<object>(message => MessageBox.Show(message.ToString())) },
if (!settings.TryGetValue("Script", out var script))
{
return LogicResult.NoResult("No script loaded");
}

// screen detail
{ "get_screens", new Func<Screen[]>(() => Screen.AllScreens) },
{ "get_all_screen_bounds", new Func<Rectangle>(() => OS.Utilities.GetAllScreenBounds()) },
var context = new PythonContext();
context.Execute(script!);

// python shorthands .NET object constructors
{ "rectangle", new Func<int, int, int, int, Rectangle>((x, y, w, h) => new Rectangle(x, y, w, h)) },
{ "point", new Func<int, int, Point>((x, y) => new Point(x, y)) },
if (context.Result is Rectangle result)
{
return LogicResult.OK(result);
}

return LogicResult.NoResult("Script didn't yield");
});
}

private void PopulatePythonScope(Dictionary<string, object?> values)
public override void ShowSettings(Settings settings)
{
foreach (var (key, value) in values)
{
_scriptScope.SetVariable(key, value);
}
using var dialog = new PythonScriptEditor(settings);
dialog.ShowDialog();
}
}
4 changes: 2 additions & 2 deletions SuperSize/CoreLogic/UseAllScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class UseAllScreen : Logic
{
public override string DisplayName { get; } = "Use all the screen real estate";

public override Task<Rectangle> CalculateWindowSize(Settings config)
public override Task<LogicResult> CalculateWindowSize(Settings config)
{
var left = int.MaxValue;
var top = int.MaxValue;
Expand All @@ -26,6 +26,6 @@ public override Task<Rectangle> CalculateWindowSize(Settings config)
right = Math.Max(right, bounds.Right);
bottom = Math.Max(bottom, bounds.Bottom);
}
return Task.FromResult(Rectangle.FromLTRB(left, top, right, bottom));
return Task.FromResult(LogicResult.OK(Rectangle.FromLTRB(left, top, right, bottom)));
}
}
18 changes: 17 additions & 1 deletion SuperSize/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using SuperSize.Model;
using SuperSize.Service;
using System;
using System.Diagnostics;
using System.Drawing;

namespace SuperSize
Expand Down Expand Up @@ -27,7 +29,21 @@ public static Rectangle Calculate(this Logic logic)
return Rectangle.Empty;
}

return logic.CalculateWindowSize(SettingsService.GetSettings(logic)).Result;
var settings = SettingsService.GetSettings(logic);
var result = logic.CalculateWindowSize(settings).Result;

if (result.TryGetRectangle(out var rectangle))
{
return rectangle;
}

if (result.HasException)
{
throw new Exception("Logic returned an exception", result.Exception!);
}

Debug.Print($"Logic returned no result: {result.NoResultMessage}");
return Rectangle.Empty;
}
}
}
2 changes: 1 addition & 1 deletion SuperSize/Model/Logic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class Logic

public virtual Dictionary<string, string> InitialSettings { get; } = new();

public abstract Task<Rectangle> CalculateWindowSize(Settings settings);
public abstract Task<LogicResult> CalculateWindowSize(Settings settings);

public virtual void ShowSettings(Settings settings) => throw new NotImplementedException();

Expand Down
45 changes: 45 additions & 0 deletions SuperSize/Model/LogicResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Drawing;

namespace SuperSize.Model
{
public class LogicResult
{
public Rectangle Rectangle { get; private init; }

public string NoResultMessage { get; private init; }

public Exception? Exception { get; private init; }

private LogicResult()
{
Rectangle = Rectangle.Empty;
NoResultMessage = string.Empty;
}

public static LogicResult OK(Rectangle rectangle) => new()
{
Rectangle = rectangle,
};

public static LogicResult NoResult(string message) => new()
{
NoResultMessage = message,
};

public static LogicResult Error(Exception exception) => new()
{
Exception = exception,
};

public bool HasResult => !Rectangle.IsEmpty;

public bool HasException => Exception is not null;

public bool TryGetRectangle(out Rectangle rectangle)
{
rectangle = Rectangle;
return rectangle != Rectangle.Empty;
}
}
}
Loading
Loading