Skip to content

Commit

Permalink
feat(mobile): Adds WiFi only backup option to iOS (#6724)
Browse files Browse the repository at this point in the history
Adds WiFi only backup option to iOS

Co-authored-by: Marty Fuhry <marty@fuhry.farm>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
  • Loading branch information
3 people authored Feb 8, 2024
1 parent e086476 commit 0d876a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions mobile/ios/Runner/BackgroundSync/BackgroundServicePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Flutter
import BackgroundTasks
import path_provider_foundation
import CryptoKit
import Network

class BackgroundServicePlugin: NSObject, FlutterPlugin {

Expand Down Expand Up @@ -335,8 +336,8 @@ class BackgroundServicePlugin: NSObject, FlutterPlugin {
defaults.set(Date().timeIntervalSince1970, forKey: "last_background_fetch_run_time")

// If we have required charging, we should check the charging status
let requireCharging = defaults.value(forKey: "require_charging") as? Bool
if (requireCharging ?? false) {
let requireCharging = defaults.value(forKey: "require_charging") as? Bool ?? false
if (requireCharging) {
UIDevice.current.isBatteryMonitoringEnabled = true
if (UIDevice.current.batteryState == .unplugged) {
// The device is unplugged and we have required charging
Expand All @@ -347,6 +348,20 @@ class BackgroundServicePlugin: NSObject, FlutterPlugin {
}
}

// If we have required Wi-Fi, we can check the isExpensive property
let requireWifi = defaults.value(forKey: "require_wifi") as? Bool ?? false
if (requireWifi) {
let wifiMonitor = NWPathMonitor(requiredInterfaceType: .wifi)
let isExpensive = wifiMonitor.currentPath.isExpensive
if (isExpensive) {
// The network is expensive and we have required Wi-Fi
// Therfore, we will simply complete the task without
// running it
task.setTaskCompleted(success: true)
return
}
}

// Schedule the next sync task so we can run this again later
scheduleBackgroundFetch()

Expand Down
2 changes: 1 addition & 1 deletion mobile/lib/modules/backup/views/backup_options_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class BackupOptionsPage extends HookConsumerWidget {
"backup_controller_page_background_description",
).tr(),
),
if (isBackgroundEnabled && Platform.isAndroid)
if (isBackgroundEnabled)
SwitchListTile.adaptive(
title: const Text("backup_controller_page_background_wifi")
.tr(),
Expand Down

0 comments on commit 0d876a4

Please sign in to comment.