Skip to content
Open
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
66 changes: 46 additions & 20 deletions source/Generic/SteamViewer/SteamViewer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ function GetGameMenuItems
$extensionName = "Steam Viewer"
$subSection = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentsSection")

$menuItem9 = New-Object Playnite.SDK.Plugins.ScriptGameMenuItem
$menuItem9.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentActivateProductDescription")
$menuItem9.FunctionName = "Start-ComponentActivateProduct"
$menuItem9.MenuSection = "$extensionName|$subSection"

$menuItem10 = New-Object Playnite.SDK.Plugins.ScriptGameMenuItem
$menuItem10.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentDownloadsDescription")
$menuItem10.FunctionName = "Start-ComponentDownloads"
$menuItem10.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentActivateProductDescription")
$menuItem10.FunctionName = "Start-ComponentActivateProduct"
$menuItem10.MenuSection = "$extensionName|$subSection"

$menuItem11 = New-Object Playnite.SDK.Plugins.ScriptGameMenuItem
$menuItem11.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentFriendsDescription")
$menuItem11.FunctionName = "Start-ComponentFriends"
$menuItem11.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentDownloadsDescription")
$menuItem11.FunctionName = "Start-ComponentDownloads"
$menuItem11.MenuSection = "$extensionName|$subSection"

$menuItem12 = New-Object Playnite.SDK.Plugins.ScriptGameMenuItem
$menuItem12.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentNewsDescription")
$menuItem12.FunctionName = "Start-ComponentNews"
$menuItem12.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentFriendsDescription")
$menuItem12.FunctionName = "Start-ComponentFriends"
$menuItem12.MenuSection = "$extensionName|$subSection"

$menuItem13 = New-Object Playnite.SDK.Plugins.ScriptGameMenuItem
$menuItem13.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentScreenshotsDescription")
$menuItem13.FunctionName = "Start-ComponentScreenshots"
$menuItem13.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentNewsDescription")
$menuItem13.FunctionName = "Start-ComponentNews"
$menuItem13.MenuSection = "$extensionName|$subSection"

$menuItem14 = New-Object Playnite.SDK.Plugins.ScriptGameMenuItem
$menuItem14.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentSettingsDescription")
$menuItem14.FunctionName = "Start-ComponentSettings"
$menuItem14.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentScreenshotsDescription")
$menuItem14.FunctionName = "Start-ComponentScreenshots"
$menuItem14.MenuSection = "$extensionName|$subSection"

$menuItem15 = New-Object Playnite.SDK.Plugins.ScriptGameMenuItem
$menuItem15.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemComponentSettingsDescription")
$menuItem15.FunctionName = "Start-ComponentSettings"
$menuItem15.MenuSection = "$extensionName|$subSection"

$game = $scriptGameMenuItemActionArgs.Games | Select-Object -last 1
if ([Playnite.SDK.BuiltinExtensions]::GetExtensionFromId($game.PluginId) -eq "SteamLibrary")
{
Comment on lines -31 to 42
Copy link
Owner

Choose a reason for hiding this comment

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

The new menu item should be added last to prevent modifying all other ones. Also helps to maintain consistency in items placement

Expand Down Expand Up @@ -80,11 +80,24 @@ function GetGameMenuItems
$menuItem8.FunctionName = "Start-Library"
$menuItem8.MenuSection = $extensionName

return $menuItem1, $menuItem2, $menuItem3, $menuItem4, $menuItem5, $menuItem6, $menuItem7, $menuItem8, $menuItem9, $menuItem10, $menuItem11, $menuItem12, $menuItem13, $menuItem14
#check if workshop link exists before adding it
$workshopLink = $game.Links | Where-Object { $_.Name -eq "Workshop" }
if ($workshopLink)
{
Comment on lines +84 to +86
Copy link
Owner

Choose a reason for hiding this comment

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

  1. I'd be better if the link search was done by the url instead of name as it would prevent false positives or work in cases where the link name was changed for any reason
  2. I'd prefer if the link search was done in a loop that breaks upon finding, to prevent having to loop through all the links

$menuItem9 = New-Object Playnite.SDK.Plugins.ScriptGameMenuItem
$menuItem9.Description = [Playnite.SDK.ResourceProvider]::GetString("LOCSteam_Viewer_MenuItemGameWorkshopDescription")
$menuItem9.FunctionName = "Start-Workshop"
$menuItem9.MenuSection = $extensionName
return $menuItem1, $menuItem2, $menuItem3, $menuItem4, $menuItem5, $menuItem6, $menuItem7, $menuItem8, $menuItem9, $menuItem10, $menuItem11, $menuItem12, $menuItem13, $menuItem14, $menuItem15
}
else
{
return $menuItem1, $menuItem2, $menuItem3, $menuItem4, $menuItem5, $menuItem6, $menuItem7, $menuItem8, $menuItem10, $menuItem11, $menuItem12, $menuItem13, $menuItem14, $menuItem15
}
}
else
{
return $menuItem9, $menuItem10, $menuItem11, $menuItem12, $menuItem13, $menuItem14
return $menuItem10, $menuItem11, $menuItem12, $menuItem13, $menuItem14, $menuItem15
}
}

Expand Down Expand Up @@ -183,6 +196,19 @@ function Start-PointsShop
Start-Process $uri
}

function Start-Workshop
{
param(
$scriptGameMenuItemActionArgs
)
$game = $scriptGameMenuItemActionArgs.Games | Select-Object -last 1
#get workshop link
$workshopLink = $game.Links | Where-Object { $_.Name -eq "Workshop" }
Copy link
Owner

Choose a reason for hiding this comment

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

Also should be done as a loop and via url

$url = $workshopLink.Url
$uri = "steam://openurl/{0}" -f $url
Comment on lines +207 to +208
Copy link
Owner

Choose a reason for hiding this comment

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

This could be done in a single line

Start-Process $uri
}

function Start-ComponentActivateProduct
{
param(
Expand Down Expand Up @@ -241,4 +267,4 @@ function Start-ComponentSettings

$uri = "steam://open/{0}" -f "settings"
Start-Process $uri
}
}