Skip to content

Commit

Permalink
feat: 检测升级功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon406 committed Sep 5, 2021
1 parent be287a4 commit e264668
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 22 deletions.
4 changes: 3 additions & 1 deletion src/main/kotlin/me/leon/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package me.leon

const val VERSION = "1.6.0"
const val REPO_URL = "https://github.com/Leon406/ToolsFx"
const val PJ52_URL = "https://www.52pojie.cn/thread-1501153-1-1.html"
const val LAN_ZOU_DOWNLOAD_URL = "https://leon.lanzoui.com/b0d9av2kb"
const val CHECK_UPDATE_URL = "https://leon.lanzoui.com/b0d9av2kb"
const val CHECK_UPDATE_URL = "https://cdn.staticaly.com/gh/Leon406/ToolsFx/dev/current"
const val LICENSE = "https://cdn.staticaly.com/gh/Leon406/ToolsFx/main/LICENSE"
const val APP_NAME = "密码学工具箱 by Leon406 "
13 changes: 13 additions & 0 deletions src/main/kotlin/me/leon/ext/Prefs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.leon.ext

import java.util.prefs.Preferences

object Prefs {
private const val IGNORE_UPDATE = "isIgnoreUpdate"
private val preference = Preferences.userNodeForPackage(Prefs::class.java)
var isIgnoreUpdate
get() = preference.getBoolean(IGNORE_UPDATE, false)
set(value) {
preference.putBoolean(IGNORE_UPDATE, value)
}
}
2 changes: 2 additions & 0 deletions src/main/kotlin/me/leon/ext/Spacing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ const val DEFAULT_SPACING_3X = 24.0
const val DEFAULT_SPACING_4X = 32.0
const val DEFAULT_SPACING_8X = 64.0
const val DEFAULT_SPACING_20X = 160.0
const val DEFAULT_SPACING_40X = 320.0
const val DEFAULT_SPACING_80X = 640.0
2 changes: 1 addition & 1 deletion src/main/kotlin/me/leon/ext/Times.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

fun times() =
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_hh-mm-ss")) ?: "unknown"
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")) ?: "unknown"
42 changes: 29 additions & 13 deletions src/main/kotlin/me/leon/view/AboutView.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
package me.leon.view

import javafx.beans.property.SimpleBooleanProperty
import javafx.geometry.Pos
import javafx.scene.image.Image
import javafx.scene.text.Font
import me.leon.CHECK_UPDATE_URL
import me.leon.LAN_ZOU_DOWNLOAD_URL
import me.leon.REPO_URL
import me.leon.VERSION
import me.leon.ext.DEFAULT_SPACING
import me.leon.ext.openInBrowser
import me.leon.ext.readFromNet
import javafx.scene.text.Text
import me.leon.*
import me.leon.ext.*
import tornadofx.*

class AboutView : View("关于") {

override val closeable = SimpleBooleanProperty(false)
lateinit var latestVersion: Text

override val root = vbox {
alignment = Pos.TOP_CENTER
spacing = DEFAULT_SPACING
paddingAll = DEFAULT_SPACING
imageview(Image("/tb.png"))
text("版本 v$VERSION") { font = Font.font(18.0) }
hyperlink("github地址") { action { REPO_URL.openInBrowser() } }
text("构建时间 ${times()}")
hyperlink("吾爱破解地址") { action { PJ52_URL.openInBrowser() } }
hyperlink("github开源地址") {
font = Font.font(18.0)
action { REPO_URL.openInBrowser() }
}
hyperlink("开源协议 ISC") { action { LICENSE.openInBrowser() } }
button("检测新版本") { action { checkUpdate() } }
latestVersion = text()
hyperlink("蓝奏云下载 密码52pj") { action { LAN_ZOU_DOWNLOAD_URL.openInBrowser() } }
button("检测新版本") {
action {
CHECK_UPDATE_URL.readFromNet()
find<MyFragment>().openModal()
checkUpdate(!Prefs.isIgnoreUpdate)
}

private fun checkUpdate(isAuto: Boolean = true) {
if (!isAuto) return
runAsync { CHECK_UPDATE_URL.readFromNet() } ui
{
latestVersion.text =
if (it.isEmpty()) "未知错误"
else if (VERSION != it)
"发现新版本 v$it".also { find<UpdateFragment>().openModal() }
else "已是最新版本"
}
}
}
}
7 changes: 0 additions & 7 deletions src/main/kotlin/me/leon/view/MyFragment.kt

This file was deleted.

25 changes: 25 additions & 0 deletions src/main/kotlin/me/leon/view/UpdateFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.leon.view

import javafx.geometry.Pos
import me.leon.REPO_URL
import me.leon.ext.*
import tornadofx.*

class UpdateFragment : Fragment("检测到新版本") {
override val root = hbox {
prefWidth = DEFAULT_SPACING_40X
prefHeight = DEFAULT_SPACING_20X
paddingAll = DEFAULT_SPACING
spacing = DEFAULT_SPACING_2X
alignment = Pos.CENTER

button("马上升级") { action { action { REPO_URL.openInBrowser() } } }
button("忽略本次") { action { close() } }
button("永久忽略") {
action {
Prefs.isIgnoreUpdate = true
close()
}
}
}
}

0 comments on commit e264668

Please sign in to comment.