Plugins are now a unified format for both sources and actions. Actions dictate what to do with a link and can now be added through a plugin JSON file. Backups have also been versioned to improve performance and add action support. Tags are used to give small amounts of information before a user installs a plugin. Signed-off-by: kingbri <bdashore3@proton.me>
75 lines
2.5 KiB
Swift
75 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 {
|
|
Task {
|
|
await backupManager.createBackup()
|
|
}
|
|
} label: {
|
|
Image(systemName: "plus")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct BackupsView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
BackupsView()
|
|
}
|
|
}
|