Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e7e0c13386 | |||
|
eaf3f61ebd |
24 changed files with 498 additions and 564 deletions
|
|
@ -14,7 +14,7 @@
|
|||
}
|
||||
},
|
||||
"scripts": {
|
||||
"dev:mobile:raw": "tauri android dev --host ${TAURI_DEV_HOST:-127.0.0.1}",
|
||||
"dev:mobile:raw": "adb reverse tcp:3000 tcp:3000 && tauri android dev --host ${TAURI_DEV_HOST:-127.0.0.1}",
|
||||
"start-adb:mobile:raw": "adb devices",
|
||||
"build:mobile:raw": "tauri android build",
|
||||
"build:mobile:ci": "node render-version.ts && trap 'node render-version.ts --unrender' EXIT && tauri android build --debug",
|
||||
|
|
|
|||
557
apps/tauri/src-tauri/Cargo.lock
generated
557
apps/tauri/src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -15,14 +15,14 @@ name = "mobile_lib"
|
|||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { git = "https://github.com/tauri-apps/tauri", rev = "e2e585ad1196c9572f86ef39aae01ef4c3b1a762", features = [] }
|
||||
tauri-build = { git = "https://github.com/tauri-apps/tauri", rev = "4af26a3f7f8b692d62cca549bbacd93f5ce90b41", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
base64 = "0.22"
|
||||
reqwest = { version = "0.13", default-features = false, features = ["json", "rustls-tls"] }
|
||||
reqwest = { version = "0.13", default-features = false, features = ["json", "rustls"] }
|
||||
tokio = { version = "1", features = ["rt-multi-thread", "sync", "time"] }
|
||||
mtp = { git = "https://git.methanium.net/methanium/mtp.git", rev = "b067614a684eb1856bc5db7b3fd82148c036ce6b", features = ["client", "crypto"] }
|
||||
mtp-transport = { git = "https://git.methanium.net/methanium/mtp.git", rev = "b067614a684eb1856bc5db7b3fd82148c036ce6b" }
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
{
|
||||
"identifier": "mobile-capability",
|
||||
"platforms": [
|
||||
"android",
|
||||
"iOS"
|
||||
],
|
||||
"windows": [
|
||||
"main"
|
||||
],
|
||||
"platforms": ["android", "iOS"],
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:event:default",
|
||||
"deep-link:default",
|
||||
"barcode-scanner:default",
|
||||
"barcode-scanner:allow-scan",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import java.util.Properties
|
||||
import java.io.FileInputStream
|
||||
|
||||
|
|
@ -61,14 +62,17 @@ android {
|
|||
)
|
||||
}
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
buildFeatures {
|
||||
buildConfig = true
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget = JvmTarget.JVM_1_8
|
||||
}
|
||||
}
|
||||
|
||||
rust {
|
||||
rootDirRel = "../../../"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,8 @@ package net.tensamin.client
|
|||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Rect
|
||||
import android.media.projection.MediaProjectionManager
|
||||
import android.os.Bundle
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewTreeObserver
|
||||
import android.view.WindowManager
|
||||
import android.webkit.JavascriptInterface
|
||||
|
|
@ -56,7 +54,7 @@ class MainActivity : TauriActivity() {
|
|||
}
|
||||
|
||||
override fun onWebViewCreate(webView: WebView) {
|
||||
webView.setInitialScale(290)
|
||||
NativeAccessibilityBridge.attach(webView)
|
||||
mediaWebView = webView
|
||||
MobileMediaEvents.attach(webView)
|
||||
webView.addJavascriptInterface(MobileMediaJavascriptInterface(), "tensaminMobileMedia")
|
||||
|
|
@ -65,11 +63,12 @@ class MainActivity : TauriActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, true)
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING)
|
||||
super.onCreate(savedInstanceState)
|
||||
NativeMtpBridge.nativeAttach(applicationContext)
|
||||
if (MtpSecureStore.isEnabled(this) && MtpSecureStore.hasConfig(this)) {
|
||||
NativeMtpBridge.startService(this)
|
||||
}
|
||||
super.onCreate(savedInstanceState)
|
||||
NativeMtpBridge.nativeAttach(applicationContext)
|
||||
NativeAccessibilityBridge.nativeAttach(applicationContext)
|
||||
installKeyboardResizeWorkaround()
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +89,10 @@ class MainActivity : TauriActivity() {
|
|||
attachLayoutListener = null
|
||||
contentRoot = null
|
||||
contentChild = null
|
||||
mediaWebView?.removeJavascriptInterface("tensaminMobileMedia")
|
||||
mediaWebView?.let {
|
||||
NativeAccessibilityBridge.detach(it)
|
||||
it.removeJavascriptInterface("tensaminMobileMedia")
|
||||
}
|
||||
mediaWebView = null
|
||||
MobileMediaEvents.detach()
|
||||
super.onDestroy()
|
||||
|
|
@ -203,16 +205,20 @@ class MainActivity : TauriActivity() {
|
|||
child: android.view.View,
|
||||
insets: WindowInsetsCompat? = ViewCompat.getRootWindowInsets(child),
|
||||
) {
|
||||
val visibleFrame = Rect()
|
||||
child.getWindowVisibleDisplayFrame(visibleFrame)
|
||||
|
||||
val rootHeight = child.rootView.height
|
||||
if (rootHeight <= 0) return
|
||||
|
||||
val imeHeight = insets?.getInsets(WindowInsetsCompat.Type.ime())?.bottom ?: 0
|
||||
val keyboardHeight = maxOf(imeHeight, rootHeight - visibleFrame.bottom)
|
||||
val keyboardVisible = keyboardHeight > rootHeight * 0.15
|
||||
val usableHeight = if (keyboardVisible) rootHeight - keyboardHeight else ViewGroup.LayoutParams.MATCH_PARENT
|
||||
val imeVisible = insets?.isVisible(WindowInsetsCompat.Type.ime()) == true
|
||||
val imeHeight = if (imeVisible) {
|
||||
insets.getInsets(WindowInsetsCompat.Type.ime()).bottom
|
||||
} else {
|
||||
0
|
||||
}
|
||||
val usableHeight = if (imeHeight in 1 until rootHeight) {
|
||||
rootHeight - imeHeight
|
||||
} else {
|
||||
WindowManager.LayoutParams.MATCH_PARENT
|
||||
}
|
||||
|
||||
if (previousUsableHeight == usableHeight) return
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import android.os.HandlerThread
|
|||
import android.os.IBinder
|
||||
import android.util.Base64
|
||||
import android.util.DisplayMetrics
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
|
@ -107,16 +108,12 @@ class MediaProjectionService : Service() {
|
|||
stopIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
|
||||
)
|
||||
val notification = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
android.app.Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
} else {
|
||||
android.app.Notification.Builder(this)
|
||||
}
|
||||
val notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||
.setSmallIcon(android.R.drawable.ic_menu_share)
|
||||
.setContentTitle("Tensamin is sharing your screen")
|
||||
.setContentText("Tap Stop to end screen sharing")
|
||||
.setOngoing(true)
|
||||
.setCategory(android.app.Notification.CATEGORY_SERVICE)
|
||||
.setCategory(NotificationCompat.CATEGORY_SERVICE)
|
||||
.addAction(android.R.drawable.ic_media_pause, "Stop", stopPendingIntent)
|
||||
.build()
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import android.net.Network
|
|||
import android.net.NetworkCapabilities
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.os.Process
|
||||
import android.os.SystemClock
|
||||
import androidx.core.app.NotificationCompat
|
||||
|
||||
class MtpForegroundService : Service() {
|
||||
|
|
@ -74,10 +76,19 @@ class MtpForegroundService : Service() {
|
|||
}
|
||||
|
||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
val preferences = getSharedPreferences(SERVICE_PREFERENCES, Context.MODE_PRIVATE)
|
||||
val now = SystemClock.elapsedRealtime()
|
||||
if (now - preferences.getLong(LAST_TASK_RESTART, 0) < TASK_RESTART_COOLDOWN_MS) {
|
||||
super.onTaskRemoved(rootIntent)
|
||||
return
|
||||
}
|
||||
preferences.edit().putLong(LAST_TASK_RESTART, now).commit()
|
||||
if (MtpSecureStore.isEnabled(this) && MtpSecureStore.hasConfig(this)) {
|
||||
startService(Intent(this, MtpForegroundService::class.java))
|
||||
}
|
||||
super.onTaskRemoved(rootIntent)
|
||||
// Tauri cannot recreate its WebView after the UI task is removed while this process survives.
|
||||
Process.killProcess(Process.myPid())
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
|
@ -94,6 +105,9 @@ class MtpForegroundService : Service() {
|
|||
private const val CHANNEL_ID = "tensamin-connection"
|
||||
private const val NOTIFICATION_ID = 2201
|
||||
private const val ACTION_STOP = "net.tensamin.client.STOP_MTP"
|
||||
private const val SERVICE_PREFERENCES = "tensamin-service"
|
||||
private const val LAST_TASK_RESTART = "last-task-restart"
|
||||
private const val TASK_RESTART_COOLDOWN_MS = 15_000L
|
||||
@Volatile private var connectionStatus = "Connecting"
|
||||
|
||||
fun updateNotification(context: Context, status: String) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
package net.tensamin.client
|
||||
|
||||
import android.content.Context
|
||||
import android.webkit.WebView
|
||||
import androidx.annotation.Keep
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
@Keep
|
||||
object NativeAccessibilityBridge {
|
||||
const val DEFAULT_INITIAL_SCALE = 290
|
||||
private const val MIN_INITIAL_SCALE = 210
|
||||
private const val MAX_INITIAL_SCALE = 500
|
||||
private const val PREFERENCES = "tensamin-accessibility"
|
||||
private const val INITIAL_SCALE = "initial-scale"
|
||||
|
||||
private var webView = WeakReference<WebView>(null)
|
||||
|
||||
init {
|
||||
System.loadLibrary("mobile_lib")
|
||||
}
|
||||
|
||||
@JvmStatic external fun nativeAttach(context: Context)
|
||||
|
||||
fun attach(webView: WebView) {
|
||||
this.webView = WeakReference(webView)
|
||||
webView.setInitialScale(getInitialScale(webView.context))
|
||||
}
|
||||
|
||||
fun detach(webView: WebView) {
|
||||
if (this.webView.get() === webView) this.webView.clear()
|
||||
}
|
||||
|
||||
fun getInitialScale(context: Context): Int {
|
||||
val preferences = context.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE)
|
||||
val storedScale = preferences.getInt(INITIAL_SCALE, DEFAULT_INITIAL_SCALE)
|
||||
val scale = storedScale.coerceIn(MIN_INITIAL_SCALE, MAX_INITIAL_SCALE)
|
||||
if (scale != storedScale) preferences.edit().putInt(INITIAL_SCALE, scale).apply()
|
||||
return scale
|
||||
}
|
||||
|
||||
fun setInitialScale(context: Context, initialScale: Int) {
|
||||
val nextScale = initialScale.coerceIn(MIN_INITIAL_SCALE, MAX_INITIAL_SCALE)
|
||||
context.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE)
|
||||
.edit()
|
||||
.putInt(INITIAL_SCALE, nextScale)
|
||||
.apply()
|
||||
webView.get()?.let { currentWebView ->
|
||||
currentWebView.post { currentWebView.setInitialScale(nextScale) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import com.android.build.gradle.LibraryExtension
|
||||
import com.android.build.api.dsl.LibraryExtension
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
|
|
@ -6,8 +6,8 @@ buildscript {
|
|||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:9.3.1")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.4.10")
|
||||
classpath("com.android.tools.build:gradle:8.11.0")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.20")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,5 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
compileOnly(gradleApi())
|
||||
implementation("com.android.tools.build:gradle:9.3.1")
|
||||
implementation("com.android.tools.build:gradle:8.11.0")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@ import org.gradle.api.GradleException
|
|||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.process.ExecOperations
|
||||
import javax.inject.Inject
|
||||
|
||||
open class BuildTask : DefaultTask() {
|
||||
open class BuildTask @Inject constructor(
|
||||
private val execOperations: ExecOperations,
|
||||
) : DefaultTask() {
|
||||
@Input
|
||||
var rootDirRel: String? = null
|
||||
@Input
|
||||
|
|
@ -50,7 +54,7 @@ open class BuildTask : DefaultTask() {
|
|||
val release = release ?: throw GradleException("release cannot be null")
|
||||
val args = listOf("tauri", "android", "android-studio-script");
|
||||
|
||||
project.exec {
|
||||
execOperations.exec {
|
||||
workingDir(File(project.projectDir, rootDirRel))
|
||||
executable(executable)
|
||||
args(args)
|
||||
|
|
@ -65,4 +69,4 @@ open class BuildTask : DefaultTask() {
|
|||
args(listOf("--target", target))
|
||||
}.assertNormalExitValue()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
135
apps/tauri/src-tauri/src/accessibility_backend.rs
Normal file
135
apps/tauri/src-tauri/src/accessibility_backend.rs
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
#[cfg(not(target_os = "android"))]
|
||||
const DEFAULT_INITIAL_SCALE: i32 = 290;
|
||||
const MIN_INITIAL_SCALE: i32 = 210;
|
||||
const MAX_INITIAL_SCALE: i32 = 500;
|
||||
|
||||
#[tauri::command]
|
||||
pub fn accessibility_get_initial_scale() -> Result<i32, String> {
|
||||
android_get_initial_scale()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn accessibility_set_initial_scale(initial_scale: i32) -> Result<(), String> {
|
||||
if !(MIN_INITIAL_SCALE..=MAX_INITIAL_SCALE).contains(&initial_scale) {
|
||||
return Err(format!(
|
||||
"Initial scale must be between {MIN_INITIAL_SCALE} and {MAX_INITIAL_SCALE}"
|
||||
));
|
||||
}
|
||||
|
||||
android_set_initial_scale(initial_scale)
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
fn android_get_initial_scale() -> Result<i32, String> {
|
||||
Ok(DEFAULT_INITIAL_SCALE)
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
fn android_set_initial_scale(_: i32) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
mod android {
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use jni::{
|
||||
jni_sig, jni_str,
|
||||
objects::{Global, JClass, JObject, JValue},
|
||||
Env, EnvUnowned, JavaVM,
|
||||
};
|
||||
|
||||
struct Host {
|
||||
vm: JavaVM,
|
||||
context: Global<JObject<'static>>,
|
||||
bridge: Global<JObject<'static>>,
|
||||
}
|
||||
|
||||
static HOST: OnceLock<Host> = OnceLock::new();
|
||||
|
||||
fn attach(env: &mut Env, context: JObject) -> Result<(), String> {
|
||||
if HOST.get().is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let class = env
|
||||
.find_class(jni_str!("net/tensamin/client/NativeAccessibilityBridge"))
|
||||
.map_err(|error| error.to_string())?;
|
||||
let bridge = env
|
||||
.get_static_field(
|
||||
class,
|
||||
jni_str!("INSTANCE"),
|
||||
jni_sig!("Lnet/tensamin/client/NativeAccessibilityBridge;"),
|
||||
)
|
||||
.and_then(|value| value.l())
|
||||
.map_err(|error| error.to_string())?;
|
||||
|
||||
HOST.set(Host {
|
||||
vm: env.get_java_vm().map_err(|error| error.to_string())?,
|
||||
context: env
|
||||
.new_global_ref(context)
|
||||
.map_err(|error| error.to_string())?,
|
||||
bridge: env
|
||||
.new_global_ref(bridge)
|
||||
.map_err(|error| error.to_string())?,
|
||||
})
|
||||
.map_err(|_| "Android accessibility host is already attached".to_string())
|
||||
}
|
||||
|
||||
fn with_env<T>(call: impl FnOnce(&mut Env, &Host) -> Result<T, String>) -> Result<T, String> {
|
||||
let host = HOST
|
||||
.get()
|
||||
.ok_or("Android accessibility host is not attached")?;
|
||||
host.vm
|
||||
.attach_current_thread(|env| Ok::<_, jni::errors::Error>(call(env, host)))
|
||||
.map_err(|error| error.to_string())?
|
||||
}
|
||||
|
||||
pub fn get_initial_scale() -> Result<i32, String> {
|
||||
with_env(|env, host| {
|
||||
env.call_method(
|
||||
host.bridge.as_obj(),
|
||||
jni_str!("getInitialScale"),
|
||||
jni_sig!("(Landroid/content/Context;)I"),
|
||||
&[JValue::Object(host.context.as_obj())],
|
||||
)
|
||||
.and_then(|value| value.i())
|
||||
.map_err(|error| error.to_string())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_initial_scale(initial_scale: i32) -> Result<(), String> {
|
||||
with_env(|env, host| {
|
||||
env.call_method(
|
||||
host.bridge.as_obj(),
|
||||
jni_str!("setInitialScale"),
|
||||
jni_sig!("(Landroid/content/Context;I)V"),
|
||||
&[
|
||||
JValue::Object(host.context.as_obj()),
|
||||
JValue::Int(initial_scale),
|
||||
],
|
||||
)
|
||||
.map_err(|error| error.to_string())?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_net_tensamin_client_NativeAccessibilityBridge_nativeAttach<
|
||||
'caller,
|
||||
>(
|
||||
mut env: EnvUnowned<'caller>,
|
||||
_class: JClass,
|
||||
context: JObject<'caller>,
|
||||
) {
|
||||
let _ = env.with_env(|env| {
|
||||
let _ = attach(env, context);
|
||||
Ok::<_, jni::errors::Error>(())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
use android::{
|
||||
get_initial_scale as android_get_initial_scale, set_initial_scale as android_set_initial_scale,
|
||||
};
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
mod accessibility_backend;
|
||||
mod mtp_backend;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
|
|
@ -19,6 +20,8 @@ pub fn run() {
|
|||
|
||||
let app = builder
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
accessibility_backend::accessibility_get_initial_scale,
|
||||
accessibility_backend::accessibility_set_initial_scale,
|
||||
mtp_backend::mtp_request,
|
||||
mtp_backend::mtp_status,
|
||||
mtp_backend::mtp_store_credentials,
|
||||
|
|
|
|||
|
|
@ -372,9 +372,13 @@ async fn connect(config: &MtpConfig) -> Result<(MTPConnection, Value), String> {
|
|||
.with_max_missed_pings(3);
|
||||
#[cfg(target_os = "android")]
|
||||
let client_config = client_config.with_pinned_pem(android_root_certificates().clone());
|
||||
let connection = MTPClient::auth_connect(client_config, &keyring, &host_key)
|
||||
.await
|
||||
.map_err(|error| format!("transport authentication failed: {error}"))?;
|
||||
let connection = tokio::time::timeout(
|
||||
Duration::from_secs(30),
|
||||
MTPClient::auth_connect(client_config, &keyring, &host_key),
|
||||
)
|
||||
.await
|
||||
.map_err(|_| "transport authentication timed out".to_string())?
|
||||
.map_err(|error| format!("transport authentication failed: {error}"))?;
|
||||
manager().log(2, "Native MTP authentication completed", None);
|
||||
|
||||
let connected = CommunicationValue::new(CommunicationType::ClientConnected)
|
||||
|
|
@ -385,10 +389,13 @@ async fn connect(config: &MtpConfig) -> Result<(MTPConnection, Value), String> {
|
|||
.add_typed_default(DataType::VersionNumber, DataValue::UnsignedNumber(0))
|
||||
.add_typed_default(DataType::CacheValid, DataValue::BoolFalse)
|
||||
.add_typed_default(DataType::CacheSchemaVersion, DataValue::UnsignedNumber(0));
|
||||
let state = connection
|
||||
.request(&connected, None)
|
||||
.await
|
||||
.map_err(|error| format!("initial state synchronization failed: {error}"))?;
|
||||
let state = tokio::time::timeout(
|
||||
Duration::from_secs(30),
|
||||
connection.request(&connected, None),
|
||||
)
|
||||
.await
|
||||
.map_err(|_| "initial state synchronization timed out".to_string())?
|
||||
.map_err(|error| format!("initial state synchronization failed: {error}"))?;
|
||||
if !state.is_type(CommunicationType::ClientStateSync) {
|
||||
return Err(format!(
|
||||
"expected ClientStateSync, received {}",
|
||||
|
|
@ -406,9 +413,9 @@ async fn connect(config: &MtpConfig) -> Result<(MTPConnection, Value), String> {
|
|||
let ack = CommunicationValue::new(CommunicationType::ClientStateAck)
|
||||
.add_typed_default(DataType::SessionId, number_to_data(session_id))
|
||||
.add_typed_default(DataType::VersionNumber, number_to_data(version));
|
||||
let response = connection
|
||||
.request(&ack, None)
|
||||
let response = tokio::time::timeout(Duration::from_secs(30), connection.request(&ack, None))
|
||||
.await
|
||||
.map_err(|_| "state acknowledgement timed out".to_string())?
|
||||
.map_err(|error| format!("state acknowledgement failed: {error}"))?;
|
||||
if response
|
||||
.get_type_name()
|
||||
|
|
@ -433,7 +440,19 @@ async fn resolve_endpoint(config: &MtpConfig) -> Result<(String, String), String
|
|||
public_key: String,
|
||||
}
|
||||
let root = config.omega_url.trim_end_matches('/');
|
||||
let response = reqwest::get(format!("{root}/api/get/omikron/{}", config.user_id))
|
||||
let client = reqwest::Client::builder()
|
||||
.connect_timeout(Duration::from_secs(10))
|
||||
.timeout(Duration::from_secs(20));
|
||||
#[cfg(target_os = "android")]
|
||||
let client = client.tls_certs_only(
|
||||
reqwest::Certificate::from_pem_bundle(android_root_certificates())
|
||||
.map_err(|error| format!("invalid bundled root certificates: {error}"))?,
|
||||
);
|
||||
let response = client
|
||||
.build()
|
||||
.map_err(|error| error.to_string())?
|
||||
.get(format!("{root}/api/get/omikron/{}", config.user_id))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|error| error.to_string())?;
|
||||
if !response.status().is_success() {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
|
||||
<link rel="icon" href="./favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Tensamin</title>
|
||||
</head>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
"scripts": {
|
||||
"format": "pnpm exec prettier --write .",
|
||||
"lint": "eslint src",
|
||||
"dev": "vite --port 3000 --host 0.0.0.0",
|
||||
"dev": "vite",
|
||||
"test": "vitest run --passWithNoTests",
|
||||
"build": "pnpm run test && tsc -b && vite build",
|
||||
"preview": "cd dist && nix-shell -p python3 --run 'python3 -m http.server 3000' && cd .."
|
||||
|
|
|
|||
|
|
@ -76,11 +76,6 @@ function parseTuFileContent(rawFileContent: string): {
|
|||
throw new Error("Invalid file");
|
||||
}
|
||||
|
||||
console.log({
|
||||
domain,
|
||||
userId,
|
||||
});
|
||||
|
||||
return { userId, privateKey, domain };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ export default defineConfig({
|
|||
],
|
||||
},
|
||||
server: {
|
||||
port: 5173,
|
||||
port: 3000,
|
||||
strictPort: true,
|
||||
host: host || "0.0.0.0",
|
||||
host: "0.0.0.0",
|
||||
hmr: host
|
||||
? {
|
||||
protocol: "ws",
|
||||
|
|
|
|||
|
|
@ -777,40 +777,49 @@ function TauriProvider(props: {
|
|||
let disposed = false;
|
||||
let unlisten: UnlistenFn | undefined;
|
||||
void (async () => {
|
||||
unlisten = await listen<
|
||||
| { kind: "state"; snapshot: NativeSnapshot }
|
||||
| { kind: "message"; generation: number; message: unknown }
|
||||
| {
|
||||
kind: "log";
|
||||
level: number;
|
||||
message: string;
|
||||
details?: unknown;
|
||||
try {
|
||||
const nextUnlisten = await listen<
|
||||
| { kind: "state"; snapshot: NativeSnapshot }
|
||||
| { kind: "message"; generation: number; message: unknown }
|
||||
| {
|
||||
kind: "log";
|
||||
level: number;
|
||||
message: string;
|
||||
details?: unknown;
|
||||
}
|
||||
>("mtp://event", ({ payload }) => {
|
||||
if (disposed) return;
|
||||
if (payload.kind === "state") {
|
||||
applySnapshot(payload.snapshot);
|
||||
return;
|
||||
}
|
||||
>("mtp://event", ({ payload }) => {
|
||||
if (disposed) return;
|
||||
if (payload.kind === "state") {
|
||||
applySnapshot(payload.snapshot);
|
||||
return;
|
||||
}
|
||||
if (payload.kind === "message") {
|
||||
if (payload.generation === generationRef.current) {
|
||||
dispatchMessage(payload.message);
|
||||
if (payload.kind === "message") {
|
||||
if (payload.generation === generationRef.current) {
|
||||
dispatchMessage(payload.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
log(
|
||||
payload.level,
|
||||
"android",
|
||||
"orange",
|
||||
payload.message,
|
||||
payload.details,
|
||||
);
|
||||
});
|
||||
const current = await invoke<NativeSnapshot>("mtp_status");
|
||||
if (!disposed) applySnapshot(current);
|
||||
})().catch((error) => {
|
||||
log(0, "mtp", "red", "Failed to initialize native MTP bridge", error);
|
||||
});
|
||||
log(
|
||||
payload.level,
|
||||
"android",
|
||||
"orange",
|
||||
payload.message,
|
||||
payload.details,
|
||||
);
|
||||
});
|
||||
if (disposed) nextUnlisten();
|
||||
else unlisten = nextUnlisten;
|
||||
} catch (error) {
|
||||
log(0, "mtp", "red", "Failed to subscribe to native MTP events", error);
|
||||
}
|
||||
|
||||
try {
|
||||
const current = await invoke<NativeSnapshot>("mtp_status");
|
||||
if (!disposed) applySnapshot(current);
|
||||
} catch (error) {
|
||||
log(0, "mtp", "red", "Failed to load native MTP status", error);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
disposed = true;
|
||||
unlisten?.();
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
"dependencies": {
|
||||
"@methanium/ui": "*",
|
||||
"@tanstack/react-router": "^1.170.21",
|
||||
"@tauri-apps/api": "^2.11.1",
|
||||
"@tensamin/cache": "workspace:*",
|
||||
"@tensamin/hotkeys": "workspace:*",
|
||||
"@tensamin/mtp": "workspace:*",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import Accessibility from "./pages/accessibility";
|
||||
import Cache from "./pages/cache";
|
||||
import Call from "./pages/call";
|
||||
import Chat from "./pages/chat";
|
||||
|
|
@ -26,6 +27,12 @@ export const settingsPages = [
|
|||
{ category: "general", path: "call", label: "Call", component: Call },
|
||||
{ category: "application", path: "cache", label: "Cache", component: Cache },
|
||||
{ category: "application", path: "theme", label: "Theme", component: Theme },
|
||||
{
|
||||
category: "application",
|
||||
path: "accessibility",
|
||||
label: "Accessibility",
|
||||
component: Accessibility,
|
||||
},
|
||||
{
|
||||
category: "application",
|
||||
path: "hotkeys",
|
||||
|
|
|
|||
80
packages/settings/src/pages/accessibility.tsx
Normal file
80
packages/settings/src/pages/accessibility.tsx
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import { Button, Label, Slider } from "@methanium/ui";
|
||||
import { invoke, isTauri } from "@tauri-apps/api/core";
|
||||
import { RotateCcw } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
const DEFAULT_INITIAL_SCALE = 290;
|
||||
const MIN_INITIAL_SCALE = 210;
|
||||
const isAndroid = isTauri() && /Android/.test(navigator.userAgent);
|
||||
|
||||
export default function Page() {
|
||||
const [initialScale, setInitialScale] = useState(DEFAULT_INITIAL_SCALE);
|
||||
const [loading, setLoading] = useState(isAndroid);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAndroid) return;
|
||||
|
||||
let active = true;
|
||||
void invoke<number>("accessibility_get_initial_scale")
|
||||
.then((scale) => {
|
||||
if (active) setInitialScale(scale);
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
console.error("Failed to load the Android initial scale", error);
|
||||
})
|
||||
.finally(() => {
|
||||
if (active) setLoading(false);
|
||||
});
|
||||
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!isAndroid) return null;
|
||||
|
||||
function updateInitialScale(nextScale: number) {
|
||||
setInitialScale(nextScale);
|
||||
void invoke("accessibility_set_initial_scale", {
|
||||
initialScale: nextScale,
|
||||
}).catch((error: unknown) => {
|
||||
console.error("Failed to update the Android initial scale", error);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex max-w-md flex-col gap-2">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<Label htmlFor="initial-scale">Interface scale</Label>
|
||||
<span className="text-muted-foreground text-sm tabular-nums">
|
||||
{initialScale}%
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Slider
|
||||
id="initial-scale"
|
||||
aria-label="Interface scale"
|
||||
min={MIN_INITIAL_SCALE}
|
||||
max={500}
|
||||
step={1}
|
||||
value={[initialScale]}
|
||||
disabled={loading}
|
||||
onValueChange={(value) => {
|
||||
const nextScale = Array.isArray(value) ? value[0] : value;
|
||||
if (nextScale !== undefined) updateInitialScale(nextScale);
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
className="size-8 shrink-0 p-0"
|
||||
variant="outline"
|
||||
aria-label="Reset interface scale"
|
||||
title="Reset interface scale"
|
||||
disabled={loading || initialScale === DEFAULT_INITIAL_SCALE}
|
||||
onClick={() => updateInitialScale(DEFAULT_INITIAL_SCALE)}
|
||||
>
|
||||
<RotateCcw className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
|
|
@ -509,6 +509,9 @@ importers:
|
|||
'@tanstack/react-router':
|
||||
specifier: ^1.170.21
|
||||
version: 1.170.23(react-dom@19.2.8(react@19.2.8))(react@19.2.8)
|
||||
'@tauri-apps/api':
|
||||
specifier: ^2.11.1
|
||||
version: 2.11.1
|
||||
'@tensamin/cache':
|
||||
specifier: workspace:*
|
||||
version: link:../cache
|
||||
|
|
|
|||
Loading…
Reference in a new issue