package com.taaazzz.photosync.bg import android.content.Intent import android.os.Build import expo.modules.kotlin.modules.Module import expo.modules.kotlin.modules.ModuleDefinition // Pont JS <-> natif : demarre/arrete le service de premier plan qui surveille la // galerie. Expose start()/stop() a JS (pilotes par l'interrupteur "Sauvegarde // automatique" dans l'app). class PhotoSyncBgModule : Module() { override fun definition() = ModuleDefinition { Name("PhotoSyncBg") Function("start") { val ctx = appContext.reactContext ?: return@Function false val intent = Intent(ctx, PhotoSyncObserverService::class.java) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) ctx.startForegroundService(intent) else ctx.startService(intent) true } Function("stop") { val ctx = appContext.reactContext ?: return@Function false ctx.stopService(Intent(ctx, PhotoSyncObserverService::class.java)) true } // Le JS pousse ici sa config (serveurs, token, regles resolues, wifiOnly) pour // que l'uploader natif puisse travailler seul en arriere-plan. Function("setConfig") { json: String -> val ctx = appContext.reactContext ?: return@Function false ctx.getSharedPreferences("photosync_bg", android.content.Context.MODE_PRIVATE) .edit().putString("config", json).apply() true } } }