Sources/OrgstarMobile/UnsavedHeldFiles.swift

34f0b480a611c3278a48821f0233ba97462b13d1
orgstar/Sources/OrgstarMobile/UnsavedHeldFiles.swift

23 lines · 1019 bytes

 1import Foundation
 2
 3/// The files held for their passphrase when the app went to the background. iOS may end the
 4/// app there without asking, and their edits, kept only in memory, are lost: the next launch
 5/// says so.
 6enum UnsavedHeldFiles {
 7    static let key = "heldFilesInBackground"
 8
 9    static func record(_ paths: [String]) {
10        if paths.isEmpty {
11            UserDefaults.standard.removeObject(forKey: key)
12        } else {
13            UserDefaults.standard.set(paths.map { ($0 as NSString).lastPathComponent }, forKey: key)
14        }
15    }
16
17    /// The message for files whose edits were lost when the app last ended; read once, at launch.
18    static let atLaunch: String? = {
19        guard let names = UserDefaults.standard.stringArray(forKey: key), !names.isEmpty else { return nil }
20        UserDefaults.standard.removeObject(forKey: key)
21        return String(localized: "Edits to \(names.joined(separator: ", ")) weren't saved: they were waiting for a passphrase when orgstar was closed.")
22    }()
23}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form