Skip to content

Commit 8b4ef48

Browse files
committed
feat: show notification when restarting rime
This may prevent the rime backend from killing by the system.
1 parent 166e6bc commit 8b4ef48

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

app/src/main/java/com/osfans/trime/daemon/RimeDaemon.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package com.osfans.trime.daemon
22

3+
import androidx.core.app.NotificationCompat
4+
import com.blankj.utilcode.util.NotificationUtils
5+
import com.osfans.trime.R
36
import com.osfans.trime.core.Rime
47
import com.osfans.trime.core.RimeApi
58
import com.osfans.trime.core.RimeLifecycle
69
import com.osfans.trime.core.whenReady
10+
import com.osfans.trime.util.appContext
711
import kotlinx.coroutines.runBlocking
12+
import splitties.systemservices.notificationManager
813
import java.util.concurrent.locks.ReentrantLock
914
import kotlin.concurrent.withLock
1015

@@ -70,12 +75,28 @@ object RimeDaemon {
7075
}
7176
}
7277

78+
private const val CHANNEL_ID = "rime-daemon"
79+
private var restartId = 0
80+
7381
/**
7482
* Restart Rime instance to deploy while keep the session
7583
*/
7684
fun restartRime(fullCheck: Boolean = false) =
7785
lock.withLock {
86+
val id = restartId++
87+
NotificationUtils.notify(CHANNEL_ID, id) {
88+
it.setSmallIcon(R.drawable.ic_baseline_sync_24)
89+
.setContentTitle(appContext.getString(R.string.rime_daemon))
90+
.setContentText(appContext.getString(R.string.restarting_rime))
91+
.setOngoing(true)
92+
.setProgress(100, 0, true)
93+
.setPriority(NotificationCompat.PRIORITY_HIGH)
94+
}
7895
realRime.finalize()
7996
realRime.startup(fullCheck)
97+
// cancel notification on ready
98+
realRime.lifecycle.whenReady {
99+
notificationManager.cancel(CHANNEL_ID, id)
100+
}
80101
}
81102
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:autoMirrored="true" android:height="24dp"
2+
android:tint="#000000" android:viewportHeight="24"
3+
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M12,4L12,1L8,5l4,4L12,6c3.31,0 6,2.69 6,6 0,1.01 -0.25,1.97 -0.7,2.8l1.46,1.46C19.54,15.03 20,13.57 20,12c0,-4.42 -3.58,-8 -8,-8zM12,18c-3.31,0 -6,-2.69 -6,-6 0,-1.01 0.25,-1.97 0.7,-2.8L5.24,7.74C4.46,8.97 4,10.43 4,12c0,4.42 3.58,8 8,8v3l4,-4 -4,-4v3z"/>
5+
</vector>

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,6 @@
284284
<string name="schedule_exact_alarm_permission_message">没有闹钟和提醒权限,我们无法在启用定时同步时及时为您同步数据配置。</string>
285285
<string name="notification_permission_title">没有通知权限</string>
286286
<string name="notification_permission_message">没有发送通知的权限,我们无法在一些耗时操作完成时通知您。</string>
287+
<string name="rime_daemon">Rime 守护程序</string>
288+
<string name="restarting_rime">正在重新启动 Rime</string>
287289
</resources>

app/src/main/res/values-zh-rTW/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,6 @@
285285
<string name="schedule_exact_alarm_permission_message">尚未賦予鬧鐘和提醒權限,因此無法在啟用定時同步時及時為您同步資料配置。</string>
286286
<string name="notification_permission_title">沒有通知權限</string>
287287
<string name="notification_permission_message">尚未賦予通知權限,因此無法在耗時較長的操作完成後給您發送通知。</string>
288+
<string name="rime_daemon">Rime 常駐程式</string>
289+
<string name="restarting_rime">重新啟動 Rime</string>
288290
</resources>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,6 @@
286286
<string name="schedule_exact_alarm_permission_message">Without the permmission to schedule exact alarm, we are not able to sync your profile in time when you enable syncing on schedule.</string>
287287
<string name="notification_permission_title">No Notification Permission</string>
288288
<string name="notification_permission_message">Without the permission to post notifications, we are not able to notify you when some time-consuming operations are done.</string>
289+
<string name="rime_daemon">Rime Daemon</string>
290+
<string name="restarting_rime">Restarting Rime</string>
289291
</resources>

0 commit comments

Comments
 (0)