Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build viewer
on:
pull_request:
push:
branches:
- main
- fix/tbs-sdk-1.0.8.6000124

jobs:
build-viewer:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v5
with:
distribution: corretto
java-version: '17'
- name: Build viewer
shell: bash
run: ./gradlew :viewer:assemble --stacktrace --console=plain
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {
}

val publishGroup = "io.github.vickyleu.documentviewer"
val publishVersion = "2.0.1"
val publishVersion = "2.0.2"
val publishRepo = "DocumentViewer"
val publishUrl = "https://github.com/vickyleu/$publishRepo"
val publishCoordinates = mapOf(
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Aug 23 04:29:59 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 6 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ dependencyResolutionManagement {
}
}


includeBuild("../ComposeFilePicker") {
dependencySubstitution {
substitute(module("com.vickyleu.kmp.filepicker:filepicker")).using(project(":filePicker"))
val composeFilePickerDir = file("../ComposeFilePicker")
if (composeFilePickerDir.isDirectory) {
includeBuild(composeFilePickerDir) {
dependencySubstitution {
substitute(module("io.github.vickyleu.filepicker:filepicker")).using(project(":filePicker"))
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions viewer/libs/TBS_FILE_SDK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tencent TbsFile SDK binary

This module expects the official Tencent Browsing Service document SDK binary:

- Version: `V1.0.8.6000124`
- Release date: `2026-08-06`
- Variant: comprehensive document formats, `64-bit + 32-bit`
- Expected file path: `viewer/src/androidMain/libs/TbsFileSdk.aar`
- Official SDK page: `https://cloud.tencent.com/document/product/1645/83899`
- Official binary URL at the time of this update: `https://tbs.imtt.qq.com/sdk/release/TbsFileSdk_base_universal_release_1.0.8.6000124.20260806101826.aar`

The repository currently contains an AAR at that path, but its binary version has not been verified/replaced through the source connector. Replace it on the local build machine with the official `V1.0.8.6000124` binary before validation and publication.

Before publishing `viewer`, verify the downloaded AAR came from the official Tencent host, record its SHA-256, run a clean Android build, and confirm a smoke-test document can be opened.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.uooc.document

import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.Settings
import android.util.Log
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -21,57 +19,62 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.viewinterop.AndroidView
import coil3.Uri
import com.github.jing332.filepicker.base.FileImpl
import com.tencent.tbs.reader.TbsFileInterfaceImpl
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.launch

private const val TAG = "DocumentPreviewer"

internal actual fun DocumentPreviewer.setupLicense(
license: String,
applicationContext: coil3.PlatformContext
applicationContext: coil3.PlatformContext,
) {
val ctx = applicationContext.applicationContext as Context
TbsFileInterfaceImpl.setLicenseKey(license)
TbsFileInterfaceImpl.fileEnginePreCheck(ctx)
//初始化Engine
val isInit = if(TbsFileInterfaceImpl.isEngineLoaded().not()){
TbsFileInterfaceImpl.initEngine(ctx)
}else {
DocumentPreviewer.TMResult.SUCCESS.code
}
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
// if(!Settings.System.canWrite(ctx)){
// val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
// intent.setData(android.net.Uri.parse("package:" + ctx.packageName))
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// ctx.startActivity(intent)
// }
// }
this.currentState = DocumentPreviewer.TMResult.fromCode(isInit)
println("TbsFileInterfaceImpl.initEngine: ${this.currentState.message}")
}
val initCode =
try {
if (license.isBlank()) {
DocumentPreviewer.TMResult.UNSET.code
} else {
TbsFileInterfaceImpl.setLicenseKey(license)
if (TbsFileInterfaceImpl.isEngineLoaded()) {
DocumentPreviewer.TMResult.SUCCESS.code
} else {
TbsFileInterfaceImpl.initEngine(ctx)
}
}
} catch (t: Throwable) {
Log.e(TAG, "TbsFile initEngine threw an exception for package=${ctx.packageName}", t)
DocumentPreviewer.TMResult.UNKNOWN.code
}

this.currentInitCode = initCode
this.currentState = DocumentPreviewer.TMResult.fromCode(initCode)
Log.i(
TAG,
"TbsFile initEngine package=${ctx.packageName}, code=$initCode, " +
"state=${this.currentState.name}, engineLoaded=${runCatching { TbsFileInterfaceImpl.isEngineLoaded() }.getOrDefault(false)}",
)
}

@Composable
internal actual fun DocumentPreviewer.documentView(
document: FileImpl,
callback: (Boolean, String) -> Unit
callback: (Boolean, String) -> Unit,
) {
val file = remember {
mutableStateOf(document)
}
val file = remember { mutableStateOf(document) }
val density = LocalDensity.current
val scope = rememberCoroutineScope()
BoxWithConstraints(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {

BoxWithConstraints(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center,
) {
val loadState = remember { mutableStateOf(false to "Loading document...") }
val documentView = remember { mutableStateOf<DocumentView?>(null) }

val documentView = remember {
mutableStateOf<DocumentView?>(null)
}
with(LocalDensity.current){
with(LocalDensity.current) {
Column(modifier = Modifier.fillMaxSize()) {
AndroidView(
factory = { context ->
Expand All @@ -81,56 +84,45 @@ internal actual fun DocumentPreviewer.documentView(
documentView.value = this
}
},
update = {

},
modifier = Modifier.fillMaxWidth()
.wrapContentHeight()

update = {},
modifier = Modifier.fillMaxWidth().wrapContentHeight(),
)
}
}

LaunchedEffect(documentView.value) {
if(documentView.value==null){
return@LaunchedEffect
}
val view = documentView.value ?: return@LaunchedEffect
scope.launch {
documentView.value?.setDocument(scope, file.value, density,this@documentView.currentState) { success, message ->
view.setDocument(scope, file.value, density, this@documentView.currentState) { success, message ->
loadState.value = success to message
}
}
}

DisposableEffect(documentView.value) {
if(documentView.value==null){
return@DisposableEffect onDispose { }
if (documentView.value == null) {
return@DisposableEffect onDispose {}
}
onDispose {
documentView.value?.dispose()
documentView.value = null
}
}

if (loadState.value.first.not()) {
if (!loadState.value.first) {
Text(
text = loadState.value.second.let {
if(it.contains("未设置 licenseKey")){
"tbs未充值,请联系管理员"
}else{
it
}
},
modifier = Modifier.align(Alignment.Center)
text = loadState.value.second,
modifier = Modifier.align(Alignment.Center),
)
}

LaunchedEffect(Unit) {
snapshotFlow { loadState.value }
.drop(1)
.distinctUntilChanged()
.collect{
callback(it.first,it.second)
.collect {
callback(it.first, it.second)
}
}

}
}
}
Loading
Loading