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

Commit 39d64f2

Browse files
author
Xerus
committed
fix(settings): refactor & standardise App restart
1 parent 9de806d commit 39d64f2

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/main/xerus/monstercat/tabs/TabSettings.kt

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import xerus.monstercat.api.response.Release.Type.MCOLLECTION
3838
import xerus.monstercat.api.response.Release.Type.MIX
3939
import xerus.monstercat.api.response.Release.Type.PODCAST
4040
import xerus.monstercat.api.response.Release.Type.SINGLE
41+
import xerus.monstercat.api.Player
4142
import xerus.monstercat.cacheDir
4243
import xerus.monstercat.dataDir
4344
import xerus.monstercat.downloader.DownloaderSettings
@@ -105,33 +106,21 @@ class TabSettings: VTab() {
105106
val buttonWidth = 160.0
106107
addRow(
107108
createButton("Quick Restart") {
108-
Settings.refresh()
109-
DownloaderSettings.refresh()
110-
App.restart()
109+
restartApp()
111110
}.apply { prefWidth = buttonWidth },
112111
createButton("Clear cache & Restart") {
113-
Settings.refresh()
114-
DownloaderSettings.refresh()
115-
try {
116-
Cache.clear()
117-
App.restart()
118-
} catch(e: Exception) {
119-
monsterUtilities.showError(e)
120-
}
112+
Cache.clear()
113+
restartApp()
121114
}.apply { prefWidth = buttonWidth },
122115
createButton("Reset") {
123116
App.stage.createAlert(Alert.AlertType.WARNING, content = "Are you sure you want to RESET ALL SETTINGS?", buttons = *arrayOf(ButtonType.YES, ButtonType.CANCEL)).apply {
124117
initStyle(StageStyle.UTILITY)
125118
resultProperty().listen {
126119
if(it.buttonData == ButtonBar.ButtonData.YES) {
127-
try {
128-
Settings.clear()
129-
DownloaderSettings.clear()
130-
Cache.clear()
131-
} catch(e: Exception) {
132-
monsterUtilities.showError(e)
133-
}
134-
App.restart()
120+
Settings.clear()
121+
DownloaderSettings.clear()
122+
Cache.clear()
123+
restartApp()
135124
}
136125
}
137126
show()
@@ -143,6 +132,15 @@ class TabSettings: VTab() {
143132
)
144133
}
145134

135+
/** Restarts the application. */
136+
private fun restartApp() {
137+
Player.fadeOut()
138+
Settings.refresh()
139+
DownloaderSettings.refresh()
140+
App.restart()
141+
Player.reset()
142+
}
143+
146144
fun feedback() {
147145
val dialog = Dialog<Feedback>().apply {
148146
(dialogPane.scene.window as Stage).initWindowOwner(App.stage)

0 commit comments

Comments
 (0)