Skip to content

Add projectUrl at the end of the description in the package selection #714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sara-rn
Copy link
Contributor

@sara-rn sara-rn commented Aug 4, 2025

Add projectUrl at the end of the package description if it contains a valid URL to the package selection window
closes #708

@sara-rn sara-rn force-pushed the add-package-projecturl branch from d9016e9 to 82253ec Compare August 4, 2025 18:34
@sara-rn
Copy link
Contributor Author

sara-rn commented Aug 4, 2025

@Ana06 , as per #708 (comment) this is the only way I figured out to make this work but the linter complains

@sara-rn sara-rn force-pushed the add-package-projecturl branch 3 times, most recently from 6056a3c to dde7a5f Compare August 4, 2025 18:42
@sara-rn sara-rn requested a review from Ana06 August 4, 2025 18:43
@sara-rn sara-rn force-pushed the add-package-projecturl branch from dde7a5f to cda6eb1 Compare August 5, 2025 10:29
@sara-rn
Copy link
Contributor Author

sara-rn commented Aug 5, 2025

Space between package description and URL cannot be extended, I modified the Y position as per the comment in the issue #708 (#708 (comment))
Screenshot From 2025-08-05 12-30-18

@sara-rn sara-rn force-pushed the add-package-projecturl branch 2 times, most recently from 9c89d92 to d6a1557 Compare August 5, 2025 10:40
install.ps1 Outdated
}
# Check if $projectUrl contains a valid URL
if ($projectUrl -match "^http") {
$packageObject = [PSCustomObject]@{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] why is this a PsCustomObject instead of a normal hash table? 😕

Suggested change
$packageObject = [PSCustomObject]@{
$packageObject = @{

install.ps1 Outdated
Comment on lines 531 to 541
# Check if $projectUrl contains a valid URL
if ($projectUrl -match "^http") {
$packageObject = [PSCustomObject]@{
PackageName = $packageName
PackageDescription = $description
PackageUrl = $projectUrl}
}else{
$packageObject = [PSCustomObject]@{
PackageName = $packageName
PackageDescription = $description}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not duplicate code:

Suggested change
# Check if $projectUrl contains a valid URL
if ($projectUrl -match "^http") {
$packageObject = [PSCustomObject]@{
PackageName = $packageName
PackageDescription = $description
PackageUrl = $projectUrl}
}else{
$packageObject = [PSCustomObject]@{
PackageName = $packageName
PackageDescription = $description}
}
$packageObject = @{
PackageName = $packageName
PackageDescription = $description
}
# Check if $projectUrl contains a valid URL
if ($projectUrl -match "^http") {
$packageObject.PackageUrl = $projectUrl
}

Copy link
Contributor Author

@sara-rn sara-rn Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to create PSCustomObject entries from the hashes for several reasons, including better readability and a more structured data format. Also the code is simpler and easier to read in the function Get-AllPackages (here) where we need to get a flattened array of only entries with property PackageName.
Additionally this is what Gemini responds to the question:

Hash vs. PSCustomObject
It's generally a better practice to use PSCustomObject entries instead of raw hashes for several reasons:

Property Access: You can access properties with the dot notation (e.g., $entry.PackageName), which is cleaner and more readable than hash notation ($entry["PackageName"]).

IntelliSense: In many PowerShell editors, PSCustomObject provides IntelliSense for its properties, which makes writing and navigating code much easier.

Object-Oriented Structure: They behave more like objects, which is often a more natural fit for representing structured data like your package entries.

Cmdlet Compatibility: Many PowerShell cmdlets are designed to work seamlessly with objects, making it easier to pipe and process your data.

While hashes are flexible, converting them to PSCustomObjects is a recommended practice for better code structure and compatibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason Gemini is providing are IMO not relevant for this simple code and not even correct. For example you can use the dot notation for a simple hash table too:

> $hash = @{ name = "value" }
> $hash.name
value

While I think AI is a useful resource that can speed your code writing, I advise you to be careful with trust it blindly and always rely on official documentation and testing the code on your own.

I think it is overkilled to use an object for this use of case. But if you think the code in Get-AllPackages is simpler, I have no strong opinion (note the suggestion of using a hash was a nitpick, only the code duplication was not, which is already solved.

install.ps1 Outdated
# Create a temporary, local variable with the correct URL for this specific link.
$linkProjectUrl.add_Click({
$tempUrl = $this.Text
[system.Diagnostics.Process]::start($tempUrl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Why are you using [system.Diagnostics.Process]::start instead of the PS functionStart-Process? This is already used in other links in the installer and I would change it there too.

Copy link
Contributor Author

@sara-rn sara-rn Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no particular reason, I asked Gemini and I think it is better to use the built-int cmdlet Start-Process generally but for this particular case it makes no difference and it seems slower. I changed it in the rest of the links as well

Feature

[System.Diagnostics.Process]::Start()

Start-Process

Type

.NET Framework Method

PowerShell Cmdlet

Speed

Generally faster; direct method call.

Slightly slower; involves command parsing.

Parameters

Limited to method overloads (e.g., arguments).

Extensive, with options like -NoNewWindow, -Wait, etc.

Error Handling

Uses standard .NET exception handling.

Integrates with PowerShell's error handling system ($ErrorActionPreference).

Output

Returns a System.Diagnostics.Process object.

Returns a System.Diagnostics.Process object by default, but can be suppressed.

Use Case

Ideal for simple, high-performance tasks within a GUI where you just need to launch a process.

Better for complex scripts where you need fine-grained control over the process, manage output, or use other PowerShell features.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sara-rn what do you mean that it seems slower? We should use the fastest option if this is noticeable for the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't experience any difference myself, this is what Gemini responded and maybe it's worth testing it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think performance shouldn't be an issue for such a simple task (opening a link) and as long as we are using it consistently I have no strong opinion (note I added it as nitpick), but please test that there is no performance difference locally or double check this information in official documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree for this case, like I said I didn't notice any performance issue

@Ana06 Ana06 added the 💎 enhancement It is working, but it could be better label Aug 6, 2025
Add ProjectUrl if it contains a valid URL to the package selection window
@sara-rn sara-rn force-pushed the add-package-projecturl branch from d6a1557 to bb99139 Compare August 8, 2025 10:29
@sara-rn
Copy link
Contributor Author

sara-rn commented Aug 8, 2025

Thanks @Ana06 for the review, I addressed some of the requested changes, see my comments above.
Screenshot From 2025-08-08 12-28-12

@sara-rn sara-rn requested a review from Ana06 August 8, 2025 10:58
}
# Check if $projectUrl contains a valid URL
if ($projectUrl -match "^http") {
Add-Member -InputObject $packageObject -MemberType NoteProperty -Name "PackageUrl" -Value $projectURl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just the code I proposed (simpler and more readable)?

Suggested change
Add-Member -InputObject $packageObject -MemberType NoteProperty -Name "PackageUrl" -Value $projectURl
$packageObject.PackageUrl = $projectUrl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because I am using the PsCustomObject, see my comment #714 (comment)
That doesn't work when using a PsCustomObject, see error : ForEach-Object : Exception setting "PackageUrl": "The property 'PackageUrl' cannot be found on this object. Verify that the property exists and can be set."

install.ps1 Outdated
# Create a temporary, local variable with the correct URL for this specific link.
$linkProjectUrl.add_Click({
$tempUrl = $this.Text
[system.Diagnostics.Process]::start($tempUrl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think performance shouldn't be an issue for such a simple task (opening a link) and as long as we are using it consistently I have no strong opinion (note I added it as nitpick), but please test that there is no performance difference locally or double check this information in official documentation.

@sara-rn sara-rn requested a review from Ana06 August 8, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 enhancement It is working, but it could be better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Installer] Add tool link after the tool description
2 participants