added autoconnect at startup
This commit is contained in:
parent
0f8d2ba256
commit
71f50b832e
|
@ -1,31 +1,12 @@
|
||||||
package org.hso.texturesyncclient.app
|
package org.hso.texturesyncclient.app
|
||||||
|
|
||||||
import org.hso.texturesyncclient.controller.RootController
|
|
||||||
import org.hso.texturesyncclient.controller.SettingsController
|
|
||||||
import org.hso.texturesyncclient.view.importView.ImportView
|
|
||||||
import org.hso.texturesyncclient.view.mainView.MainView
|
|
||||||
import org.hso.texturesyncclient.view.mainView.MainViewController
|
|
||||||
import org.hso.texturesyncclient.view.startupView.StartupView
|
import org.hso.texturesyncclient.view.startupView.StartupView
|
||||||
import org.hso.texturesyncclient.view.startupView.StartupViewController
|
import org.hso.texturesyncclient.view.startupView.StartupViewController
|
||||||
import tornadofx.App
|
import tornadofx.App
|
||||||
|
|
||||||
class Main: App(StartupView::class){
|
class Main: App(StartupView::class){
|
||||||
|
|
||||||
val controller = RootController()
|
//start first controller
|
||||||
|
private val svc = StartupViewController()
|
||||||
private val svc: StartupViewController by inject()
|
|
||||||
|
|
||||||
init {
|
|
||||||
SettingsController.init()
|
|
||||||
|
|
||||||
if (SettingsController.serverAddressIsSet()) {
|
|
||||||
//load settings in ui and try to connect
|
|
||||||
println("serverAddress is set")
|
|
||||||
svc.setServerAddress(SettingsController.getServerAddress())
|
|
||||||
svc.btnConnectAction(SettingsController.getServerAddress())
|
|
||||||
} else {
|
|
||||||
println("serverAddress is not set")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ import javafx.collections.ObservableList
|
||||||
import javafx.event.EventHandler
|
import javafx.event.EventHandler
|
||||||
import javafx.stage.DirectoryChooser
|
import javafx.stage.DirectoryChooser
|
||||||
import org.hso.texturesyncclient.alerts.JFXOkayCancelAlert
|
import org.hso.texturesyncclient.alerts.JFXOkayCancelAlert
|
||||||
|
import org.hso.texturesyncclient.controller.net.AutoConnect
|
||||||
import org.hso.texturesyncclient.controller.net.Connection
|
import org.hso.texturesyncclient.controller.net.Connection
|
||||||
import org.hso.texturesyncclient.model.GUIModel
|
import org.hso.texturesyncclient.model.GUIModel
|
||||||
import org.hso.texturesyncclient.model.Sha256
|
import org.hso.texturesyncclient.model.Sha256
|
||||||
|
@ -37,17 +38,6 @@ class RootController : Controller() {
|
||||||
|
|
||||||
private var lastExportDir: String = System.getProperty("user.home")
|
private var lastExportDir: String = System.getProperty("user.home")
|
||||||
|
|
||||||
init {
|
|
||||||
/*var data = Texture()
|
|
||||||
var img = con.getTexturePreview(data.textureHash)
|
|
||||||
var test = GUIModel(data, img)
|
|
||||||
test.exportItem.setOnAction {
|
|
||||||
|
|
||||||
}
|
|
||||||
mvc.addElement(test)*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* calculate the resolution, get today's date -> upload to server
|
* calculate the resolution, get today's date -> upload to server
|
||||||
* @param path the absolute path of the file on the client's system
|
* @param path the absolute path of the file on the client's system
|
||||||
|
@ -74,7 +64,6 @@ class RootController : Controller() {
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
println(e)
|
println(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,18 +71,53 @@ class RootController : Controller() {
|
||||||
* @param name server name as IP or domain
|
* @param name server name as IP or domain
|
||||||
*/
|
*/
|
||||||
fun initConnection(name: String) {
|
fun initConnection(name: String) {
|
||||||
try {
|
if (name == " ") {
|
||||||
con = Connection(InetAddress.getByName(name))
|
//no user input, try automatic connect or restore address from settings file
|
||||||
con.ping()
|
println("try auto connect")
|
||||||
println("Connection to Server successful")
|
try {
|
||||||
SettingsController.setServerAddress(name)
|
val foundServer = AutoConnect.searchServer()
|
||||||
switchStartupToMain()
|
if (foundServer != null) {
|
||||||
println("swithing to MainView @ initCon")
|
println("[auto] server found")
|
||||||
} catch (e: Exception) {
|
con = foundServer
|
||||||
println(e)
|
con.ping()
|
||||||
println("Connection to Server NOT successful")
|
println("auto Connection to Server successful")
|
||||||
|
switchStartupToMain()
|
||||||
|
} else {
|
||||||
|
println("[auto] no server found")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
println(e)
|
||||||
|
println("auto Connection to Server NOT successful")
|
||||||
|
}
|
||||||
|
if (SettingsController.serverAddressIsSet()) {
|
||||||
|
println("[file] try connect with settings file")
|
||||||
|
try {
|
||||||
|
con = Connection(InetAddress.getByName(SettingsController.getServerAddress()))
|
||||||
|
con.ping()
|
||||||
|
println("[file] Connection to Server successful")
|
||||||
|
switchStartupToMain()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
println(e)
|
||||||
|
println("[file] Connection to Server NOT successful")
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
println("[file] no address in settings file")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//try to connect with user input
|
||||||
|
try {
|
||||||
|
println("try connect with user input")
|
||||||
|
con = Connection(InetAddress.getByName(name))
|
||||||
|
con.ping()
|
||||||
|
println("Connection to Server successful")
|
||||||
|
SettingsController.setServerAddress(name) //store address in settings file
|
||||||
|
switchStartupToMain()
|
||||||
|
println("swithing to MainView @ initCon")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
println(e)
|
||||||
|
println("Connection to Server NOT successful")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun search(tags: ObservableList<String>): ArrayList<GUIModel> {
|
fun search(tags: ObservableList<String>): ArrayList<GUIModel> {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package org.hso.texturesyncclient.view.startupView
|
package org.hso.texturesyncclient.view.startupView
|
||||||
|
|
||||||
import org.hso.texturesyncclient.controller.RootController
|
import org.hso.texturesyncclient.controller.RootController
|
||||||
|
import org.hso.texturesyncclient.controller.SettingsController
|
||||||
import org.hso.texturesyncclient.view.mainView.MainView
|
import org.hso.texturesyncclient.view.mainView.MainView
|
||||||
|
import tornadofx.ConfigProperties
|
||||||
import tornadofx.Controller
|
import tornadofx.Controller
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,29 +12,55 @@ class StartupViewController : Controller() {
|
||||||
private val sv = find(StartupView::class)
|
private val sv = find(StartupView::class)
|
||||||
private val rootc = find(RootController::class)
|
private val rootc = find(RootController::class)
|
||||||
|
|
||||||
fun setServerAddress(address: String){
|
init {
|
||||||
|
println("init StartupViewController")
|
||||||
|
SettingsController.init()
|
||||||
|
startConnectionUI()
|
||||||
|
runAsync {
|
||||||
|
rootc.initConnection(" ")
|
||||||
|
} ui {
|
||||||
|
// reset for later use
|
||||||
|
endConnectionUI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setServerAddress(address: String) {
|
||||||
sv.tfServerIP.text = address
|
sv.tfServerIP.text = address
|
||||||
sv.tfServerIP.isFocusTraversable = false
|
sv.tfServerIP.isFocusTraversable = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun btnConnectAction(name: String) {
|
fun btnConnectAction(name: String) {
|
||||||
sv.labelStatus.text = "Verbinden ..."
|
startConnectionUI()
|
||||||
sv.tfServerIP.isEditable = false
|
|
||||||
sv.btnConnect.isDisable = true
|
|
||||||
sv.spinnerStatus.isVisible = true
|
|
||||||
|
|
||||||
runAsync {
|
runAsync {
|
||||||
rootc.initConnection(name)
|
rootc.initConnection(name)
|
||||||
} ui {
|
} ui {
|
||||||
// reset for later use
|
// reset for later use
|
||||||
sv.spinnerStatus.isVisible = false
|
endConnectionUI()
|
||||||
sv.labelStatus.text = "Verbindung zum Server einrichten"
|
|
||||||
sv.tfServerIP.isEditable = true
|
|
||||||
sv.btnConnect.isDisable = false
|
|
||||||
sv.tfServerIP.clear()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* show spinner and block textfied + button and set label
|
||||||
|
*/
|
||||||
|
fun startConnectionUI() {
|
||||||
|
sv.labelStatus.text = "Verbinden ..."
|
||||||
|
sv.tfServerIP.isEditable = false
|
||||||
|
sv.btnConnect.isDisable = true
|
||||||
|
sv.spinnerStatus.isVisible = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove spinner and unblock textfied + button and set label
|
||||||
|
*/
|
||||||
|
fun endConnectionUI() {
|
||||||
|
sv.spinnerStatus.isVisible = false
|
||||||
|
sv.labelStatus.text = "Verbindung zum Server einrichten"
|
||||||
|
sv.tfServerIP.isEditable = true
|
||||||
|
sv.btnConnect.isDisable = false
|
||||||
|
sv.tfServerIP.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue