Skip to content

Commit d455296

Browse files
committed
feat: add chocolatey support
1 parent a89683b commit d455296

File tree

8 files changed

+246
-2
lines changed

8 files changed

+246
-2
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,7 @@ jobs:
7878
Or download the Source Code and Build it on your own.
7979
files: ./MouseTrap-${{ steps.version.outputs.version }}.zip
8080

81+
- name: Push to Chocolatey
82+
env:
83+
CHOCO_TOKEN: ${{ secrets.CHOCO_TOKEN }}
84+
run: pwsh .\MouseTrap\choco\Push.ps1 -nuspec .\MouseTrap\choco\MouseTrap.nuspec -zip ./MouseTrap-${{ steps.version.outputs.version }}.zip -version ${{ steps.version.outputs.version_tag }}

MouseTrap.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
99
ProjectSection(SolutionItems) = preProject
1010
.editorconfig = .editorconfig
1111
.github\workflows\build.yml = .github\workflows\build.yml
12+
LICENSE.txt = LICENSE.txt
1213
README.md = README.md
14+
VERIFICATION.txt = VERIFICATION.txt
1315
EndProjectSection
1416
EndProject
1517
Global

MouseTrap/choco/MouseTrap.nuspec

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package>
3+
<metadata>
4+
<id>MouseTrap</id>
5+
<version>0.0.0</version>
6+
<title>MouseTrap DPI aware mouse move across screens</title>
7+
<tags>multiscreen mouse-pointer screen-scale dpi-awareness dpi-scaling cursor-moves cursor-position</tags>
8+
<summary>A small tool to map the cursor between monitors with different DPIs</summary>
9+
<description>
10+
# MouseTrap
11+
12+
MouseTrap is a small tool to map the cursor between multiple monitors with
13+
different resolutions and scaling settings.
14+
15+
## Min requirements
16+
17+
For this tool to function correctly you should have:
18+
19+
- At least **Windows 10 Creators update** (Build 1703)
20+
- [**.NET 8 Runtime**](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) (in most cases it will notify you if the runtime is missing)
21+
22+
## Usage and Configuration
23+
24+
Here you can find the [documentation](https://github.com/r-Larch/MouseTrap/blob/master/README.md).
25+
</description>
26+
<authors>René Larch</authors>
27+
<owners>René Larch</owners>
28+
<copyright>Copyright 2023 René Larch</copyright>
29+
<licenseUrl>https://github.com/r-Larch/MouseTrap/blob/master/LICENSE.txt</licenseUrl>
30+
<projectUrl>https://github.com/r-Larch/MouseTrap</projectUrl>
31+
<projectSourceUrl>https://github.com/r-Larch/MouseTrap</projectSourceUrl>
32+
<bugTrackerUrl>https://github.com/r-Larch/MouseTrap/issues</bugTrackerUrl>
33+
<docsUrl>https://github.com/r-Larch/MouseTrap/blob/master/README.md</docsUrl>
34+
<iconUrl>https://raw.githubusercontent.com/r-Larch/MouseTrap/master/MouseTrap/AppIcon.png</iconUrl>
35+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
36+
<releaseNotes>...</releaseNotes>
37+
</metadata>
38+
<files>
39+
<file src="..\..\LICENSE.txt" />
40+
<file src="..\..\VERIFICATION.txt" />
41+
<file src="*.ps1" target="tools" />
42+
</files>
43+
</package>

MouseTrap/choco/Push.ps1

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
2+
param (
3+
[string] $nuspec,
4+
[string] $zip,
5+
[string] $version,
6+
[switch] $debug = $false
7+
)
8+
9+
10+
function Main() {
11+
$dir = Split-Path -parent $nuspec;
12+
13+
$choco = @{
14+
version = $version
15+
nuspec = $nuspec
16+
dir = $dir
17+
installScript = [System.IO.Path]::Combine($dir, "chocolateyinstall.ps1")
18+
uninstallScript = [System.IO.Path]::Combine($dir, "chocolateyuninstall.ps1")
19+
}
20+
21+
$hash = (Get-FileHash -Algorithm SHA256 -Path $zip).Hash.ToUpper()
22+
ChocoUpdateScript $choco $version $hash
23+
24+
Push-Location $dir
25+
$previousTag = [Git]::GetVersionTags() | where { $_ -ne "v$version" } | sort -Descending | select -first 2 | select -last 1;
26+
$history = [Git]::GetHistorySince($previousTag);
27+
Pop-Location
28+
29+
ChocoUpdateNuspec $choco $history "https://api.github.com/repos/r-Larch/MouseTrap"
30+
31+
ChocoPublish $choco $debug
32+
33+
}
34+
35+
36+
function ChocoUpdateScript([object] $choco, [string] $version, [string] $hash) {
37+
$script = Get-Content $choco.installScript -Encoding UTF8 -Raw
38+
$script = $script.replace('<version>', $version)
39+
$script = $script.replace('<hash>', $hash)
40+
$script | Set-Content $choco.installScript -Force -Encoding UTF8
41+
}
42+
43+
44+
function ChocoUpdateNuspec([object] $choco, [string] $history, [string] $githubRepoApi) {
45+
$repo = $(Invoke-Webrequest $githubRepoApi).Content | ConvertFrom-Json;
46+
$topics = $(Invoke-Webrequest $githubRepoApi/topics -Headers @{'Accept'='application/vnd.github.mercy-preview+json'}).Content | ConvertFrom-Json
47+
$xml = [xml] $(gc -Path $choco.nuspec -Encoding UTF8);
48+
$xml.package.metadata.version = [Regex]::Replace($version, '^v', '');
49+
$xml.package.metadata.summary = $repo.description;
50+
$xml.package.metadata.tags = [string]::Join(" ", $topics.names);
51+
$xml.package.metadata.copyright = "Copyright $([DateTime]::Now.Year) René Larch";
52+
$xml.package.metadata.releaseNotes = [string]::Join("`r`n", $history);
53+
$xml.Save($choco.nuspec);
54+
}
55+
56+
57+
function ChocoPublish([object] $choco, [bool] $debug = $false) {
58+
59+
$chocoCommand = "choco";
60+
if (!$(Get-Command $chocoCommand -errorAction SilentlyContinue)) {
61+
Write-Host "Install chocolatey";
62+
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
63+
$env:Path += ";%ALLUSERSPROFILE%\chocolatey\bin";
64+
}
65+
66+
# create the nuspec package
67+
& $chocoCommand pack $choco.nuspec --out $choco.dir
68+
69+
$ver = [Regex]::Replace($choco.version, "^v(.*)", '$1');
70+
$nupkgName = $choco.nuspec.replace('.nuspec', ".$($ver).nupkg");
71+
72+
if (!$debug) {
73+
# if token is given, we will publish the package to Chocolatey here
74+
if ($env:CHOCO_TOKEN) {
75+
& $chocoCommand apiKey -k $env:CHOCO_TOKEN -source https://push.chocolatey.org/
76+
& $chocoCommand push $nupkgName -source https://push.chocolatey.org/
77+
} else {
78+
Write-Warning "Chocolatey token was not set. Publication skipped."
79+
}
80+
} else {
81+
# For development/debugging purposes
82+
$script = Get-Content $choco.installScript -Encoding UTF8 -Raw
83+
Write-Host "=============== Choco Install Script ==============="
84+
Write-Host $script
85+
Write-Host "===================================================="
86+
87+
$script = Get-Content $choco.uninstallScript -Encoding UTF8 -Raw
88+
Write-Host "============== Choco Uninstall Script =============="
89+
Write-Host $script
90+
Write-Host "===================================================="
91+
92+
$nuspec = Get-Content $choco.nuspec -Encoding UTF8 -Raw
93+
Write-Host "================== Nuspec ==========================="
94+
Write-Host $nuspec
95+
Write-Host "===================================================="
96+
97+
Write-Host "$chocoCommand pack " $choco.nuspec
98+
Write-Host "$chocoCommand apiKey -k $env:CHOCO_TOKEN -source https://push.chocolatey.org/"
99+
Write-Host "$chocoCommand push $nupkgName"
100+
}
101+
}
102+
103+
104+
class Git {
105+
static [string[]] GetTags() {
106+
return $(git tag --list).Split("`n");
107+
}
108+
static [string[]] GetVersionTags() {
109+
return [Git]::GetTags() | Select-String -pattern "v[\d+\.]+(-(alpha|beta))?";
110+
}
111+
static [string[]] GetHistorySince([string] $tagOrHash) {
112+
if ([string]::IsNullOrEmpty($tagOrHash)){
113+
return $(git log --oneline);
114+
}
115+
return $(git log "$tagOrHash..HEAD" --oneline);
116+
}
117+
}
118+
119+
120+
#########################
121+
# run main #
122+
#########################
123+
124+
Main;
125+
126+
#########################

MouseTrap/choco/chocolateyinstall.ps1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
$ErrorActionPreference = 'Stop';
2+
3+
$version = '<version>'
4+
$hash = '<hash>'
5+
$versionNumber = [Regex]::Replace($version, 'v(\d+\.\d+\.\d+).*', '$1')
6+
7+
$packageName = 'mousetrap'
8+
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
9+
$url = "https://github.com/r-Larch/MouseTrap/releases/download/$version/MouseTrap-$versionNumber.zip"
10+
11+
12+
$packageArgs = @{
13+
packageName = $packageName
14+
unzipLocation = $toolsDir
15+
url = $url
16+
checksum = $hash
17+
checksumType = 'SHA256'
18+
}
19+
20+
Install-ChocolateyZipPackage @packageArgs
21+
22+
23+
$mousetrap = "$toolsDir\$packageName";
24+
25+
# install
26+
& $mousetrap "-i";
27+
if (-not $?) {
28+
throw "error while install";
29+
}
30+
31+
# start the app minimized as tray icon in taskbar.
32+
& $mousetrap
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
$ErrorActionPreference = 'Stop';
3+
4+
$packageName= 'mousetrap.exe'
5+
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
6+
7+
$mousetrap = "$toolsDir\$packageName";
8+
9+
# uninstall
10+
& $mousetrap "-u";
11+
if (-not $?) {
12+
throw "error while uninstall";
13+
}

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,20 @@ For this tool to function correctly you should have:
1818
You can find the latest release here:
1919
> [Download](https://github.com/r-Larch/MouseTrap/releases)
2020
21+
You can install MouseTrap with **chocolatey**:
22+
```Powershell
23+
# install the package
24+
choco install mousetrap
25+
26+
# running it
27+
mousetrap
28+
```
2129

2230
## Changelog
2331

32+
### Version 1.0.20
33+
- Add `chocolatey` support
34+
2435
### Version 1.0.19
2536

2637
- **Migrate to .NET 8**

VERIFICATION.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22
VERIFICATION
33
Verification is intended to assist the Chocolatey moderators and community
44
in verifying that this package's contents are trustworthy.
5-
65

7-
This package contains MouseTrap.exe; This is an open source Windows Application written by me (René Larch).
6+
7+
This package contains the tool MouseTrap.
8+
This is an open source Windows Application written by me (René Larch).
89
You can find the source code on github:
910

1011
* https://github.com/r-Larch/MouseTrap/
12+
13+
Files:
14+
15+
|-------------------------------|--------------------------------------------------------|
16+
| Files | Description |
17+
|-------------------------------|--------------------------------------------------------|
18+
| MouseTrap.exe | Executable .NET wrapper to start the .NET Core Runtime |
19+
| MouseTrap.dll | The actual application to run in the .NET Core Runtime |
20+
| MouseTrap.pdb | Debugging symbols to have better error reports |
21+
| MouseTrap.deps.json | Dependencies file required for the .NET Core Runtime |
22+
| MouseTrap.runtimeconfig.json | Runtimeconfig file required for the .NET Core Runtime |
23+
|-------------------------------|--------------------------------------------------------|

0 commit comments

Comments
 (0)