()
| 1567 | } |
| 1568 | |
| 1569 | private func performBackupImport() async { |
| 1570 | do { |
| 1571 | let panel = NSOpenPanel() |
| 1572 | panel.canChooseDirectories = false |
| 1573 | panel.canChooseFiles = true |
| 1574 | panel.allowsMultipleSelection = false |
| 1575 | panel.allowedContentTypes = [.json] |
| 1576 | |
| 1577 | guard panel.runModal() == .OK, let url = panel.url else { return } |
| 1578 | |
| 1579 | let data = try Data(contentsOf: url) |
| 1580 | let document = try BackupService.shared.decode(data) |
| 1581 | |
| 1582 | let formatter = DateFormatter() |
| 1583 | formatter.dateStyle = .medium |
| 1584 | formatter.timeStyle = .short |
| 1585 | |
| 1586 | let confirm = NSAlert() |
| 1587 | confirm.messageText = "Import this backup?" |
| 1588 | confirm.informativeText = """ |
| 1589 | This replaces your current settings, prompt profiles, and stats history. |
| 1590 | |
| 1591 | Exported: \(formatter.string(from: document.exportedAt)) |
| 1592 | API keys are not included and will not be changed. |
| 1593 | """ |
| 1594 | confirm.alertStyle = .warning |
| 1595 | confirm.addButton(withTitle: "Import") |
| 1596 | confirm.addButton(withTitle: "Cancel") |
| 1597 | |
| 1598 | guard confirm.runModal() == .alertFirstButtonReturn else { return } |
| 1599 | |
| 1600 | try await BackupService.shared.restore(document) |
| 1601 | self.syncLocalSettingsAfterBackupRestore() |
| 1602 | |
| 1603 | self.presentInfoAlert( |
| 1604 | title: "Backup Imported", |
| 1605 | message: "Your settings, prompt profiles, and stats were restored successfully." |
| 1606 | ) |
| 1607 | } catch { |
| 1608 | self.presentErrorAlert( |
| 1609 | title: "Backup Import Failed", |
| 1610 | message: error.localizedDescription |
| 1611 | ) |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | private func syncLocalSettingsAfterBackupRestore() { |
| 1616 | self.shareAnonymousAnalytics = SettingsStore.shared.shareAnonymousAnalytics |
no test coverage detected