Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Update Coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerus committed Sep 13, 2018
1 parent 57c9043 commit 0f6798e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
8 changes: 3 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ repositories {
}

dependencies {
compile("com.github.Xerus2000", "util", "master-SNAPSHOT")
compile(kotlin("stdlib-jdk8"))
compile(kotlin("reflect"))

compile("com.github.Xerus2000.util", "javafx", "-SNAPSHOT")
compile("org.controlsfx", "controlsfx", "8.40.14")

compile("be.bluexin", "drpc4k", "0.6-SNAPSHOT")

compile("com.github.Bluexin", "drpc4k", "-SNAPSHOT")
compile("org.apache.httpcomponents", "httpmime", "4.5.5")
compile("com.google.apis", "google-api-services-sheets", "v4-rev527-1.23.0")

Expand Down Expand Up @@ -112,7 +110,7 @@ tasks {
setDelete(file(".").listFiles { f -> f.name.run { startsWith("MonsterUtilities-") && endsWith("jar") && this != file } })
}

"test"(Test::class) {
withType<Test> {
useJUnitPlatform()
}

Expand Down
2 changes: 1 addition & 1 deletion src/archive/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DownloaderSwing : BasePanel() {
}

init {
launch {
GlobalScope.launch {
logger.fine("DownloadWorker started")

var limit = LIMIT.int
Expand Down
8 changes: 3 additions & 5 deletions src/main/xerus/monstercat/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.services.sheets.v4.SheetsScopes
import javafx.scene.Scene
import javafx.scene.image.Image
import kotlinx.coroutines.experimental.asCoroutineDispatcher
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.*
import xerus.ktutil.*
import xerus.ktutil.javafx.applySkin
import xerus.ktutil.javafx.ui.App
Expand Down Expand Up @@ -44,7 +42,7 @@ fun main(args: Array<String>) {
try {
XerusLogger.logToFile(logfile)
logger.config("Logging to $logfile")
launch {
GlobalScope.launch {
val logs = logDir.listFiles()
if (logs.size > 10) {
logs.asSequence().sortedByDescending { it.name }.drop(5).filter {
Expand Down Expand Up @@ -82,7 +80,7 @@ fun main(args: Array<String>) {
}

fun showErrorSafe(error: Throwable, title: String = "Error") {
launch {
GlobalScope.launch {
var i = 0
while (i < 100 && !::monsterUtilities.isInitialized) {
delay(200)
Expand Down
7 changes: 4 additions & 3 deletions src/main/xerus/monstercat/MonsterUtilities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import javafx.scene.control.*
import javafx.scene.image.Image
import javafx.scene.image.ImageView
import javafx.scene.layout.VBox
import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.launch
import org.controlsfx.dialog.ExceptionDialog
import xerus.ktutil.*
Expand Down Expand Up @@ -42,7 +43,7 @@ class MonsterUtilities : VBox(), JFXMessageDisplay {

fun addTab(tabClass: KClass<out BaseTab>) {
try {
val baseTab = tabClass.java.newInstance()
val baseTab = tabClass.java.getDeclaredConstructor().newInstance()
logger.finer("New Tab: $baseTab")
tabs.add(baseTab)
val tab = Tab(baseTab.tabName, baseTab.asNode())
Expand All @@ -65,7 +66,7 @@ class MonsterUtilities : VBox(), JFXMessageDisplay {
showIntro()
Settings.LASTVERSION.put(VERSION)
} else {
launch {
GlobalScope.launch {
logger.fine("New version! Now running $VERSION, previously " + Settings.LASTVERSION())
val f = Settings.DELETE()
if (f.exists()) {
Expand Down Expand Up @@ -97,7 +98,7 @@ class MonsterUtilities : VBox(), JFXMessageDisplay {
inline fun <reified T : BaseTab> tabsByClass() = tabs.mapNotNull { it as? T }

fun checkForUpdate(userControlled: Boolean = false, unstable: Boolean = isUnstable) {
launch {
GlobalScope.launch {
try {
val latestVersion = URL("http://monsterutilities.bplaced.net/downloads/" + if (unstable) "unstable" else "latest").openConnection().getInputStream().reader().readLines().firstOrNull()
logger.fine("Latest version: $latestVersion")
Expand Down
3 changes: 2 additions & 1 deletion src/main/xerus/monstercat/api/DiscordRPC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package xerus.monstercat.api

import be.bluexin.drpc4k.jna.DiscordRichPresence
import be.bluexin.drpc4k.jna.RPCHandler
import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.launch
import xerus.ktutil.getResource
Expand All @@ -23,7 +24,7 @@ object DiscordRPC {
}

fun connect(delay: Int = 0) {
launch {
GlobalScope.launch {
delay(delay)
if (!RPCHandler.connected.get()) {
RPCHandler.onReady = {
Expand Down
7 changes: 4 additions & 3 deletions src/main/xerus/monstercat/api/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import javafx.scene.layout.VBox
import javafx.scene.media.Media
import javafx.scene.media.MediaPlayer
import javafx.util.Duration
import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.launch
import xerus.ktutil.javafx.*
Expand Down Expand Up @@ -91,7 +92,7 @@ object Player : FadingHBox(true, targetHeight = 25) {
/** hides the Player and appears again displaying the latest Release */
fun reset() {
fadeOut()
launch {
GlobalScope.launch {
val latest = Releases.getReleases().lastOrNull() ?: return@launch
while (fading) delay(50)
showText("Latest Release: $latest")
Expand Down Expand Up @@ -177,7 +178,7 @@ object Player : FadingHBox(true, targetHeight = 25) {

/** Finds the best match for the given [title] and [artists] and starts playing it */
fun play(title: String, artists: String) {
launch {
GlobalScope.launch {
showText("Searching for \"$title\"...")
disposePlayer()
val track = API.find(title, artists)
Expand All @@ -193,7 +194,7 @@ object Player : FadingHBox(true, targetHeight = 25) {
/** Plays this [release], creating an internal playlist when it has multiple Tracks */
fun play(release: Release) {
checkFx { showText("Searching for $release") }
launch {
GlobalScope.launch {
val results = APIConnection("catalog", "release", release.id, "tracks").getTracks()?.takeUnless { it.isEmpty() }
?: run {
showBack("No tracks found for Release $release")
Expand Down
3 changes: 2 additions & 1 deletion src/main/xerus/monstercat/downloader/SongViews.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xerus.monstercat.downloader

import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.launch
import xerus.ktutil.javafx.controlsfx.FilterableCheckTreeView
import xerus.ktutil.javafx.onFx
Expand Down Expand Up @@ -31,7 +32,7 @@ abstract class SongView<T : MusicItem>(root: T) : FilterableCheckTreeView<T>(roo
}

fun load() {
launch {
GlobalScope.launch {
fetchItems()
onFx {
onReady()
Expand Down
12 changes: 6 additions & 6 deletions src/main/xerus/monstercat/downloader/TabDownloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class TabDownloader : VTab() {
.also {
it.selectedProperty().listen {
if (it) {
launch {
GlobalScope.launch {
awaitReady()
releaseView.roots.forEach {
it.value.internalChildren.removeIf {
Expand All @@ -218,7 +218,7 @@ class TabDownloader : VTab() {
releaseView.root.internalChildren.clear()
releaseView.roots.clear()
trackView.root.internalChildren.clear()
launch {
GlobalScope.launch {
releaseView.load()
trackView.load()
}
Expand All @@ -236,7 +236,7 @@ class TabDownloader : VTab() {
val dont = arrayOf("Album", "EP", "Single")
val deferred = (albums.flatMap { it.children } + releaseView.roots.filterNot { it.value.value.title in dont }.flatMap { it.value.internalChildren }.filterNot { it.value.isMulti })
.map {
async(context) {
GlobalScope.async(context) {
if (!isActive) return@async null
APIConnection("catalog", "release", it.value.id, "tracks").getTracks()?.map { it.toString().normalised }
}
Expand Down Expand Up @@ -284,7 +284,7 @@ class TabDownloader : VTab() {

private fun refreshDownloadButton(button: Button) {
button.text = "Checking..."
launch {
GlobalScope.launch {
var valid = false
val text = when (APIConnection.checkCookie()) {
CookieValidity.NOCONNECTION -> "No connection"
Expand Down Expand Up @@ -359,7 +359,7 @@ class TabDownloader : VTab() {
if (done == total)
progressLabel.text = "$done / $total Errors: $e"
else
counter = launch {
counter = GlobalScope.launch {
val estimate = ((estimatedLength / lengths.sum() + total / done - 2) * timer.time() / 1000).roundToLong()
time = if (time > 0) (time * 9 + estimate) / 10 else estimate
logger.finest("Estimate: ${formatTimeDynamic(estimate, estimate.coerceAtLeast(60))} Weighed: ${formatTimeDynamic(time, time.coerceAtLeast(60))}")
Expand Down Expand Up @@ -398,7 +398,7 @@ class TabDownloader : VTab() {
private val success = SimpleIntegerProperty()
private val errors = SimpleIntegerProperty()
private fun startDownload() {
downloader = launch {
downloader = GlobalScope.launch {
log("Download started")
for (item in items) {
val download = item.downloadTask()
Expand Down

0 comments on commit 0f6798e

Please sign in to comment.