From 4ff58f8756dd9b40f18d35695b9c26263ba0b621 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 14 May 2026 16:03:13 +0300 Subject: [PATCH] Hook up client pausing and resuming next to sync starting and stopping for nightly and debug builds. This will hopefully close all file descriptors and prevent the system from killing the app in the background. Reported in https://github.com/matrix-org/matrix-rust-sdk/issues/6366 and implemented in https://github.com/matrix-org/matrix-rust-sdk/pull/6495 --- .../Application/Settings/AppSettings.swift | 4 ++++ .../Sources/Services/Client/ClientProxy.swift | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/ElementX/Sources/Application/Settings/AppSettings.swift b/ElementX/Sources/Application/Settings/AppSettings.swift index addf461e2..82a37cc7e 100644 --- a/ElementX/Sources/Application/Settings/AppSettings.swift +++ b/ElementX/Sources/Application/Settings/AppSettings.swift @@ -81,6 +81,7 @@ final class AppSettings { case focusEventOnNotificationTap case linkNewDeviceEnabled case automaticBackPaginationEnabled + case clientPausingAndResumingEnabled // Doug's tweaks 🔧 case roomListActivityVisibility @@ -448,6 +449,9 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.automaticBackPaginationEnabled, defaultValue: false, storageType: .userDefaults(store)) var automaticBackPaginationEnabled + @UserPreference(key: UserDefaultsKeys.clientPausingAndResumingEnabled, defaultValue: appBuildType != .release, storageType: .volatile) + var clientPausingAndResumingEnabled + @UserPreference(key: UserDefaultsKeys.developerOptionsEnabled, defaultValue: appBuildType != .release, storageType: .userDefaults(store)) var developerOptionsEnabled } diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index 1ff29d450..dbcb037ce 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -403,6 +403,14 @@ class ClientProxy: ClientProxyProtocol { MXLog.info("Starting sync") Task { + if appSettings.clientPausingAndResumingEnabled { + do { + try await client.resume() + } catch { + MXLog.error("Failed resuming client with error: \(error)") + } + } + await syncService.start() // If we are using OAuth we want to cache the account management URL in volatile memory on the SDK side. @@ -454,6 +462,15 @@ class ClientProxy: ClientProxyProtocol { } await syncService.stop() + + if appSettings.clientPausingAndResumingEnabled { + do { + try await client.pause() + } catch { + MXLog.error("Failed pausing client with error: \(error)") + } + } + MXLog.info("Sync stopped") } }