Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 66d28761a8 | |||
| ec478531da |
@@ -23,6 +23,8 @@ import com.syncflow.data.db.SyncPairDao
|
|||||||
import com.syncflow.domain.model.ScheduleType
|
import com.syncflow.domain.model.ScheduleType
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -35,6 +37,8 @@ class FileWatchService : Service() {
|
|||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||||
private val mainHandler = Handler(Looper.getMainLooper())
|
private val mainHandler = Handler(Looper.getMainLooper())
|
||||||
|
// Prevents concurrent refresh() calls from doubling watchers + catchup scans
|
||||||
|
private val refreshMutex = Mutex()
|
||||||
|
|
||||||
// Multiple FileObserver instances per pair: one per directory (recursive)
|
// Multiple FileObserver instances per pair: one per directory (recursive)
|
||||||
private val fileObservers = mutableMapOf<Long, MutableList<FileObserver>>()
|
private val fileObservers = mutableMapOf<Long, MutableList<FileObserver>>()
|
||||||
@@ -81,7 +85,7 @@ class FileWatchService : Service() {
|
|||||||
|
|
||||||
override fun onBind(intent: Intent?): IBinder? = null
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
|
|
||||||
private suspend fun refresh() {
|
private suspend fun refresh() = refreshMutex.withLock {
|
||||||
clearWatchers()
|
clearWatchers()
|
||||||
val pairs = syncPairDao.getEnabled().filter { it.scheduleType == ScheduleType.ON_CHANGE }
|
val pairs = syncPairDao.getEnabled().filter { it.scheduleType == ScheduleType.ON_CHANGE }
|
||||||
|
|
||||||
@@ -145,6 +149,9 @@ class FileWatchService : Service() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
fileObservers[pairId] = mutableListOf()
|
fileObservers[pairId] = mutableListOf()
|
||||||
|
// Set startup cooldown BEFORE registering watchers so inotify events that fire
|
||||||
|
// immediately on registration don't trigger the debounce before catchupScan runs.
|
||||||
|
syncCooldownUntil[pairId] = System.currentTimeMillis() + 15_000
|
||||||
watchDirRecursive(dir, pairId, wifiOnly, chargingOnly)
|
watchDirRecursive(dir, pairId, wifiOnly, chargingOnly)
|
||||||
Timber.d("FileWatchService: watching pair $pairId at $path (${fileObservers[pairId]?.size} dirs)")
|
Timber.d("FileWatchService: watching pair $pairId at $path (${fileObservers[pairId]?.size} dirs)")
|
||||||
scope.launch { catchupScan(pairId, dir, wifiOnly, chargingOnly) }
|
scope.launch { catchupScan(pairId, dir, wifiOnly, chargingOnly) }
|
||||||
@@ -203,12 +210,26 @@ class FileWatchService : Service() {
|
|||||||
if (hasNew || hasModified || hasDeleted) {
|
if (hasNew || hasModified || hasDeleted) {
|
||||||
Timber.d("FileWatchService: catchup detected changes for pair $pairId, scheduling sync")
|
Timber.d("FileWatchService: catchup detected changes for pair $pairId, scheduling sync")
|
||||||
val pair = syncPairDao.getById(pairId) ?: return
|
val pair = syncPairDao.getById(pairId) ?: return
|
||||||
|
// Cancel any debounce that started before our startup cooldown was set
|
||||||
|
debounceJobs[pairId]?.cancel()
|
||||||
|
debounceJobs.remove(pairId)
|
||||||
|
// Hold cooldown for duration of sync + 60s settle
|
||||||
|
syncCooldownUntil[pairId] = System.currentTimeMillis() + 120_000
|
||||||
|
val req = SyncWorker.buildOneTimeRequest(pairId, wifiOnly, chargingOnly)
|
||||||
WorkManager.getInstance(applicationContext)
|
WorkManager.getInstance(applicationContext)
|
||||||
.enqueueUniqueWork(
|
.enqueueUniqueWork("catchup_$pairId", ExistingWorkPolicy.KEEP, req)
|
||||||
"catchup_$pairId",
|
scope.launch {
|
||||||
ExistingWorkPolicy.KEEP,
|
try {
|
||||||
SyncWorker.buildOneTimeRequest(pairId, wifiOnly, chargingOnly),
|
WorkManager.getInstance(applicationContext)
|
||||||
)
|
.getWorkInfoByIdFlow(req.id)
|
||||||
|
.first { it?.state?.isFinished == true }
|
||||||
|
syncCooldownUntil[pairId] = System.currentTimeMillis() + 60_000
|
||||||
|
} catch (e: CancellationException) {
|
||||||
|
throw e
|
||||||
|
} catch (_: Exception) {
|
||||||
|
syncCooldownUntil[pairId] = System.currentTimeMillis() + 60_000
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +244,12 @@ class FileWatchService : Service() {
|
|||||||
debounceJobs[pairId]?.cancel()
|
debounceJobs[pairId]?.cancel()
|
||||||
debounceJobs[pairId] = scope.launch {
|
debounceJobs[pairId] = scope.launch {
|
||||||
delay(5_000)
|
delay(5_000)
|
||||||
|
// Re-check: catchupScan or another path may have already set a cooldown
|
||||||
|
// and handled this sync while we were waiting.
|
||||||
|
if (System.currentTimeMillis() < (syncCooldownUntil[pairId] ?: 0L)) {
|
||||||
|
Timber.d("FileWatchService: debounce fired but cooldown active for pair $pairId, skipping")
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
val pair = syncPairDao.getById(pairId)
|
val pair = syncPairDao.getById(pairId)
|
||||||
if (pair == null || !pair.isEnabled) return@launch
|
if (pair == null || !pair.isEnabled) return@launch
|
||||||
Timber.d("FileWatchService: triggering sync for pair $pairId after debounce")
|
Timber.d("FileWatchService: triggering sync for pair $pairId after debounce")
|
||||||
@@ -253,8 +280,10 @@ class FileWatchService : Service() {
|
|||||||
}
|
}
|
||||||
delay(12_000)
|
delay(12_000)
|
||||||
updateNotificationDynamic(null)
|
updateNotificationDynamic(null)
|
||||||
|
} catch (e: CancellationException) {
|
||||||
|
throw e
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
syncCooldownUntil[pairId] = 0L
|
syncCooldownUntil[pairId] = System.currentTimeMillis() + 60_000
|
||||||
updateNotificationDynamic(null)
|
updateNotificationDynamic(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:aapt="http://schemas.android.com/aapt"
|
|
||||||
android:width="108dp"
|
android:width="108dp"
|
||||||
android:height="108dp"
|
android:height="108dp"
|
||||||
android:viewportWidth="108"
|
android:viewportWidth="108"
|
||||||
android:viewportHeight="108">
|
android:viewportHeight="108">
|
||||||
|
|
||||||
<!-- Dark charcoal background, matching Avast-style dark icon bg -->
|
<!-- Pure black background -->
|
||||||
<path android:pathData="M0,0 H108 V108 H0 Z"
|
<path android:pathData="M0,0 H108 V108 H0 Z"
|
||||||
android:fillColor="#1F1F2E"/>
|
android:fillColor="#000000"/>
|
||||||
|
|
||||||
<!-- Very subtle inner glow -->
|
|
||||||
<path android:pathData="M0,0 H108 V108 H0 Z"
|
|
||||||
android:fillAlpha="0.25">
|
|
||||||
<aapt:attr name="android:fillColor">
|
|
||||||
<gradient android:type="radial"
|
|
||||||
android:gradientRadius="60"
|
|
||||||
android:centerX="54" android:centerY="50"
|
|
||||||
android:startColor="#3D3A50"
|
|
||||||
android:endColor="#00000000"/>
|
|
||||||
</aapt:attr>
|
|
||||||
</path>
|
|
||||||
|
|
||||||
</vector>
|
</vector>
|
||||||
|
|||||||
@@ -1,67 +1,84 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
|
||||||
SyncFlow icon foreground.
|
|
||||||
Three bold teardrop shapes in Avast-palette colors (teal, red, amber),
|
|
||||||
tips meeting at center (54,54), wide heads pointing outward at 0/120/240 deg.
|
|
||||||
White cloud centred over the intersection point.
|
|
||||||
-->
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:width="108dp"
|
android:width="108dp"
|
||||||
android:height="108dp"
|
android:height="108dp"
|
||||||
android:viewportWidth="108"
|
android:viewportWidth="108"
|
||||||
android:viewportHeight="108">
|
android:viewportHeight="108">
|
||||||
|
|
||||||
<!-- Teal teardrop — head pointing straight up -->
|
<!--
|
||||||
<group android:rotation="0"
|
Four thick arcs arranged as an interlocked pinwheel.
|
||||||
android:pivotX="54"
|
Each arc sweeps ~210 degrees, rounded caps, radius 18 from center (54,54).
|
||||||
android:pivotY="54">
|
Draw order creates natural over/under at the four crossing points:
|
||||||
<path
|
blue under green, green under red, red under orange, orange under blue (re-draw blue tip).
|
||||||
android:fillColor="#00C4A7"
|
|
||||||
android:pathData="M 54,57 C 50,57 38,52 34,41 C 30,30 38,20 54,20 C 70,20 78,30 74,41 C 70,52 58,57 54,57 Z"/>
|
|
||||||
</group>
|
|
||||||
|
|
||||||
<!-- Red teardrop — head pointing lower-right (120 deg CW from up) -->
|
Arc endpoints computed at radius 18, sweep 210 deg clockwise:
|
||||||
<group android:rotation="120"
|
start angle end angle start point end point
|
||||||
android:pivotX="54"
|
270 (top) 120 (54, 36) (45, 70)
|
||||||
android:pivotY="54">
|
0 (right) 210 (72, 54) (39, 45)
|
||||||
<path
|
90 (bot) 300 (54, 72) (63, 38)
|
||||||
android:fillColor="#F44336"
|
180 (left) 390=30 (36, 54) (69, 63)
|
||||||
android:pathData="M 54,57 C 50,57 38,52 34,41 C 30,30 38,20 54,20 C 70,20 78,30 74,41 C 70,52 58,57 54,57 Z"/>
|
-->
|
||||||
</group>
|
|
||||||
|
|
||||||
<!-- Amber teardrop — head pointing lower-left (240 deg CW from up) -->
|
<!-- Blue — starts at top, sweeps clockwise to lower-left -->
|
||||||
<group android:rotation="240"
|
<path
|
||||||
android:pivotX="54"
|
android:strokeColor="#2979FF"
|
||||||
android:pivotY="54">
|
android:strokeWidth="8.5"
|
||||||
<path
|
android:fillColor="#00000000"
|
||||||
android:fillColor="#FFC107"
|
android:strokeLineCap="round"
|
||||||
android:pathData="M 54,57 C 50,57 38,52 34,41 C 30,30 38,20 54,20 C 70,20 78,30 74,41 C 70,52 58,57 54,57 Z"/>
|
android:pathData="M 54,36 A 18,18 0 1,1 45,70"/>
|
||||||
</group>
|
|
||||||
|
|
||||||
<!-- White cloud centred at (54,52), sits over the teardrop intersection -->
|
<!-- Green — starts at bottom, sweeps clockwise to upper-right -->
|
||||||
|
<path
|
||||||
|
android:strokeColor="#00C853"
|
||||||
|
android:strokeWidth="8.5"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:pathData="M 54,72 A 18,18 0 1,1 63,38"/>
|
||||||
|
|
||||||
|
<!-- Red — starts at right, sweeps clockwise to lower-left -->
|
||||||
|
<path
|
||||||
|
android:strokeColor="#E53935"
|
||||||
|
android:strokeWidth="8.5"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:pathData="M 72,54 A 18,18 0 1,1 39,45"/>
|
||||||
|
|
||||||
|
<!-- Orange — starts at left, sweeps clockwise to upper-right -->
|
||||||
|
<path
|
||||||
|
android:strokeColor="#FF6D00"
|
||||||
|
android:strokeWidth="8.5"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:pathData="M 36,54 A 18,18 0 1,1 69,63"/>
|
||||||
|
|
||||||
|
<!-- Re-draw blue start cap on top so it goes OVER orange end -->
|
||||||
|
<path
|
||||||
|
android:strokeColor="#2979FF"
|
||||||
|
android:strokeWidth="8.5"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:pathData="M 54,36 A 18,18 0 0,1 62,37.5"/>
|
||||||
|
|
||||||
|
<!-- White sync circle at center -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#000000"
|
||||||
|
android:pathData="M 45,54 A 9,9 0 1,0 63,54 A 9,9 0 1,0 45,54 Z"/>
|
||||||
|
|
||||||
|
<!-- Sync ring -->
|
||||||
|
<path
|
||||||
|
android:strokeColor="#FFFFFF"
|
||||||
|
android:strokeWidth="2.5"
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M 46.5,54 A 7.5,7.5 0 1,0 61.5,54 A 7.5,7.5 0 1,0 46.5,54 Z"/>
|
||||||
|
|
||||||
|
<!-- Top arrow head (pointing up) -->
|
||||||
<path
|
<path
|
||||||
android:fillColor="#FFFFFF"
|
android:fillColor="#FFFFFF"
|
||||||
android:pathData="
|
android:pathData="M 54,46.5 L 57,50.5 L 51,50.5 Z"/>
|
||||||
M 42,62
|
|
||||||
A 8,8 0 0,1 42,46
|
|
||||||
A 8,8 0 0,1 51,39
|
|
||||||
A 11,11 0 0,1 67,42
|
|
||||||
A 7,7 0 0,1 68,56
|
|
||||||
A 7,7 0 0,1 66,62
|
|
||||||
Z"/>
|
|
||||||
|
|
||||||
<!-- Cloud inner shadow to make it pop from the coloured teardrops -->
|
<!-- Bottom arrow head (pointing down) -->
|
||||||
<path
|
<path
|
||||||
android:fillColor="#00000000"
|
android:fillColor="#FFFFFF"
|
||||||
android:strokeColor="#18000000"
|
android:pathData="M 54,61.5 L 51,57.5 L 57,57.5 Z"/>
|
||||||
android:strokeWidth="1.5"
|
|
||||||
android:pathData="
|
|
||||||
M 42,62
|
|
||||||
A 8,8 0 0,1 42,46
|
|
||||||
A 8,8 0 0,1 51,39
|
|
||||||
A 11,11 0 0,1 67,42
|
|
||||||
A 7,7 0 0,1 68,56
|
|
||||||
A 7,7 0 0,1 66,62
|
|
||||||
Z"/>
|
|
||||||
|
|
||||||
</vector>
|
</vector>
|
||||||
|
|||||||
+2
-2
@@ -1,2 +1,2 @@
|
|||||||
VERSION_NAME=1.0.29
|
VERSION_NAME=1.0.31
|
||||||
VERSION_CODE=30
|
VERSION_CODE=32
|
||||||
|
|||||||
Reference in New Issue
Block a user