package soy.iko.opencode.platform import android.app.PendingIntent import android.content.Intent import android.os.Build import android.service.quicksettings.TileService import soy.iko.opencode.MainActivity /** * Quick-settings tile that starts a new opencode session. Tapping launches [MainActivity] * with [MainActivity.ACTION_NEW_SESSION]; the app creates and opens a fresh session once * connected. On Android 14+ [startActivityAndCollapse] requires a PendingIntent. */ class NewSessionTileService : TileService() { override fun onClick() { super.onClick() val intent = Intent(this, MainActivity::class.java).apply { action = MainActivity.ACTION_NEW_SESSION addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP) } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { val pending = PendingIntent.getActivity( this, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT, ) startActivityAndCollapse(pending) } else { @Suppress("DEPRECATION", "StartActivityAndCollapseDeprecated") startActivityAndCollapse(intent) } } }