-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add "server" to "checkForUpdate" logic names * Use "webUIRoot" as default path for "getLocalVersion" * Use local version as default version for "isUpdateAvailable" * Return the version with the webUI update check * Update WebinterfaceManager to be async * Add query, mutation and subscription for webUI update * Catch error and return default error value for missing local WebUI version
- Loading branch information
Showing
7 changed files
with
305 additions
and
58 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/InfoMutation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package suwayomi.tachidesk.graphql.mutations | ||
|
||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.withTimeout | ||
import suwayomi.tachidesk.graphql.types.UpdateState.DOWNLOADING | ||
import suwayomi.tachidesk.graphql.types.UpdateState.FINISHED | ||
import suwayomi.tachidesk.graphql.types.UpdateState.STOPPED | ||
import suwayomi.tachidesk.graphql.types.WebUIUpdateInfo | ||
import suwayomi.tachidesk.graphql.types.WebUIUpdateStatus | ||
import suwayomi.tachidesk.server.JavalinSetup.future | ||
import suwayomi.tachidesk.server.serverConfig | ||
import suwayomi.tachidesk.server.util.WebInterfaceManager | ||
import java.util.concurrent.CompletableFuture | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
class InfoMutation { | ||
data class WebUIUpdateInput( | ||
val clientMutationId: String? = null | ||
) | ||
|
||
data class WebUIUpdatePayload( | ||
val clientMutationId: String?, | ||
val updateStatus: WebUIUpdateStatus | ||
) | ||
|
||
fun updateWebUI(input: WebUIUpdateInput): CompletableFuture<WebUIUpdatePayload> { | ||
return future { | ||
withTimeout(30.seconds) { | ||
if (WebInterfaceManager.status.value.state === DOWNLOADING) { | ||
return@withTimeout WebUIUpdatePayload(input.clientMutationId, WebInterfaceManager.status.value) | ||
} | ||
|
||
val (version, updateAvailable) = WebInterfaceManager.isUpdateAvailable() | ||
|
||
if (!updateAvailable) { | ||
return@withTimeout WebUIUpdatePayload( | ||
input.clientMutationId, | ||
WebUIUpdateStatus( | ||
info = WebUIUpdateInfo( | ||
channel = serverConfig.webUIChannel, | ||
tag = version, | ||
updateAvailable | ||
), | ||
state = STOPPED, | ||
progress = 0 | ||
) | ||
) | ||
} | ||
try { | ||
WebInterfaceManager.startDownloadInScope(version) | ||
} catch (e: Exception) { | ||
// ignore since we use the status anyway | ||
} | ||
|
||
WebUIUpdatePayload( | ||
input.clientMutationId, | ||
updateStatus = WebInterfaceManager.status.first { it.state == DOWNLOADING } | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
server/src/main/kotlin/suwayomi/tachidesk/graphql/subscriptions/InfoSubscription.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package suwayomi.tachidesk.graphql.subscriptions | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import suwayomi.tachidesk.graphql.types.WebUIUpdateStatus | ||
import suwayomi.tachidesk.server.util.WebInterfaceManager | ||
|
||
class InfoSubscription { | ||
fun webUIUpdateStatusChange(): Flow<WebUIUpdateStatus> { | ||
return WebInterfaceManager.status | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
server/src/main/kotlin/suwayomi/tachidesk/graphql/types/WebUIUpdateType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package suwayomi.tachidesk.graphql.types | ||
|
||
data class WebUIUpdateInfo( | ||
val channel: String, | ||
val tag: String, | ||
val updateAvailable: Boolean | ||
) | ||
|
||
enum class UpdateState { | ||
STOPPED, | ||
DOWNLOADING, | ||
FINISHED, | ||
ERROR | ||
} | ||
|
||
data class WebUIUpdateStatus( | ||
val info: WebUIUpdateInfo, | ||
val state: UpdateState, | ||
val progress: Int | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.