feat: add app update checks and standalone release publishing panel

This commit is contained in:
Codex
2026-10-24 13:50:42 +08:00
parent 437ed14dbe
commit 75e0b5587d
27 changed files with 1566 additions and 7 deletions
@@ -9,6 +9,7 @@ class MainActivity : FlutterActivity() {
private var calendar: CalendarBridge? = null
private var reminders: ReminderSystemBridge? = null
private var schoolDocuments: SchoolDocumentBridge? = null
private var updateBrowser: UpdateBrowserBridge? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
@@ -23,10 +24,14 @@ class MainActivity : FlutterActivity() {
reminders = ReminderSystemBridge(this, flutterEngine.dartExecutor.binaryMessenger)
schoolDocuments?.close()
schoolDocuments = SchoolDocumentBridge(flutterEngine)
updateBrowser?.close()
updateBrowser = UpdateBrowserBridge(this, flutterEngine.dartExecutor.binaryMessenger)
}
override fun cleanUpFlutterEngine(flutterEngine: FlutterEngine) {
schoolDocuments?.close()
schoolDocuments = null
updateBrowser?.close()
updateBrowser = null
super.cleanUpFlutterEngine(flutterEngine)
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
@@ -37,6 +42,7 @@ class MainActivity : FlutterActivity() {
calendar?.close()
reminders?.close()
schoolDocuments?.close()
updateBrowser?.close()
super.onDestroy()
}
}
@@ -0,0 +1,33 @@
package com.tpschedule.app
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodChannel
class UpdateBrowserBridge(private val activity: Activity, messenger: BinaryMessenger) {
private val channel = MethodChannel(messenger, "com.tpschedule.app/updates")
init {
channel.setMethodCallHandler { call, result ->
if (call.method != "openDownload") {
result.notImplemented()
} else {
val value = call.argument<String>("url")
val uri = value?.let { Uri.parse(it) }
if (value == null || value.length > 2048 || value.any { it.isWhitespace() || it.code < 32 } ||
uri?.scheme != "https" || uri.host.isNullOrBlank() || !uri.userInfo.isNullOrEmpty()) {
result.success(false)
} else {
try {
activity.startActivity(Intent(Intent.ACTION_VIEW, uri).addCategory(Intent.CATEGORY_BROWSABLE))
result.success(true)
} catch (_: ActivityNotFoundException) { result.success(false) }
catch (_: SecurityException) { result.success(false) }
}
}
}
}
fun close() { channel.setMethodCallHandler(null) }
}