Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: automatic backup #2392

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions wire-ios-utilities/Source/DeveloperFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public enum DeveloperFlag: String, CaseIterable {
case debugDuplicateObjects
case decryptAndStoreEventsSleep
case forceCRLExpiryAfterOneMinute
case enablePerformBackupAction

public var description: String {
switch self {
Expand All @@ -52,6 +53,9 @@ public enum DeveloperFlag: String, CaseIterable {

case .forceCRLExpiryAfterOneMinute:
"Turn on to force CRLs to expire after 1 minute"

case .enablePerformBackupAction:
"Expose perform Backup Intent"
}
}

Expand Down Expand Up @@ -90,6 +94,8 @@ public enum DeveloperFlag: String, CaseIterable {
nil
case .ignoreIncomingEvents:
"IgnoreIncomingEventsEnabled"
case .enablePerformBackupAction:
"EnablePerformBackupAction"
}
}

Expand Down
8 changes: 8 additions & 0 deletions wire-ios/Wire-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
016DB6DF2C261A4900DEB81B /* WireDomain.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 016DB6DD2C261A4900DEB81B /* WireDomain.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
017ABBBB299542BA0004C243 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F1FDF2C521ADA3F000E037A1 /* Images.xcassets */; };
01874DD72C18581C00208716 /* DeveloperToolsContextItemsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01874DD62C18581C00208716 /* DeveloperToolsContextItemsProvider.swift */; };
01A1624B2D3710AA00A0F0D5 /* PerformBackupIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01A1624A2D3710AA00A0F0D5 /* PerformBackupIntent.swift */; };
01A1624D2D37168400A0F0D5 /* WireAppShorcuts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01A1624C2D37168400A0F0D5 /* WireAppShorcuts.swift */; };
01BC68512CE3AF9E00445243 /* EmptyConversationSearchResultsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01BC68502CE3AF9E00445243 /* EmptyConversationSearchResultsView.swift */; };
01BC68652CE496A500445243 /* EmptyPlaceholderContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01BC68642CE496A500445243 /* EmptyPlaceholderContainerView.swift */; };
01C1A7C72A54C45A0058D578 /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 01C1A7C62A54C45A0058D578 /* SnapshotTesting */; };
Expand Down Expand Up @@ -1972,6 +1974,8 @@
016BDDEF2AA0AE670054FB04 /* Developer-Flags.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Developer-Flags.xcconfig"; sourceTree = "<group>"; };
016DB6DD2C261A4900DEB81B /* WireDomain.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = WireDomain.framework; sourceTree = BUILT_PRODUCTS_DIR; };
01874DD62C18581C00208716 /* DeveloperToolsContextItemsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperToolsContextItemsProvider.swift; sourceTree = "<group>"; };
01A1624A2D3710AA00A0F0D5 /* PerformBackupIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerformBackupIntent.swift; sourceTree = "<group>"; };
01A1624C2D37168400A0F0D5 /* WireAppShorcuts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WireAppShorcuts.swift; sourceTree = "<group>"; };
01A5E047297FDAB500624B65 /* updateStylekit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = updateStylekit; sourceTree = "<group>"; };
01A5E048297FDAB500624B65 /* copyExtraAudioNotifications */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = copyExtraAudioNotifications; sourceTree = "<group>"; };
01BC68502CE3AF9E00445243 /* EmptyConversationSearchResultsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyConversationSearchResultsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6207,6 +6211,8 @@
F1141C961F5EB2DC005340B3 /* WireApplication.swift */,
5489E20D252C84BE0010461D /* AppStateCalculator.swift */,
543DF6AC25309641001F6EA6 /* AppRootRouter.swift */,
01A1624C2D37168400A0F0D5 /* WireAppShorcuts.swift */,
01A1624A2D3710AA00A0F0D5 /* PerformBackupIntent.swift */,
54B27985258113FD0043ED25 /* AuthenticatedRouter.swift */,
546EEA8C2536DDF500195097 /* URLActionRouter.swift */,
546EEA8E2536DFAB00195097 /* SwitchingAccountRouter.swift */,
Expand Down Expand Up @@ -9533,6 +9539,7 @@
87BEB0401D3E44E600DE9575 /* AssetCell.swift in Sources */,
E66258872B4D393400C23E79 /* DeveloperDebugActionsView.swift in Sources */,
A92CB35923CDF97800F12797 /* ConversationViewController+ConversationContentViewControllerDelegate.swift in Sources */,
01A1624B2D3710AA00A0F0D5 /* PerformBackupIntent.swift in Sources */,
0622D6A2265B38DE00D759DB /* UserBlockingReasonCell.swift in Sources */,
BFCCA4FE20A0A03D000A4F33 /* CallInfoRootViewController.swift in Sources */,
7C52F723200CBE61009F85FB /* CameraKeyboardPermissionsCell.swift in Sources */,
Expand Down Expand Up @@ -9595,6 +9602,7 @@
A90BECF124A23E6500E5C008 /* LinkViewDelegate.swift in Sources */,
A993719123F7461600881564 /* UIView+ExtendedBlockAnimations.swift in Sources */,
D550F57920445AD7009E09DD /* UIAlertController+ConversationGuestOptions.swift in Sources */,
01A1624D2D37168400A0F0D5 /* WireAppShorcuts.swift in Sources */,
E662588B2B4D3C9D00C23E79 /* DeveloperDebugActionsDisplayModel.swift in Sources */,
16D74BE82B573A1C00160298 /* AuthenticationE2EIdentityMissingErrorHandler.swift in Sources */,
871BC3601D34F94200DF0793 /* SettingsPropertyFactory.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions wire-ios/Wire-iOS/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
WireLogger.appDelegate
.info("application:didFinishLaunchingWithOptions END \(String(describing: launchOptions))")
WireLogger.appDelegate.info("Application was launched with arguments: \(ProcessInfo.processInfo.arguments)")

return true
}

Expand Down
71 changes: 71 additions & 0 deletions wire-ios/Wire-iOS/Sources/PerformBackupIntent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// Wire
// Copyright (C) 2025 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//


import AppIntents
import Foundation
import WireSyncEngine
import Intents
import UniformTypeIdentifiers

enum BackupError: Error, LocalizedError {
case emptyPassword

var errorDescription: String? {
switch self {
case .emptyPassword:
return "Password cannot be empty."
}
}
}

struct PerformBackupIntent: AppIntent {
static var title: LocalizedStringResource = "Perform Backup"

@Parameter(title: "Password")
var password: String

static var description: IntentDescription {
IntentDescription("Perform a backup with the provided password.")
}

func perform() async throws -> some ReturnsValue<IntentFile> {
if password.isEmpty {
throw BackupError.emptyPassword
}

let fileURL = try await withCheckedThrowingContinuation { continuation in
DispatchQueue.main.async {
SessionManager.shared?.backupActiveAccount(password: password) { result in
switch result {
case .success(let url):
continuation.resume(returning: url)
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}

return .result(
value: IntentFile(fileURL: fileURL,
filename: fileURL.lastPathComponent,
type: UTType("com.wire.backup-ios-underscore")!)
)
}
}
31 changes: 31 additions & 0 deletions wire-ios/Wire-iOS/Sources/WireAppShorcuts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Wire
// Copyright (C) 2025 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//

import AppIntents
import WireUtilities

struct WireAppShorcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
if DeveloperFlag.enablePerformBackupAction.isOn {
return [AppShortcut(intent: PerformBackupIntent(), phrases: ["Backup data with \(.applicationName)"])]
} else {
return []
}

}
}
Loading