Skip to content

Commit

Permalink
feat: adds validation if frame is within any screens bounds (#42)
Browse files Browse the repository at this point in the history
* chore: Added validation if frame is within any screens bounds.

* refactor: improve documentation and code style

---------

Co-authored-by: Kris <[email protected]>
  • Loading branch information
CloudS3c and Z-Kris authored Dec 23, 2024
1 parent 9873961 commit 4393c59
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gui/proxy-tool/src/main/kotlin/net/rsprox/gui/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import net.rsprox.proxy.ProxyService
import net.rsprox.proxy.config.BINARY_PATH
import java.awt.Desktop
import java.awt.Dimension
import java.awt.GraphicsEnvironment
import java.awt.event.ComponentAdapter
import java.awt.event.ComponentEvent
import java.awt.event.WindowAdapter
Expand Down Expand Up @@ -56,6 +57,9 @@ public class App {
frame.size = defaultSize
frame.minimumSize = UIScale.scale(Dimension(800, 600))
frame.iconImages = FlatSVGUtils.createWindowIconImages("/favicon.svg")
if (!validFramePosition(frame)) {
frame.setLocationRelativeTo(null)
}
val windowHandler =
object : WindowAdapter() {
override fun windowClosing(e: WindowEvent) {
Expand Down Expand Up @@ -220,6 +224,17 @@ public class App {
add(sessionsPanel)
}

/**
* Checks if the frame intersects with any screen device. If the function returns false, the window
* is completely outside the device's visible area, meaning the user would not be able to interact
* with the window.
*/
private fun validFramePosition(frame: JFrame): Boolean {
return GraphicsEnvironment.getLocalGraphicsEnvironment().screenDevices.any { device ->
device.defaultConfiguration.bounds.intersects(frame.bounds)
}
}

public companion object {
public val service: ProxyService = ProxyService(ByteBufAllocator.DEFAULT)
}
Expand Down

0 comments on commit 4393c59

Please sign in to comment.