Skip to content
Snippets Groups Projects

Account recovery/backup feature

9 files
+ 129
22
Compare changes
  • Side-by-side
  • Inline

Files

@@ -7,6 +7,7 @@ import DependencyInjection
import iCloudFeature
import DropboxFeature
import GoogleDriveFeature
import NetworkMonitor
public struct BackupService {
var backup: () -> Void
@@ -25,11 +26,13 @@ extension BackupService {
@Dependency var icloudService: iCloudInterface
@Dependency var dropboxService: DropboxInterface
@Dependency var driveService: GoogleDriveInterface
@Dependency var networkManager: NetworkMonitoring
@KeyObject(.backupSettings, defaultValue: Data()) var storedSettings: Data
lazy var settings = CurrentValueSubject<BackupSettings, Never>(.init(fromData: storedSettings))
var connType: ConnectionType = .wifi
var settingsLastRefreshedDate: Date?
var cancellables = Set<AnyCancellable>()
@@ -39,6 +42,11 @@ extension BackupService {
.removeDuplicates()
.sink { [unowned self] in storedSettings = $0.toData() }
.store(in: &cancellables)
networkManager.connType
.receive(on: DispatchQueue.main)
.sink { [unowned self] in connType = $0 }
.store(in: &cancellables)
}
func refreshConnections() {
@@ -226,9 +234,22 @@ extension BackupService {
fatalError("Couldn't write backup to fileurl")
}
let isWifiOnly = context.settings.value.wifiOnlyBackup
let isAutomaticEnabled = context.settings.value.automaticBackups
let hasEnabledService = context.settings.value.enabledService != nil
if isWifiOnly {
guard context.connType == .wifi else {
print(">>> A BACKUP WOULD START BUT IS WIFI ONLY AND CONN TYPE IS: \(context.connType)")
return
}
} else {
guard context.connType != .unknown else {
print(">>> A BACKUP WOULD START BUT ALTOUGH IT IS NOT WIFI ONLY, CONN TYPE IS: \(context.connType)")
return
}
}
if isAutomaticEnabled && hasEnabledService {
context.performBackup()
}
@@ -275,8 +296,12 @@ extension BackupService {
context.refreshBackups()
}).eraseToAnyPublisher()
},
setWifiOnly: { context.settings.value.wifiOnlyBackup = $0 },
setAutomatic: { context.settings.value.automaticBackups = $0 }
setWifiOnly: {
context.settings.value.wifiOnlyBackup = $0
},
setAutomatic: {
context.settings.value.automaticBackups = $0
}
)
}
}
Loading