@@ -15,8 +15,10 @@ import com.sameerasw.airsync.utils.WebSocketUtil
1515import kotlinx.coroutines.CoroutineScope
1616import kotlinx.coroutines.Dispatchers
1717import kotlinx.coroutines.SupervisorJob
18+ import kotlinx.coroutines.flow.first
1819import kotlinx.coroutines.launch
1920import kotlinx.coroutines.cancel
21+ import com.sameerasw.airsync.data.local.DataStoreManager
2022
2123@RequiresApi(Build .VERSION_CODES .N )
2224class ClipboardTileService : TileService () {
@@ -93,19 +95,27 @@ class ClipboardTileService : TileService() {
9395 // Removed direct sendClipboard method as it is now handled by the Activity
9496
9597 private fun updateTileState (isConnected : Boolean ) {
96- try {
97- qsTile?.apply {
98- state = if (isConnected) Tile .STATE_ACTIVE else Tile .STATE_INACTIVE
99- val labelText = if (isConnected) " Send Clipboard" else " Not Connected"
100- label = labelText
101-
102- // Using existing icon as placeholder
103- // icon = Icon.createWithResource(this@ClipboardTileService, R.drawable.ic_laptop_24)
104-
105- updateTile()
98+ serviceScope.launch {
99+ try {
100+ val dataStoreManager = DataStoreManager .getInstance(this @ClipboardTileService)
101+ val connectedDevice = dataStoreManager.getLastConnectedDevice().first()
102+ val deviceName = connectedDevice?.name ? : getString(R .string.your_mac)
103+
104+ qsTile?.apply {
105+ state = if (isConnected) Tile .STATE_ACTIVE else Tile .STATE_INACTIVE
106+
107+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
108+ subtitle = if (isConnected) deviceName else getString(R .string.disconnected)
109+ } else {
110+ val labelText = if (isConnected) " Send Clipboard ($deviceName )" else " Not Connected"
111+ label = labelText
112+ }
113+
114+ updateTile()
115+ }
116+ } catch (e: Exception ) {
117+ Log .e(TAG , " Error updating tile state" , e)
106118 }
107- } catch (e: Exception ) {
108- Log .e(TAG , " Error updating tile state" , e)
109119 }
110120 }
111121}
0 commit comments