Backups in Ferrite archive a user's bookmarks, history, source lists, and source names. Sources are not archived due to the size of the backup increasing exponentially. These files use the .feb format to avoid JSON conflicts when opening the file in Ferrite. The backup file can be renamed to JSON for editing at any time. Add the Backport namespace to be used for ported features rather than making a file for every iOS 14 adaptation. Move history and bookmark creation to the PersistenceController rather than individual functions. Signed-off-by: kingbri <bdashore3@proton.me>
73 lines
2.5 KiB
Swift
73 lines
2.5 KiB
Swift
//
|
|
// BackupsView.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 9/16/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct BackupsView: View {
|
|
@EnvironmentObject var backupManager: BackupManager
|
|
@EnvironmentObject var navModel: NavigationViewModel
|
|
|
|
@State private var selectedBackupUrl: URL?
|
|
@State private var showRestoreAlert = false
|
|
@State private var showRestoreCompletedAlert = false
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
if backupManager.backupUrls.isEmpty {
|
|
EmptyInstructionView(title: "No Backups", message: "Create one using the + button in the top-right")
|
|
} else {
|
|
List {
|
|
ForEach(backupManager.backupUrls, id: \.self) { url in
|
|
Button(url.lastPathComponent) {
|
|
backupManager.selectedBackupUrl = url
|
|
backupManager.showRestoreAlert.toggle()
|
|
}
|
|
.contextMenu {
|
|
Button {
|
|
navModel.activityItems = [url]
|
|
navModel.currentChoiceSheet = .activity
|
|
} label: {
|
|
Label("Export", systemImage: "square.and.arrow.up")
|
|
}
|
|
}
|
|
.backport.tint(.primary)
|
|
}
|
|
.onDelete { offsets in
|
|
for index in offsets {
|
|
if let url = backupManager.backupUrls[safe: index] {
|
|
backupManager.removeBackup(backupUrl: url, index: index)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.inlinedList()
|
|
.listStyle(.insetGrouped)
|
|
}
|
|
}
|
|
.onAppear {
|
|
backupManager.backupUrls = FileManager.default.appDirectory
|
|
.appendingPathComponent("Backups", isDirectory: true).contentsByDateAdded
|
|
}
|
|
.navigationTitle("Backups")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
Button {
|
|
backupManager.createBackup()
|
|
} label: {
|
|
Image(systemName: "plus")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct BackupsView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
BackupsView()
|
|
}
|
|
}
|