mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
feat(mobile): Adds WiFi only backup option to iOS (#6724)
Adds WiFi only backup option to iOS Co-authored-by: Marty Fuhry <marty@fuhry.farm> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
e0864768c2
commit
0d876a470f
2 changed files with 18 additions and 3 deletions
|
@ -9,6 +9,7 @@ import Flutter
|
||||||
import BackgroundTasks
|
import BackgroundTasks
|
||||||
import path_provider_foundation
|
import path_provider_foundation
|
||||||
import CryptoKit
|
import CryptoKit
|
||||||
|
import Network
|
||||||
|
|
||||||
class BackgroundServicePlugin: NSObject, FlutterPlugin {
|
class BackgroundServicePlugin: NSObject, FlutterPlugin {
|
||||||
|
|
||||||
|
@ -335,8 +336,8 @@ class BackgroundServicePlugin: NSObject, FlutterPlugin {
|
||||||
defaults.set(Date().timeIntervalSince1970, forKey: "last_background_fetch_run_time")
|
defaults.set(Date().timeIntervalSince1970, forKey: "last_background_fetch_run_time")
|
||||||
|
|
||||||
// If we have required charging, we should check the charging status
|
// If we have required charging, we should check the charging status
|
||||||
let requireCharging = defaults.value(forKey: "require_charging") as? Bool
|
let requireCharging = defaults.value(forKey: "require_charging") as? Bool ?? false
|
||||||
if (requireCharging ?? false) {
|
if (requireCharging) {
|
||||||
UIDevice.current.isBatteryMonitoringEnabled = true
|
UIDevice.current.isBatteryMonitoringEnabled = true
|
||||||
if (UIDevice.current.batteryState == .unplugged) {
|
if (UIDevice.current.batteryState == .unplugged) {
|
||||||
// The device is unplugged and we have required charging
|
// The device is unplugged and we have required charging
|
||||||
|
@ -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
|
// Schedule the next sync task so we can run this again later
|
||||||
scheduleBackgroundFetch()
|
scheduleBackgroundFetch()
|
||||||
|
|
||||||
|
|
|
@ -264,7 +264,7 @@ class BackupOptionsPage extends HookConsumerWidget {
|
||||||
"backup_controller_page_background_description",
|
"backup_controller_page_background_description",
|
||||||
).tr(),
|
).tr(),
|
||||||
),
|
),
|
||||||
if (isBackgroundEnabled && Platform.isAndroid)
|
if (isBackgroundEnabled)
|
||||||
SwitchListTile.adaptive(
|
SwitchListTile.adaptive(
|
||||||
title: const Text("backup_controller_page_background_wifi")
|
title: const Text("backup_controller_page_background_wifi")
|
||||||
.tr(),
|
.tr(),
|
||||||
|
|
Loading…
Reference in a new issue