mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-22 22:36:34 +01:00
Replace GUI balance thread with a akka scheduler (#3174)
* Replace GUI balance thread with a akka scheduler * Make actory system a param
This commit is contained in:
parent
4146876369
commit
604194293c
5 changed files with 25 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
|||
package org.bitcoins.bundle.gui
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import com.typesafe.config.Config
|
||||
import org.bitcoins.db.AppConfig
|
||||
import org.bitcoins.db.AppConfig.DEFAULT_BITCOIN_S_DATADIR
|
||||
|
@ -30,6 +31,9 @@ object BundleGUI extends WalletGUI with JFXApp {
|
|||
}.showAndWait()
|
||||
})
|
||||
|
||||
implicit val system: ActorSystem = ActorSystem(
|
||||
s"bitcoin-s-gui-${System.currentTimeMillis()}")
|
||||
|
||||
lazy val args = parameters.raw
|
||||
|
||||
// Set log location
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.bitcoins.gui
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import org.bitcoins.cli.CliCommand.GetInfo
|
||||
import org.bitcoins.cli.ConsoleCli
|
||||
import org.bitcoins.commons.jsonmodels.BitcoinSServerInfo
|
||||
|
@ -17,6 +18,9 @@ import scala.util._
|
|||
|
||||
object GUI extends WalletGUI with JFXApp {
|
||||
|
||||
implicit val system: ActorSystem = ActorSystem(
|
||||
s"bitcoin-s-gui-${System.currentTimeMillis()}")
|
||||
|
||||
// Catch unhandled exceptions on FX Application thread
|
||||
Thread
|
||||
.currentThread()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.bitcoins.gui
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import org.bitcoins.gui.dlc.DLCPane
|
||||
import scalafx.beans.property.StringProperty
|
||||
import scalafx.geometry._
|
||||
|
@ -10,6 +11,8 @@ abstract class WalletGUI {
|
|||
|
||||
def glassPane: VBox
|
||||
|
||||
implicit val system: ActorSystem
|
||||
|
||||
private lazy val statusLabel = new Label {
|
||||
maxWidth = Double.MaxValue
|
||||
padding = Insets(0, 10, 10, 10)
|
||||
|
@ -17,7 +20,7 @@ abstract class WalletGUI {
|
|||
}
|
||||
|
||||
def fetchStartingData(): Unit = {
|
||||
model.startBalanceThread()
|
||||
model.startWalletInfoScheduler()
|
||||
model.updateFeeRate()
|
||||
dlcPane.model.setUp()
|
||||
}
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
package org.bitcoins.gui
|
||||
|
||||
import akka.actor.{ActorSystem, Cancellable}
|
||||
import org.bitcoins.cli.CliCommand._
|
||||
import org.bitcoins.cli.ConsoleCli
|
||||
import org.bitcoins.core.currency.{Bitcoins, Satoshis}
|
||||
import org.bitcoins.core.protocol.BitcoinAddress
|
||||
import org.bitcoins.core.wallet.fee.FeeUnit
|
||||
import org.bitcoins.gui.dialog._
|
||||
import org.bitcoins.gui.dialog.{GetNewAddressDialog, SendDialog}
|
||||
import org.bitcoins.gui.util.GUIUtil
|
||||
import scalafx.application.Platform
|
||||
import scalafx.beans.property.{ObjectProperty, StringProperty}
|
||||
import scalafx.scene.control.Alert
|
||||
import scalafx.scene.control.Alert.AlertType
|
||||
import scalafx.stage.Window
|
||||
|
||||
import scala.concurrent.duration.DurationInt
|
||||
import scala.util.{Failure, Success, Try}
|
||||
|
||||
class WalletGUIModel() {
|
||||
class WalletGUIModel()(implicit system: ActorSystem) {
|
||||
var taskRunner: TaskRunner = _
|
||||
|
||||
// Sadly, it is a Java "pattern" to pass null into
|
||||
|
@ -23,23 +25,19 @@ class WalletGUIModel() {
|
|||
lazy val parentWindow: ObjectProperty[Window] =
|
||||
ObjectProperty[Window](null.asInstanceOf[Window])
|
||||
|
||||
private case object UpdateBalanceRunnable extends Runnable {
|
||||
private case object UpdateWalletInfoRunnable extends Runnable {
|
||||
|
||||
override def run(): Unit = {
|
||||
while (true) {
|
||||
Platform.runLater {
|
||||
updateBalance()
|
||||
// wait 10 seconds
|
||||
Thread.sleep(10000)
|
||||
}
|
||||
}
|
||||
}
|
||||
lazy val updateBalanceThread = new Thread(UpdateBalanceRunnable)
|
||||
|
||||
def startBalanceThread(): Unit = {
|
||||
updateBalanceThread.setDaemon(true)
|
||||
updateBalanceThread.setName(
|
||||
s"bitcoin-s-gui-balance-${System.currentTimeMillis()}")
|
||||
updateBalanceThread.start()
|
||||
def startWalletInfoScheduler(): Cancellable = {
|
||||
import system.dispatcher
|
||||
system.scheduler.scheduleAtFixedRate(0.seconds, 10.seconds)(
|
||||
UpdateWalletInfoRunnable)
|
||||
}
|
||||
|
||||
def updateFeeRate(): Try[FeeUnit] = {
|
||||
|
|
|
@ -408,7 +408,9 @@ object Deps {
|
|||
)
|
||||
}
|
||||
|
||||
val gui = List(Compile.breezeViz, Compile.scalaFx) ++ Compile.javaFxDeps
|
||||
val gui = List(Compile.akkaActor,
|
||||
Compile.breezeViz,
|
||||
Compile.scalaFx) ++ Compile.javaFxDeps
|
||||
|
||||
val server = Def.setting {
|
||||
List(
|
||||
|
|
Loading…
Add table
Reference in a new issue