Skip to content

Commit

Permalink
Highly anticipated fix for small screens (#1358)
Browse files Browse the repository at this point in the history
* Increase performance during loading.
Add a clear button to the search box.
Add link and description attributes to the applications JSON.
Use the link for linking to the app website.
Use the description as a tooltip for each app.
Add a clickable link to the website for each application (this took a long time; don't kick me if I got some wrong).
Pressing Escape now clears the filter box.
Pressing Alt-P prints your PID.

* Fix for services that are being stopped

* Compile winutil

* Adding new Get-LocalizedYesNo based on choice.exe which is faster and more reliable, thank you @dtm-r for implementing it and testing it on English, German, Dutch, French, Italian, Spansich and Russian. Incredible work by @dtm-r, all cridit and props go to him.
See this thread for details #1324

* Added error-checking logic for mounting ISOs and also created a wiki page that explains some of the errors.

* Highly anticipated fix for small screen computers

---------

Co-authored-by: KonTy <[email protected]>
  • Loading branch information
KonTy and KonTy authored Jan 10, 2024
1 parent 699c984 commit a4f2ebb
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 62 deletions.
69 changes: 38 additions & 31 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -280,27 +280,18 @@ $sync["Form"].Add_MouseDoubleClick({
}
})

$sync["Form"].Add_ContentRendered({

# setting window icon to make it look more professional
$sync["Form"].Add_Loaded({

$downloadUrl = "https://christitus.com/images/logo-full.png"
$destinationPath = Join-Path $env:TEMP "cttlogo.png"

# Check if the file already exists
if (-not (Test-Path $destinationPath)) {
# File does not exist, download it
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($downloadUrl, $destinationPath)
Write-Host "File downloaded to: $destinationPath"
} else {
Write-Output "File already exists at: $destinationPath"
foreach ($proc in (Get-Process | Where-Object { $_.MainWindowTitle -and $_.MainWindowTitle -like "*tit*" })) {
if ($proc.Id -ne [System.IntPtr]::Zero) {
Write-Debug "MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle) $($proc.MainWindowHandle)"
$windowHandle = $proc.MainWindowHandle
}
}
$sync["Form"].Icon = $destinationPath

Try {
[Void][Window]
} Catch {
try {
[void][Window]
} catch {
Add-Type @"
using System;
using System.Runtime.InteropServices;
Expand All @@ -312,8 +303,7 @@ $sync["Form"].Add_Loaded({
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ShowWindow(IntPtr handle, int state);
public static extern int GetSystemMetrics(int nIndex);
}
public struct RECT {
public int Left; // x position of upper-left corner
Expand All @@ -323,20 +313,37 @@ $sync["Form"].Add_Loaded({
}
"@
}

$processId = [System.Diagnostics.Process]::GetCurrentProcess().Id
$windowHandle = (Get-Process -Id $processId).MainWindowHandle

$rect = New-Object RECT
[Void][Window]::GetWindowRect($windowHandle,[ref]$rect)

# only snap upper edge don't move left to right, in case people have multimon setup
$x = $rect.Left
$y = 0
[void][Window]::GetWindowRect($windowHandle, [ref]$rect)
$width = $rect.Right - $rect.Left
$height = $rect.Bottom - $rect.Top

# Move the window to that position...
[Void][Window]::MoveWindow($windowHandle, $x, $y, $width, $height, $True)

Write-Debug "UpperLeft:$($rect.Left),$($rect.Top) LowerBottom:$($rect.Right),$($rect.Bottom). Width:$($width) Height:$($height)"

# Load the Windows Forms assembly
Add-Type -AssemblyName System.Windows.Forms
$primaryScreen = [System.Windows.Forms.Screen]::PrimaryScreen
# Check if the primary screen is found
if ($primaryScreen) {
# Extract screen width and height for the primary monitor
$screenWidth = $primaryScreen.Bounds.Width
$screenHeight = $primaryScreen.Bounds.Height

# Print the screen size
Write-Debug "Primary Monitor Width: $screenWidth pixels"
Write-Debug "Primary Monitor Height: $screenHeight pixels"

# Compare with the primary monitor size
if ($width -gt $screenWidth -or $height -gt $screenHeight) {
Write-Debug "The specified width and/or height is greater than the primary monitor size."
[void][Window]::MoveWindow($windowHandle, 0, 0, $screenWidth, $screenHeight, $True)
} else {
Write-Debug "The specified width and height are within the primary monitor size limits."
}
} else {
Write-Debug "Unable to retrieve information about the primary monitor."
}

Invoke-WPFTab "WPFTab1BT"
$sync["Form"].Focus()
Expand Down
69 changes: 38 additions & 31 deletions winutil.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9808,27 +9808,18 @@ $sync["Form"].Add_MouseDoubleClick({
}
})

$sync["Form"].Add_ContentRendered({

# setting window icon to make it look more professional
$sync["Form"].Add_Loaded({

$downloadUrl = "https://christitus.com/images/logo-full.png"
$destinationPath = Join-Path $env:TEMP "cttlogo.png"

# Check if the file already exists
if (-not (Test-Path $destinationPath)) {
# File does not exist, download it
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($downloadUrl, $destinationPath)
Write-Host "File downloaded to: $destinationPath"
} else {
Write-Output "File already exists at: $destinationPath"
foreach ($proc in (Get-Process | Where-Object { $_.MainWindowTitle -and $_.MainWindowTitle -like "*tit*" })) {
if ($proc.Id -ne [System.IntPtr]::Zero) {
Write-Debug "MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle) $($proc.MainWindowHandle)"
$windowHandle = $proc.MainWindowHandle
}
}
$sync["Form"].Icon = $destinationPath

Try {
[Void][Window]
} Catch {
try {
[void][Window]
} catch {
Add-Type @"
using System;
using System.Runtime.InteropServices;
Expand All @@ -9840,8 +9831,7 @@ $sync["Form"].Add_Loaded({
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ShowWindow(IntPtr handle, int state);
public static extern int GetSystemMetrics(int nIndex);
}
public struct RECT {
public int Left; // x position of upper-left corner
Expand All @@ -9851,20 +9841,37 @@ $sync["Form"].Add_Loaded({
}
"@
}

$processId = [System.Diagnostics.Process]::GetCurrentProcess().Id
$windowHandle = (Get-Process -Id $processId).MainWindowHandle

$rect = New-Object RECT
[Void][Window]::GetWindowRect($windowHandle,[ref]$rect)

# only snap upper edge don't move left to right, in case people have multimon setup
$x = $rect.Left
$y = 0
[void][Window]::GetWindowRect($windowHandle, [ref]$rect)
$width = $rect.Right - $rect.Left
$height = $rect.Bottom - $rect.Top

# Move the window to that position...
[Void][Window]::MoveWindow($windowHandle, $x, $y, $width, $height, $True)

Write-Debug "UpperLeft:$($rect.Left),$($rect.Top) LowerBottom:$($rect.Right),$($rect.Bottom). Width:$($width) Height:$($height)"

# Load the Windows Forms assembly
Add-Type -AssemblyName System.Windows.Forms
$primaryScreen = [System.Windows.Forms.Screen]::PrimaryScreen
# Check if the primary screen is found
if ($primaryScreen) {
# Extract screen width and height for the primary monitor
$screenWidth = $primaryScreen.Bounds.Width
$screenHeight = $primaryScreen.Bounds.Height

# Print the screen size
Write-Debug "Primary Monitor Width: $screenWidth pixels"
Write-Debug "Primary Monitor Height: $screenHeight pixels"

# Compare with the primary monitor size
if ($width -gt $screenWidth -or $height -gt $screenHeight) {
Write-Debug "The specified width and/or height is greater than the primary monitor size."
[void][Window]::MoveWindow($windowHandle, 0, 0, $screenWidth, $screenHeight, $True)
} else {
Write-Debug "The specified width and height are within the primary monitor size limits."
}
} else {
Write-Debug "Unable to retrieve information about the primary monitor."
}

Invoke-WPFTab "WPFTab1BT"
$sync["Form"].Focus()
Expand Down

0 comments on commit a4f2ebb

Please sign in to comment.