winutil icon indicating copy to clipboard operation
winutil copied to clipboard

Make winutil self contained, and dev/prod agnostic

Open couleurm opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? More of a nitpick from me / quality of life improvement for contributors

Describe the solutions you're proposing Instead of having to comment and uncomment a line, why not leverage PowerShell and CI to either:

  • "Compile" (combine to a single file) MainWindow.xaml and winutil.ps1 into one file to have it self contained (a single file to irm and worry about) and speed up startup time (one less request to make to github's servers, could also make it available offline easily (of course the app installer would be unusable))

Quick and dirty way I've wrapped my brain about making it work through CI, feel free to copy my main.yaml

Set-Content ./main.ps1 @"
`$inputXML = @'
$(Get-Content ./MainWindow.xaml -Raw)
'@
$(Get-Content ./winutil.ps1 -Raw)
"@
# If you're testing this out yourself don't forget to comment the current routine to not overwrite it
  • Make use of MyInvocation to use ./MainWindow.xaml if available, else make a request to GitHub to grab it:
if (Test-Path "$PSScriptRoot/MainWindow.Xaml"){
	$inputXML = Get-Content "MainWindow.xaml"
	Write-Verbose "Using XAML from current directory" -Verbose
} else {
	$inputXML = (new-object Net.WebClient).DownloadString("https://raw.githubusercontent.com/ChrisTitusTech/winutil/$BranchToUse/MainWindow.xaml")
	Write-Verbose "Using latest XAML from GitHub"
}
# Presence of -Verbose on the first switch exclusivly on the first instance of Write-Verbose is intentional

Additional info That may hurt your $10 EXE wrapper's sales, my apologies if I'm touching a sensitive subject

couleurm avatar Nov 26 '22 12:11 couleurm

Something I tried implementing in the runspace version where you set an environment variable and it will load the files locally. https://github.com/ChrisTitusTech/winutil/blob/f83ffaf0a9acd343dc7470d03d640fceade7450b/runspace.ps1#L1362-L1377

Likely easily moveable to the main script. Currently there is a CI pipeline to modify the variable $BranchToUse so that main and test are more easily testable. Also I agree, files being pulled from gitlab is a quality of life improvement for using the script but sometimes can be a pain to develop for.

DeveloperDurp avatar Nov 26 '22 12:11 DeveloperDurp

On the same topic, that probably slows it down by quite a bit

https://github.com/ChrisTitusTech/winutil/blob/f83ffaf0a9acd343dc7470d03d640fceade7450b/winutil.ps1#L26-L34

Try it out in your shell (is it my slow connection?):

$BranchToUse = "main"
$configs = @{}

(
    "applications", 
    "tweaks",
    "preset", 
    "feature"
) | ForEach-Object {
    #$configs["$PSItem"] = Get-Content .\config\$PSItem.json | ConvertFrom-Json
    $configs["$psitem"] = Invoke-RestMethod "https://raw.githubusercontent.com/ChrisTitusTech/winutil/$BranchToUse/config/$psitem.json"
}

This also could be compiled with CI to make it self contained

couleurm avatar Nov 26 '22 14:11 couleurm

Might be your connection, I haven't noticed an impact.

I'll create a draft PR and play around with it as a proof of concept. In theory it could improve the reliability of the script and the ability to run offline as an exe would be easier.

DeveloperDurp avatar Nov 26 '22 14:11 DeveloperDurp