Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
fix proxy settings; change core updating way
Browse files Browse the repository at this point in the history
Former-commit-id: f860b2cd25de2ece679a7f47b5509dccfe449ec7 [formerly 5431348]
Former-commit-id: f189ae041fcbfbbe11d0a9a17f8a5b046bd3b59a
  • Loading branch information
ingbyr committed Sep 26, 2017
1 parent 1275118 commit cfa328e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.ingbyr.guiyouget.controllers

import com.ingbyr.guiyouget.core.OkHttpController
import com.ingbyr.guiyouget.events.RequestCheckUpdatesYouGet
import com.ingbyr.guiyouget.events.RequestCheckUpdatesYoutubeDL
import com.ingbyr.guiyouget.events.UpdateStates
import com.ingbyr.guiyouget.events.*
import com.ingbyr.guiyouget.utils.CoreUtils
import org.slf4j.LoggerFactory
import tornadofx.*
Expand All @@ -15,7 +13,7 @@ class UpdatesController : Controller() {

fun subscribeEvents() {
subscribe<RequestCheckUpdatesYouGet> {
fire(UpdateStates("Check for updates of you-get"))
fire(UpdateYouGetStates("[you-get] Check for updates..."))
val remoteJson = okhttp.requestJson(CoreUtils.REMOTE_CONF_URL)
if (remoteJson != null) {
val youget = remoteJson["youget"] as String
Expand All @@ -27,7 +25,7 @@ class UpdatesController : Controller() {
}

subscribe<RequestCheckUpdatesYoutubeDL> {
fire(UpdateStates("Check for updates of youtube-dl"))
fire(UpdateYoutubeDLStates("[youtube-dl] Check for updates..."))
val remoteJson = okhttp.requestJson(CoreUtils.REMOTE_CONF_URL)
if (remoteJson != null) {
val youtubedl = remoteJson["youtubedl"] as String
Expand All @@ -49,14 +47,15 @@ class UpdatesController : Controller() {
logger.debug("[you-get] remote version is $remoteVersion, local version is $localVersion")
if (remoteVersion > localVersion) {
// do updates
fire(UpdateStates("New version $remoteVersion of you-get, downloading..."))
fire(UpdateYouGetStates("[you-get] New version $remoteVersion downloading..."))
val url = CoreUtils.yougetUpdateURL(remoteVersion)
logger.debug("[you-get] update url $url")
okhttp.downloadFile(url,
Paths.get(System.getProperty("user.dir"), "core", "you-get.exe").toFile(),
CoreUtils.YOU_GET_VERSION,
remoteVersion)
} else {
fire(UpdateYouGetStates("[you-get] No updates"))
logger.debug("[you-get] no updates")
}
}
Expand All @@ -65,14 +64,15 @@ class UpdatesController : Controller() {
logger.debug("[youtube-dl] remote version is $remoteVersion, local version is $localVersion")
if (remoteVersion > localVersion) {
// do updates
fire(UpdateStates("New version $remoteVersion of youtube-dl, downloading..."))
fire(UpdateYoutubeDLStates("[youtube-dl] New version $remoteVersion downloading..."))
val url = CoreUtils.youtubedlUpdateURL(remoteVersion)
logger.debug("[youtube-dl] update url $url")
okhttp.downloadFile(url,
Paths.get(System.getProperty("user.dir"), "core", "youtube-dl.exe").toFile(),
CoreUtils.YOUTUBE_DL_VERSION,
remoteVersion)
} else {
fire(UpdateYoutubeDLStates("[youtube-dl]No updates"))
logger.debug("[youtube-dl] no updates")
}
}
Expand Down
23 changes: 20 additions & 3 deletions src/main/kotlin/com/ingbyr/guiyouget/core/OkHttpController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.ingbyr.guiyouget.core

import com.beust.klaxon.JsonObject
import com.beust.klaxon.Parser
import com.ingbyr.guiyouget.events.UpdateStates
import com.ingbyr.guiyouget.events.UpdateYouGetStates
import com.ingbyr.guiyouget.events.UpdateYoutubeDLStates
import com.ingbyr.guiyouget.utils.CoreUtils
import okhttp3.*
import org.slf4j.LoggerFactory
import tornadofx.*
Expand Down Expand Up @@ -49,7 +51,14 @@ class DownloadFileCallBack(private val file: File, private val k: String?, priva
private val logger = LoggerFactory.getLogger(this::class.java)

override fun onFailure(call: Call?, e: IOException?) {
fire(UpdateStates("Updating failed"))
when (k) {
CoreUtils.YOUTUBE_DL_VERSION -> {
fire(UpdateYoutubeDLStates("[youtube-dl] Fail to update"))
}
CoreUtils.YOU_GET_VERSION -> {
fire(UpdateYouGetStates("[you-get] Fail to update"))
}
}
logger.error(e.toString())
}

Expand Down Expand Up @@ -83,7 +92,15 @@ class DownloadFileCallBack(private val file: File, private val k: String?, priva
logger.error(e.toString())

}
fire(UpdateStates("Complete updates"))

when (k) {
CoreUtils.YOUTUBE_DL_VERSION -> {
fire(UpdateYoutubeDLStates("[youtube-dl] Updating completed"))
}
CoreUtils.YOU_GET_VERSION -> {
fire(UpdateYouGetStates("[you-get] Updating completed"))
}
}
// Update config of APP
if (k != null && v != null) {
app.config[k] = v
Expand Down
8 changes: 2 additions & 6 deletions src/main/kotlin/com/ingbyr/guiyouget/events/UpdatesEvents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ package com.ingbyr.guiyouget.events

import tornadofx.*

// common event
class UpdateStates(val status: String) : FXEvent()

// you-get updates
object RequestCheckUpdatesYouGet : FXEvent(EventBus.RunOn.BackgroundThread)

object UpdateYouGet : FXEvent(EventBus.RunOn.BackgroundThread)
class UpdateYouGetStates(val status: String) : FXEvent()

// you-get updates
object RequestCheckUpdatesYoutubeDL : FXEvent(EventBus.RunOn.BackgroundThread)

object UpdateYoutubeDL : FXEvent(EventBus.RunOn.BackgroundThread)

class UpdateYoutubeDLStates(val status: String) : FXEvent()
38 changes: 31 additions & 7 deletions src/main/kotlin/com/ingbyr/guiyouget/views/MainView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class MainView : View("GUI-YouGet") {
}

// Storage path
if (app.config["storagePath"] == null) {
if (app.config["storagePath"] == null || app.config["storagePath"] == "") {
labelStoragePath.text = Paths.get(System.getProperty("user.dir")).toAbsolutePath().toString()
app.config["storagePath"] = labelStoragePath.text
app.config.save()
Expand Down Expand Up @@ -176,6 +176,34 @@ class MainView : View("GUI-YouGet") {
}
}

tfSocksAddress.textProperty().addListener { _, _, newValue ->
if (app.config[CoreUtils.PROXY_TYPE] == CoreUtils.PROXY_SOCKS) {
app.config[CoreUtils.PROXY_ADDRESS] = newValue
app.config.save()
}
}

tfSocksPort.textProperty().addListener { _, _, newValue ->
if (app.config[CoreUtils.PROXY_TYPE] == CoreUtils.PROXY_SOCKS) {
app.config[CoreUtils.PROXY_PORT] = newValue
app.config.save()
}
}

tfHTTPAddress.textProperty().addListener { _, _, newValue ->
if (app.config[CoreUtils.PROXY_TYPE] == CoreUtils.PROXY_HTTP) {
app.config[CoreUtils.PROXY_ADDRESS] = newValue
app.config.save()
}
}

tfHTTPPort.textProperty().addListener { _, _, newValue ->
if (app.config[CoreUtils.PROXY_TYPE] == CoreUtils.PROXY_HTTP) {
app.config[CoreUtils.PROXY_PORT] = newValue
app.config.save()
}
}

cbSocks5.action {
val address = tfSocksAddress.text
val port = tfSocksPort.text
Expand All @@ -186,14 +214,12 @@ class MainView : View("GUI-YouGet") {
}

// Enable socks proxy
if (cbSocks5.isSelected && address.trim() != "" && port.trim() != "") {
if (cbSocks5.isSelected) {
cbHTTP.isSelected = false
app.config[CoreUtils.PROXY_TYPE] = CoreUtils.PROXY_SOCKS
app.config[CoreUtils.PROXY_ADDRESS] = address
app.config[CoreUtils.PROXY_PORT] = port
app.config.save()
} else {
cbSocks5.isSelected = false
}
}

Expand All @@ -207,14 +233,12 @@ class MainView : View("GUI-YouGet") {
}

// Enable http proxy
if (cbHTTP.isSelected && address.trim() != "" && port.trim() != "") {
if (cbHTTP.isSelected) {
cbSocks5.isSelected = false
app.config[CoreUtils.PROXY_TYPE] = CoreUtils.PROXY_HTTP
app.config[CoreUtils.PROXY_ADDRESS] = address
app.config[CoreUtils.PROXY_PORT] = port
app.config.save()
} else {
cbHTTP.isSelected = false
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/main/kotlin/com/ingbyr/guiyouget/views/UpdatesWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.ingbyr.guiyouget.views

import com.ingbyr.guiyouget.controllers.UpdatesController
import com.ingbyr.guiyouget.events.StopDownloading
import com.ingbyr.guiyouget.events.UpdateStates
import com.ingbyr.guiyouget.events.UpdateYouGetStates
import com.ingbyr.guiyouget.events.UpdateYoutubeDLStates
import javafx.scene.control.Label
import javafx.scene.layout.AnchorPane
import javafx.scene.layout.Pane
Expand All @@ -12,7 +13,8 @@ class UpdatesWindow : View() {
val controller: UpdatesController by inject()
override val root: AnchorPane by fxml("/fxml/UpdatesWindow.fxml")

private val labelStatus: Label by fxid()
private val labelYouget: Label by fxid()
private val labelYoutubedl: Label by fxid()
private val paneExit: Pane by fxid()

init {
Expand All @@ -23,8 +25,12 @@ class UpdatesWindow : View() {
this.close()
}

subscribe<UpdateStates> {
labelStatus.text = it.status
subscribe<UpdateYouGetStates> {
labelYouget.text = it.status
}

subscribe<UpdateYoutubeDLStates> {
labelYoutubedl.text = it.status
}
}
}
26 changes: 13 additions & 13 deletions src/main/resources/fxml/MediaListWindow.fxml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.shape.*?>
<?import com.jfoenix.controls.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import com.jfoenix.controls.JFXListView?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.shape.SVGPath?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="550.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane prefHeight="550.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1">
<children>
<AnchorPane fx:id="apBorder" prefHeight="30.0" prefWidth="550.0" style="-fx-background-color: #303f9f;" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
Expand All @@ -21,18 +21,13 @@
<javafx.scene.shape.SVGPath content="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" fill="white" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0" />
</children>
</Pane>
<Pane fx:id="paneBack" layoutX="135.0" layoutY="9.0" AnchorPane.rightAnchor="40.0" AnchorPane.topAnchor="5.0">
<children>
<javafx.scene.shape.SVGPath content="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z" fill="white" />
</children>
</Pane>
</children>
</AnchorPane>
<AnchorPane prefWidth="550.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="30.0">
<children>
<AnchorPane prefHeight="100.0" prefWidth="600.0" style="-fx-background-color: #3f51b5;" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label fx:id="labelTitle" layoutX="25.0" layoutY="29.0" text="Loading..." textFill="WHITE" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="20.0">
<Label fx:id="labelTitle" layoutX="25.0" layoutY="29.0" text="Loading..." textFill="WHITE" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="70.0" AnchorPane.topAnchor="20.0">
<font>
<Font name="System Bold" size="18.0" />
</font>
Expand All @@ -42,6 +37,11 @@
<Font size="14.0" />
</font>
</Label>
<Pane fx:id="paneBack" prefWidth="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="30.0">
<children>
<javafx.scene.shape.SVGPath content="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z" fill="white" scaleX="1.5" scaleY="1.5" />
</children>
</Pane>
</children>
</AnchorPane>
<JFXListView fx:id="listViewMedia" layoutY="100.0" prefHeight="400.0" prefWidth="600.0" stylesheets="@../css/ui.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="100.0" />
Expand Down
9 changes: 6 additions & 3 deletions src/main/resources/fxml/UpdatesWindow.fxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXProgressBar?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
Expand All @@ -25,12 +24,16 @@
</AnchorPane>
<AnchorPane prefHeight="140.0" prefWidth="550.0" style="-fx-background-color: #3f51b5;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="30.0">
<children>
<Label fx:id="labelStatus" layoutX="10.0" layoutY="20.0" prefWidth="410.0" text="Analyzing..." textFill="WHITE" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="20.0">
<Label fx:id="labelYouget" layoutX="10.0" layoutY="20.0" prefWidth="410.0" text="Analyzing..." textFill="WHITE" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="20.0">
<font>
<Font size="14.0" />
</font>
</Label>
<Label fx:id="labelYoutubedl" layoutX="20.0" layoutY="30.0" prefWidth="410.0" text="Analyzing..." textFill="WHITE" AnchorPane.topAnchor="60.0">
<font>
<Font size="14.0" />
</font>
</Label>
<JFXProgressBar fx:id="progressbar" layoutX="81.0" layoutY="70.0" prefHeight="10.0" stylesheets="@../css/ui.css" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="80.0" />
</children>
</AnchorPane>
</children>
Expand Down

0 comments on commit cfa328e

Please sign in to comment.