@@ -15,7 +15,7 @@ Determines if the LM Studio window should be visible after starting.
1515When specified, returns the Process object of the LM Studio application.
1616
1717. EXAMPLE
18- Start-LMStudioApplication -WithVisibleWindow -Passthru
18+ Start-LMStudioApplication -ShowWindow -Passthru
1919#>
2020function Start-LMStudioApplication {
2121
@@ -27,8 +27,7 @@ function Start-LMStudioApplication {
2727 Position = 0 ,
2828 HelpMessage = " Show or hide the LM Studio window after starting"
2929 )]
30- [Alias (" sw" , " ShowWindow" )]
31- [switch ]$WithVisibleWindow ,
30+ [switch ]$ShowWindow ,
3231 # #######################################################################
3332 [Parameter (
3433 Mandatory = $false ,
@@ -77,20 +76,18 @@ process {
7776 # start server component
7877 $null = Microsoft.PowerShell.Management\Start-Process `
7978 - FilePath $paths.LMSExe `
80- - ArgumentList " server" , " start" , " --port" , " 1234" `
81- - NoNewWindow
79+ - ArgumentList " server" , " start" , " --port" , " 1234"
8280 Microsoft.PowerShell.Utility\Start-Sleep - Seconds 4
81+ $null = Microsoft.PowerShell.Management\Start-Process `
82+ - FilePath $paths.LMStudioExe
83+ Microsoft.PowerShell.Utility\Start-Sleep - Seconds 4
84+
8385 }
8486 ArgumentList = @ ($paths , ($ShowWindow -eq $true ))
8587 }
8688
8789 $null = Microsoft.PowerShell.Core\Start-Job @jobParams | Microsoft.PowerShell.Core\Wait-Job
8890
89- if ($showWindow ) {
90-
91- $null = GenXdev.AI\Get-LMStudioWindow - ShowWindow - NoAutoStart - ErrorAction SilentlyContinue - WarningAction SilentlyContinue
92- }
93-
9491 # verify process starts within timeout period
9592 Microsoft.PowerShell.Utility\Write-Verbose " Waiting for LM Studio process..."
9693 $timeout = 30
@@ -110,13 +107,25 @@ process {
110107
111108 # return process object if requested
112109 if ($Passthru ) {
113- Microsoft.PowerShell.Management\Get-Process - Name " LM Studio" - ErrorAction Stop
110+ Microsoft.PowerShell.Management\Get-Process - Name " LM Studio" - ErrorAction Stop |
111+ Microsoft.PowerShell.Core\Where-Object - Property MainWindowHandle -ne 0 |
112+ Microsoft.PowerShell.Utility\Select-Object - First 1
114113 }
115114 }
116115
117116 end {
118117 if ($ShowWindow -and $PSCmdlet.ShouldProcess (" LM Studio" , " Show window" )) {
119- $null = GenXdev.AI\Get-LMStudioWindow - NoAutoStart - ShowWindow - ErrorAction SilentlyContinue - WarningAction SilentlyContinue
118+ try {
119+ $a = (GenXDev.Windows\Get-Window - ProcessName " LM Studio" ) ;
120+ if ($null -eq $a ) { return }
121+ $null = $a.Show ()
122+ $null = $a.Restore ()
123+ $null = GenXDev.Windows\Set-WindowPosition - WindowHelper $a - Monitor 0 - Right
124+ $null = GenXDev.Windows\Set-WindowPosition - Left - Monitor 0 - Left
125+ }
126+ catch {
127+
128+ }
120129 }
121130 }
122131}
0 commit comments