aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/xyz/brysonsteck/servercraft/controllers/InfoController.kt
blob: a4bdb1828ce67aac5597ef890ae21e848513c4b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package xyz.brysonsteck.servercraft.controllers

import javafx.fxml.FXML
import javafx.application.Platform
import javafx.scene.Node
import javafx.scene.control.Hyperlink
import javafx.stage.Stage
import javafx.event.ActionEvent
import java.awt.Desktop
import java.net.URI

class InfoController {
  private val emails = mapOf(
    "bryson" to "me@brysonsteck.xyz"
  )
  private val websites = mapOf(
    "bryson" to "https://brysonsteck.xyz"
  )
  private val source = "https://codeberg.org/brysonsteck/ServerCraft"
  private val license = "https://www.gnu.org/licenses/gpl-3.0.html"

  @FXML
  private fun openHyperlink(e: ActionEvent) {
    val link = e.source as Hyperlink
    link.isVisited = false
    val split = link.id.split('_').toMutableList()
    split.add("")
    val os = System.getProperty("os.name").lowercase()

    val desktop = Desktop.getDesktop()
    try {
      when {
        split[1].equals("email") -> {
          if (!os.contains("linux")) {
            desktop.browse(URI("mailto:" + emails[split[0]]))
          } else {
            Runtime.getRuntime().exec("xdg-open mailto:" + emails[split[0]])
          }
        }
        split[1].equals("website") -> {
          if (!os.contains("linux")) {
            desktop.browse(URI(websites[split[0]]))
          } else {
            Runtime.getRuntime().exec("xdg-open " + websites[split[0]])
          }
        }
        split[0].equals("source") -> {
          if (!os.contains("linux")) {
            desktop.browse(URI(source))
          } else {
            Runtime.getRuntime().exec("xdg-open " + source)
          }
        }
        split[0].equals("license") -> {
          println("license")
          if (!os.contains("linux")) {
            desktop.browse(URI(license))
          } else {
            Runtime.getRuntime().exec("xdg-open " + license)
          }
        }
      }
    } catch (e: Exception) {
      println(e)
    }
  }

  @FXML
  private fun closeInfo(e: ActionEvent) {
    val source = e.getSource() as Node 
    val stage = source.getScene().getWindow() as Stage
    stage.close();
  }
}