From 0e6950a60fe809cb139180de132f137a6ce7a0f2 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Tue, 30 Sep 2025 16:03:33 +0800 Subject: [PATCH] i18n: localization for notification title and text (#2143) --- .../public/locales/ar/translation.json | 4 +- .../public/locales/bn/translation.json | 4 +- .../public/locales/bo/translation.json | 4 +- .../public/locales/de/translation.json | 4 +- .../public/locales/el/translation.json | 4 +- .../public/locales/es/translation.json | 4 +- .../public/locales/fr/translation.json | 4 +- .../public/locales/hi/translation.json | 4 +- .../public/locales/id/translation.json | 4 +- .../public/locales/it/translation.json | 4 +- .../public/locales/ja/translation.json | 4 +- .../public/locales/ko/translation.json | 4 +- .../public/locales/nl/translation.json | 4 +- .../public/locales/pl/translation.json | 4 +- .../public/locales/pt/translation.json | 4 +- .../public/locales/ru/translation.json | 4 +- .../public/locales/si/translation.json | 4 +- .../public/locales/ta/translation.json | 4 +- .../public/locales/th/translation.json | 4 +- .../public/locales/tr/translation.json | 4 +- .../public/locales/uk/translation.json | 4 +- .../public/locales/vi/translation.json | 4 +- .../public/locales/zh-CN/translation.json | 4 +- .../public/locales/zh-TW/translation.json | 4 +- .../android/src/main/java/NativeTTSPlugin.kt | 42 +++++++++++++++---- .../tauri-plugin-native-tts/src/models.rs | 5 +++ .../app/reader/components/tts/TTSControl.tsx | 11 ++++- apps/readest-app/src/libs/mediaSession.ts | 38 +++++++++++------ 28 files changed, 145 insertions(+), 47 deletions(-) diff --git a/apps/readest-app/public/locales/ar/translation.json b/apps/readest-app/public/locales/ar/translation.json index bce68e43..5e97cf55 100644 --- a/apps/readest-app/public/locales/ar/translation.json +++ b/apps/readest-app/public/locales/ar/translation.json @@ -613,5 +613,7 @@ "Start Migration": "بدء الترحيل", "Advanced Settings": "إعدادات متقدمة", "File count: {{size}}": "عدد الملفات: {{size}}", - "Background Read Aloud": "قراءة بصوت عالٍ في الخلفية" + "Background Read Aloud": "قراءة بصوت عالٍ في الخلفية", + "Ready to read aloud": "جاهز للقراءة بصوت عالٍ", + "Read Aloud": "القراءة بصوت عالٍ" } diff --git a/apps/readest-app/public/locales/bn/translation.json b/apps/readest-app/public/locales/bn/translation.json index 04994962..cbe79583 100644 --- a/apps/readest-app/public/locales/bn/translation.json +++ b/apps/readest-app/public/locales/bn/translation.json @@ -597,5 +597,7 @@ "Start Migration": "মাইগ্রেশন শুরু করুন", "Advanced Settings": "উন্নত সেটিংস", "File count: {{size}}": "ফাইলের সংখ্যা: {{size}}", - "Background Read Aloud": "পটভূমিতে উচ্চস্বরে পড়ুন" + "Background Read Aloud": "পটভূমিতে উচ্চস্বরে পড়ুন", + "Ready to read aloud": "উচ্চস্বরে পড়ার জন্য প্রস্তুত", + "Read Aloud": "উচ্চস্বরে পড়ুন" } diff --git a/apps/readest-app/public/locales/bo/translation.json b/apps/readest-app/public/locales/bo/translation.json index 920643e1..70716e2f 100644 --- a/apps/readest-app/public/locales/bo/translation.json +++ b/apps/readest-app/public/locales/bo/translation.json @@ -593,5 +593,7 @@ "Start Migration": "མཉམ་དུ་ཀློག་འཛུལ་བྱས་མ་ཐུབ།", "Advanced Settings": "དབང་བསྐྱོད་སྒྲིག་སྟངས།", "File count: {{size}}": "དེབ་གནས་བཅས་པའི་ཨང་། {{size}}", - "Background Read Aloud": "གནས་སྟངས་ཀྱིས་ཀློག་བྱེད།" + "Background Read Aloud": "གནས་སྟངས་ཀྱིས་ཀློག་བྱེད།", + "Ready to read aloud": "དེབ་ཀྱི་སྤྱོད་བྱས་མ་ཐུབ།", + "Read Aloud": "ཀློག་བྱེད།" } diff --git a/apps/readest-app/public/locales/de/translation.json b/apps/readest-app/public/locales/de/translation.json index 24ca885e..271a1fb2 100644 --- a/apps/readest-app/public/locales/de/translation.json +++ b/apps/readest-app/public/locales/de/translation.json @@ -597,5 +597,7 @@ "Start Migration": "Migration starten", "Advanced Settings": "Erweiterte Einstellungen", "File count: {{size}}": "Dateianzahl: {{size}}", - "Background Read Aloud": "Hintergrund-Vorlesen" + "Background Read Aloud": "Hintergrund-Vorlesen", + "Ready to read aloud": "Bereit zum Vorlesen", + "Read Aloud": "Vorlesen" } diff --git a/apps/readest-app/public/locales/el/translation.json b/apps/readest-app/public/locales/el/translation.json index 4237c0ba..988af7b9 100644 --- a/apps/readest-app/public/locales/el/translation.json +++ b/apps/readest-app/public/locales/el/translation.json @@ -597,5 +597,7 @@ "Start Migration": "Έναρξη μετανάστευσης", "Advanced Settings": "Προηγμένες ρυθμίσεις", "File count: {{size}}": "Αριθμός αρχείων: {{size}}", - "Background Read Aloud": "Ανάγνωση στο παρασκήνιο" + "Background Read Aloud": "Ανάγνωση στο παρασκήνιο", + "Ready to read aloud": "Έτοιμο για ανάγνωση", + "Read Aloud": "Ανάγνωση" } diff --git a/apps/readest-app/public/locales/es/translation.json b/apps/readest-app/public/locales/es/translation.json index f2ca961e..a48d2cf3 100644 --- a/apps/readest-app/public/locales/es/translation.json +++ b/apps/readest-app/public/locales/es/translation.json @@ -601,5 +601,7 @@ "Start Migration": "Iniciar Migración", "Advanced Settings": "Configuraciones Avanzadas", "File count: {{size}}": "Número de archivos: {{size}}", - "Background Read Aloud": "Lectura en segundo plano" + "Background Read Aloud": "Lectura en segundo plano", + "Ready to read aloud": "Listo para leer en voz alta", + "Read Aloud": "Leer en voz alta" } diff --git a/apps/readest-app/public/locales/fr/translation.json b/apps/readest-app/public/locales/fr/translation.json index 1a628615..0bdeb908 100644 --- a/apps/readest-app/public/locales/fr/translation.json +++ b/apps/readest-app/public/locales/fr/translation.json @@ -601,5 +601,7 @@ "Start Migration": "Démarrer la Migration", "Advanced Settings": "Paramètres Avancés", "File count: {{size}}": "Nombre de fichiers : {{size}}", - "Background Read Aloud": "Lecture Vocale en Arrière-Plan" + "Background Read Aloud": "Lecture Vocale en Arrière-Plan", + "Ready to read aloud": "Prêt à lire à haute voix", + "Read Aloud": "Lire à haute voix" } diff --git a/apps/readest-app/public/locales/hi/translation.json b/apps/readest-app/public/locales/hi/translation.json index 4527f99a..9e864e15 100644 --- a/apps/readest-app/public/locales/hi/translation.json +++ b/apps/readest-app/public/locales/hi/translation.json @@ -597,5 +597,7 @@ "Start Migration": "माइग्रेशन प्रारंभ करें", "Advanced Settings": "उन्नत सेटिंग्स", "File count: {{size}}": "फ़ाइलों की संख्या: {{size}}", - "Background Read Aloud": "पृष्ठभूमि में वाचन" + "Background Read Aloud": "पृष्ठभूमि में वाचन", + "Ready to read aloud": "उच्च स्वर में पढ़ने के लिए तैयार", + "Read Aloud": "उच्च स्वर में पढ़ें" } diff --git a/apps/readest-app/public/locales/id/translation.json b/apps/readest-app/public/locales/id/translation.json index ac43b190..b9130284 100644 --- a/apps/readest-app/public/locales/id/translation.json +++ b/apps/readest-app/public/locales/id/translation.json @@ -593,5 +593,7 @@ "Start Migration": "Mulai Migrasi", "Advanced Settings": "Pengaturan Lanjutan", "File count: {{size}}": "Jumlah file: {{size}}", - "Background Read Aloud": "Bacakan Latar Belakang" + "Background Read Aloud": "Bacakan Latar Belakang", + "Ready to read aloud": "Siap untuk dibacakan", + "Read Aloud": "Bacakan" } diff --git a/apps/readest-app/public/locales/it/translation.json b/apps/readest-app/public/locales/it/translation.json index bf90a0bc..39ec4956 100644 --- a/apps/readest-app/public/locales/it/translation.json +++ b/apps/readest-app/public/locales/it/translation.json @@ -601,5 +601,7 @@ "Start Migration": "Inizia Migrazione", "Advanced Settings": "Impostazioni Avanzate", "File count: {{size}}": "Conteggio file: {{size}}", - "Background Read Aloud": "Background Read Aloud" + "Background Read Aloud": "Riproduzione in background", + "Ready to read aloud": "Pronto per la lettura ad alta voce", + "Read Aloud": "Leggi ad alta voce" } diff --git a/apps/readest-app/public/locales/ja/translation.json b/apps/readest-app/public/locales/ja/translation.json index 71a31549..839bddca 100644 --- a/apps/readest-app/public/locales/ja/translation.json +++ b/apps/readest-app/public/locales/ja/translation.json @@ -593,5 +593,7 @@ "Start Migration": "移行を開始", "Advanced Settings": "詳細設定", "File count: {{size}}": "ファイル数: {{size}}", - "Background Read Aloud": "バックグラウンド読み上げ" + "Background Read Aloud": "バックグラウンド読み上げ", + "Ready to read aloud": "読み上げの準備ができました", + "Read Aloud": "読み上げ" } diff --git a/apps/readest-app/public/locales/ko/translation.json b/apps/readest-app/public/locales/ko/translation.json index e19ff4ec..d5f8027c 100644 --- a/apps/readest-app/public/locales/ko/translation.json +++ b/apps/readest-app/public/locales/ko/translation.json @@ -593,5 +593,7 @@ "Start Migration": "마이그레이션 시작", "Advanced Settings": "고급 설정", "File count: {{size}}": "파일 수: {{size}}", - "Background Read Aloud": "백그라운드 음성 읽기" + "Background Read Aloud": "백그라운드 음성 읽기", + "Ready to read aloud": "읽기 준비 완료", + "Read Aloud": "음성 읽기" } diff --git a/apps/readest-app/public/locales/nl/translation.json b/apps/readest-app/public/locales/nl/translation.json index f87ccd71..1d8f5558 100644 --- a/apps/readest-app/public/locales/nl/translation.json +++ b/apps/readest-app/public/locales/nl/translation.json @@ -597,5 +597,7 @@ "Start Migration": "Start Migratie", "Advanced Settings": "Geavanceerde Instellingen", "File count: {{size}}": "Bestandsaantal: {{size}}", - "Background Read Aloud": "Achtergrond Voorlezen" + "Background Read Aloud": "Achtergrond Voorlezen", + "Ready to read aloud": "Klaar om voor te lezen", + "Read Aloud": "Voorlezen" } diff --git a/apps/readest-app/public/locales/pl/translation.json b/apps/readest-app/public/locales/pl/translation.json index 5dcf8b00..864ae701 100644 --- a/apps/readest-app/public/locales/pl/translation.json +++ b/apps/readest-app/public/locales/pl/translation.json @@ -605,5 +605,7 @@ "Start Migration": "Rozpocznij migrację", "Advanced Settings": "Ustawienia zaawansowane", "File count: {{size}}": "Liczba plików: {{size}}", - "Background Read Aloud": "Czytanie na głos w tle" + "Background Read Aloud": "Czytanie na głos w tle", + "Ready to read aloud": "Gotowy do przeczytania na głos", + "Read Aloud": "Czytaj na głos" } diff --git a/apps/readest-app/public/locales/pt/translation.json b/apps/readest-app/public/locales/pt/translation.json index 9bd08b9a..8e063404 100644 --- a/apps/readest-app/public/locales/pt/translation.json +++ b/apps/readest-app/public/locales/pt/translation.json @@ -601,5 +601,7 @@ "Start Migration": "Iniciar Migração", "Advanced Settings": "Configurações Avançadas", "File count: {{size}}": "Contagem de arquivos: {{size}}", - "Background Read Aloud": "Leitura em Segundo Plano" + "Background Read Aloud": "Leitura em Segundo Plano", + "Ready to read aloud": "Pronto para leitura em voz alta", + "Read Aloud": "Ler em Voz Alta" } diff --git a/apps/readest-app/public/locales/ru/translation.json b/apps/readest-app/public/locales/ru/translation.json index 772574e7..d05fbac2 100644 --- a/apps/readest-app/public/locales/ru/translation.json +++ b/apps/readest-app/public/locales/ru/translation.json @@ -605,5 +605,7 @@ "Start Migration": "Начать миграцию", "Advanced Settings": "Расширенные настройки", "File count: {{size}}": "Количество файлов: {{size}}", - "Background Read Aloud": "Озвучивание в фоне" + "Background Read Aloud": "Озвучивание в фоне", + "Ready to read aloud": "Готов к чтению вслух", + "Read Aloud": "Читать вслух" } diff --git a/apps/readest-app/public/locales/si/translation.json b/apps/readest-app/public/locales/si/translation.json index 3feb93cb..c00dba98 100644 --- a/apps/readest-app/public/locales/si/translation.json +++ b/apps/readest-app/public/locales/si/translation.json @@ -597,5 +597,7 @@ "Start Migration": "මැතිවරණය ආරම්භ කරන්න", "Advanced Settings": "උසස් සැකසුම්", "File count: {{size}}": "ගොනු ගණන: {{size}}", - "Background Read Aloud": "පසුබිම් පවසා කියවීම" + "Background Read Aloud": "පසුබිම් පවසා කියවීම", + "Ready to read aloud": "වාදනය කිරීමට සූදානම්", + "Read Aloud": "පවසා කියවීම" } diff --git a/apps/readest-app/public/locales/ta/translation.json b/apps/readest-app/public/locales/ta/translation.json index ef4067f1..0d267cc8 100644 --- a/apps/readest-app/public/locales/ta/translation.json +++ b/apps/readest-app/public/locales/ta/translation.json @@ -597,5 +597,7 @@ "Start Migration": "மொத்தமாக்கலை தொடங்கவும்", "Advanced Settings": "மேம்பட்ட அமைப்புகள்", "File count: {{size}}": "கோப்பு எண்ணிக்கை: {{size}}", - "Background Read Aloud": "பின்னணி உரை வாசிப்பு" + "Background Read Aloud": "பின்னணி உரை வாசிப்பு", + "Ready to read aloud": "வாசிக்க தயாராக உள்ளது", + "Read Aloud": "உரை வாசிப்பு" } diff --git a/apps/readest-app/public/locales/th/translation.json b/apps/readest-app/public/locales/th/translation.json index 3a06a24d..66c5550e 100644 --- a/apps/readest-app/public/locales/th/translation.json +++ b/apps/readest-app/public/locales/th/translation.json @@ -593,5 +593,7 @@ "Start Migration": "เริ่มการย้ายข้อมูล", "Advanced Settings": "การตั้งค่าขั้นสูง", "File count: {{size}}": "จำนวนไฟล์: {{size}}", - "Background Read Aloud": "อ่านออกเสียงเบื้องหลัง" + "Background Read Aloud": "อ่านออกเสียงเบื้องหลัง", + "Ready to read aloud": "พร้อมที่จะอ่านออกเสียง", + "Read Aloud": "อ่านออกเสียง" } diff --git a/apps/readest-app/public/locales/tr/translation.json b/apps/readest-app/public/locales/tr/translation.json index bf452bcd..180a6a7b 100644 --- a/apps/readest-app/public/locales/tr/translation.json +++ b/apps/readest-app/public/locales/tr/translation.json @@ -597,5 +597,7 @@ "Start Migration": "Taşımayı Başlat", "Advanced Settings": "Gelişmiş Ayarlar", "File count: {{size}}": "Dosya sayısı: {{size}}", - "Background Read Aloud": "Arka Planda Sesli Okuma" + "Background Read Aloud": "Arka Planda Sesli Okuma", + "Ready to read aloud": "Sesli okumaya hazır", + "Read Aloud": "Sesli Oku" } diff --git a/apps/readest-app/public/locales/uk/translation.json b/apps/readest-app/public/locales/uk/translation.json index f8db0904..e53e2935 100644 --- a/apps/readest-app/public/locales/uk/translation.json +++ b/apps/readest-app/public/locales/uk/translation.json @@ -605,5 +605,7 @@ "Start Migration": "Почати переміщення", "Advanced Settings": "Розширені налаштування", "File count: {{size}}": "Кількість файлів: {{size}}", - "Background Read Aloud": "Озвучування у фоновому режимі" + "Background Read Aloud": "Озвучування у фоновому режимі", + "Ready to read aloud": "Готовий до читання вголос", + "Read Aloud": "Читати вголос" } diff --git a/apps/readest-app/public/locales/vi/translation.json b/apps/readest-app/public/locales/vi/translation.json index 3a5af09e..f8f6168b 100644 --- a/apps/readest-app/public/locales/vi/translation.json +++ b/apps/readest-app/public/locales/vi/translation.json @@ -593,5 +593,7 @@ "Start Migration": "Bắt đầu di chuyển", "Advanced Settings": "Cài đặt nâng cao", "File count: {{size}}": "Số lượng tệp: {{size}}", - "Background Read Aloud": "Đọc To Nền" + "Background Read Aloud": "Đọc To Nền", + "Ready to read aloud": "Sẵn sàng để đọc to", + "Read Aloud": "Đọc To" } diff --git a/apps/readest-app/public/locales/zh-CN/translation.json b/apps/readest-app/public/locales/zh-CN/translation.json index 9e9e6c87..58f659d4 100644 --- a/apps/readest-app/public/locales/zh-CN/translation.json +++ b/apps/readest-app/public/locales/zh-CN/translation.json @@ -593,5 +593,7 @@ "Start Migration": "开始迁移", "Advanced Settings": "高级设置", "File count: {{size}}": "文件数量: {{size}}", - "Background Read Aloud": "后台语音朗读" + "Background Read Aloud": "后台语音朗读", + "Ready to read aloud": "语音朗读已就绪", + "Read Aloud": "语音朗读" } diff --git a/apps/readest-app/public/locales/zh-TW/translation.json b/apps/readest-app/public/locales/zh-TW/translation.json index 313f0d86..7d2fa52e 100644 --- a/apps/readest-app/public/locales/zh-TW/translation.json +++ b/apps/readest-app/public/locales/zh-TW/translation.json @@ -593,5 +593,7 @@ "Start Migration": "開始遷移", "Advanced Settings": "高級設置", "File count: {{size}}": "文件數量: {{size}}", - "Background Read Aloud": "背景朗讀" + "Background Read Aloud": "背景朗讀", + "Ready to read aloud": "朗讀準備就緒", + "Read Aloud": "朗讀" } diff --git a/apps/readest-app/src-tauri/plugins/tauri-plugin-native-tts/android/src/main/java/NativeTTSPlugin.kt b/apps/readest-app/src-tauri/plugins/tauri-plugin-native-tts/android/src/main/java/NativeTTSPlugin.kt index 71c88662..20de26e8 100644 --- a/apps/readest-app/src-tauri/plugins/tauri-plugin-native-tts/android/src/main/java/NativeTTSPlugin.kt +++ b/apps/readest-app/src-tauri/plugins/tauri-plugin-native-tts/android/src/main/java/NativeTTSPlugin.kt @@ -99,6 +99,11 @@ class UpdateMediaSessionStateArgs { @InvokeArg class SetMediaSessionActiveArgs { var active: Boolean? = null + var keepAppInForeground: Boolean? = null + var notificationTitle: String? = null + var notificationText: String? = null + var foregroundServiceTitle: String? = null + var foregroundServiceText: String? = null } class MediaForegroundService : Service() { @@ -134,10 +139,10 @@ class MediaForegroundService : Service() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val channel = NotificationChannel( CHANNEL_ID, - "TTS Media Playback", + NativeTTSPlugin.NOTIFICATION_TITLE, NotificationManager.IMPORTANCE_MIN ).apply { - description = "Controls for TTS media playback" + description = NativeTTSPlugin.NOTIFICATION_TEXT setShowBadge(false) setSound(null, null) } @@ -148,8 +153,8 @@ class MediaForegroundService : Service() { private fun startForegroundService() { val notification = NotificationCompat.Builder(this, CHANNEL_ID) - .setContentTitle("TTS Media Session") - .setContentText("Text-to-speech playback active") + .setContentTitle(NativeTTSPlugin.FOREGROUND_SERVICE_TITLE) + .setContentText(NativeTTSPlugin.FOREGROUND_SERVICE_TEXT) .setSmallIcon(android.R.drawable.ic_media_play) .setOngoing(true) .setSilent(true) @@ -183,6 +188,10 @@ class NativeTTSPlugin(private val activity: Activity) : Plugin(activity) { companion object { private const val TAG = "NativeTTSPlugin" private const val CHANNEL_NAME = "tts_events" + var NOTIFICATION_TITLE = "Read Aloud" + var NOTIFICATION_TEXT = "Ready to read aloud" + var FOREGROUND_SERVICE_TITLE = "Read Aloud" + var FOREGROUND_SERVICE_TEXT = "Ready to read aloud" } private var textToSpeech: TextToSpeech? = null @@ -198,6 +207,7 @@ class NativeTTSPlugin(private val activity: Activity) : Plugin(activity) { private var player: Player? = null private var mediaSession: MediaSession? = null private var isMediaSessionActive = false + private var isForegroundServiceRunning = false private val coroutineScope = CoroutineScope(Dispatchers.Main + SupervisorJob()) @@ -668,7 +678,6 @@ class NativeTTSPlugin(private val activity: Activity) : Plugin(activity) { var args = invoke.parseArgs(UpdateMediaSessionStateArgs::class.java) val isPlaying = args.playing ?: false val position = args.position ?: 0.0 - val duration = args.duration ?: 0.0 try { player?.let { player -> @@ -687,16 +696,28 @@ class NativeTTSPlugin(private val activity: Activity) : Plugin(activity) { fun set_media_session_active(invoke: Invoke) { var args = invoke.parseArgs(SetMediaSessionActiveArgs::class.java) val active = args.active ?: true - + val keepAppInForeground = args.keepAppInForeground ?: false + + args.notificationTitle?.let { NOTIFICATION_TITLE = it } + args.notificationText?.let { NOTIFICATION_TEXT = it } + args.foregroundServiceTitle?.let { FOREGROUND_SERVICE_TITLE = it } + args.foregroundServiceText?.let { FOREGROUND_SERVICE_TEXT = it } + try { if (active && !isMediaSessionActive) { initializeMediaSession() - startForegroundService() + if (keepAppInForeground) { + startForegroundService() + isForegroundServiceRunning = true + } isMediaSessionActive = true Log.d(TAG, "Media session activated with foreground service") } else if (!active && isMediaSessionActive) { deinitializeMediaSession() - stopForegroundService() + if (isForegroundServiceRunning) { + stopForegroundService() + isForegroundServiceRunning = false + } isMediaSessionActive = false Log.d(TAG, "Media session deactivated and foreground service stopped") } @@ -710,7 +731,10 @@ class NativeTTSPlugin(private val activity: Activity) : Plugin(activity) { fun destroy() { try { if (isMediaSessionActive) { - stopForegroundService() + if (isForegroundServiceRunning) { + stopForegroundService() + isForegroundServiceRunning = false + } isMediaSessionActive = false } diff --git a/apps/readest-app/src-tauri/plugins/tauri-plugin-native-tts/src/models.rs b/apps/readest-app/src-tauri/plugins/tauri-plugin-native-tts/src/models.rs index e0fa88f9..ec1055f8 100644 --- a/apps/readest-app/src-tauri/plugins/tauri-plugin-native-tts/src/models.rs +++ b/apps/readest-app/src-tauri/plugins/tauri-plugin-native-tts/src/models.rs @@ -66,6 +66,11 @@ pub struct GetVoicesResponse { #[serde(rename_all = "camelCase")] pub struct SetMediaSessionActiveRequest { pub active: bool, + pub keep_app_in_foreground: bool, + pub notification_title: Option, + pub notification_text: Option, + pub foreground_service_title: Option, + pub foreground_service_text: Option, } #[derive(Debug, Deserialize, Serialize)] diff --git a/apps/readest-app/src/app/reader/components/tts/TTSControl.tsx b/apps/readest-app/src/app/reader/components/tts/TTSControl.tsx index 47403ab1..20100f47 100644 --- a/apps/readest-app/src/app/reader/components/tts/TTSControl.tsx +++ b/apps/readest-app/src/app/reader/components/tts/TTSControl.tsx @@ -117,7 +117,14 @@ const TTSControl: React.FC = ({ bookKey, gridInsets }) => { artworkImage = await fetchImageAsBase64('/icon.png'); } - await mediaSession.setActive(true, settings.alwaysInForeground); + await mediaSession.setActive({ + active: true, + keepAppInForeground: settings.alwaysInForeground, + notificationTitle: _('Read Aloud'), + notificationText: _('Ready to read aloud'), + foregroundServiceTitle: _('Read Aloud'), + foregroundServiceText: _('Ready to read aloud'), + }); mediaSession.updateMetadata({ title: title, artist: sectionLabel || title, @@ -129,7 +136,7 @@ const TTSControl: React.FC = ({ bookKey, gridInsets }) => { const deinitMediaSession = async () => { if (mediaSessionRef.current && mediaSessionRef.current instanceof TauriMediaSession) { - await mediaSessionRef.current.setActive(false); + await mediaSessionRef.current.setActive({ active: false }); } mediaSessionRef.current = null; }; diff --git a/apps/readest-app/src/libs/mediaSession.ts b/apps/readest-app/src/libs/mediaSession.ts index 283070e7..0df1860c 100644 --- a/apps/readest-app/src/libs/mediaSession.ts +++ b/apps/readest-app/src/libs/mediaSession.ts @@ -16,6 +16,15 @@ export interface PlaybackState { duration: number; } +export interface MediaSessionState { + active: boolean; + keepAppInForeground?: boolean; + notificationTitle?: string; + notificationText?: string; + foregroundServiceTitle?: string; + foregroundServiceText?: string; +} + interface Permissions { postNotification: PermissionState; } @@ -25,16 +34,16 @@ export class TauriMediaSession { private eventListenerInited: boolean = false; private eventListeners: PluginListener[] = []; - private async initializeListeners(keepAppInForeground: boolean) { - if (keepAppInForeground) { - const permission = await invoke('plugin:native-tts|checkPermissions'); - if (permission.postNotification.startsWith('prompt')) { - await invoke('plugin:native-tts|requestPermissions', { - permissions: ['postNotification'], - }); - } + private async requestPostNotificationPermission() { + const permission = await invoke('plugin:native-tts|checkPermissions'); + if (permission.postNotification.startsWith('prompt')) { + await invoke('plugin:native-tts|requestPermissions', { + permissions: ['postNotification'], + }); } + } + private async initializeListeners() { if (this.eventListenerInited) return; this.eventListenerInited = true; @@ -103,14 +112,19 @@ export class TauriMediaSession { } } - async setActive(active: boolean, keepAppInForeground: boolean = false) { + async setActive(sessionState: MediaSessionState) { try { - if (active) { - await this.initializeListeners(keepAppInForeground); + if (sessionState.active) { + if (sessionState.keepAppInForeground) { + await this.requestPostNotificationPermission(); + } + await this.initializeListeners(); } else { await this.cleanupListeners(); } - await invoke('plugin:native-tts|set_media_session_active', { payload: { active } }); + await invoke('plugin:native-tts|set_media_session_active', { + payload: sessionState, + }); } catch (error) { console.error('Failed to set media session active state:', error); }