SPB Git

Repository Public

Settings.swift 3.4 KB 46 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: App/Settings.swift3// Description: The person's preferences (Finder integration, notifications, bandwidth limits, parallel transfers, biometric lock), kept in the shared defaults.4import Foundation5import Observation67@MainActor @Observable final class AppSettings {8    private let d = AppEnvironment.defaults9    private func bool(_ k: String, _ def: Bool) -> Bool { d.object(forKey: k) == nil ? def : d.bool(forKey: k) }1011    /// SP Drive appears as a location in the Finder.12    var finderIntegration: Bool { didSet { d.set(finderIntegration, forKey: "finderIntegration") } }13    var notifyTransfers: Bool { didSet { d.set(notifyTransfers, forKey: "notifyTransfers") } }14    var notifyConflicts: Bool { didSet { d.set(notifyConflicts, forKey: "notifyConflicts") } }15    var notifyDeposits: Bool { didSet { d.set(notifyDeposits, forKey: "notifyDeposits") } }16    /// Kilobytes per second; 0 = no limit.17    var uploadLimitKB: Int { didSet { d.set(uploadLimitKB, forKey: "uploadLimitKB") } }18    var downloadLimitKB: Int { didSet { d.set(downloadLimitKB, forKey: "downloadLimitKB") } }19    /// 0 = adapt to the measured link.20    var parallelTransfers: Int { didSet { d.set(parallelTransfers, forKey: "parallelTransfers") } }21    /// Ask for Touch ID (or the Mac's password) to show the window.22    var biometricLock: Bool { didSet { d.set(biometricLock, forKey: "biometricLock") } }23    var syncPaused: Bool { didSet { d.set(syncPaused, forKey: "syncPaused") } }24    var showMenuBarIcon: Bool { didSet { d.set(showMenuBarIcon, forKey: "showMenuBarIcon") } }25    var gridView: Bool { didSet { d.set(gridView, forKey: "gridView") } }26    /// Low Power Mode and a low battery slow transfers down and hold background ones.27    var respectPower: Bool { didSet { d.set(respectPower, forKey: "respectPower") } }28    /// Floating drop zone on the desktop (off by default) and where its files go (nil = root of Mon Drive).29    var dropZone: Bool { didSet { d.set(dropZone, forKey: "dropZone") } }30    var dropZoneFolderID: String? { didSet { d.set(dropZoneFolderID, forKey: "dropZoneFolderID") } }31    /// Names, kinds and dates of items indexed in Spotlight (never content). Off by default.32    var spotlightIndex: Bool { didSet { d.set(spotlightIndex, forKey: "spotlightIndex") } }33    /// Grid cell size step (0 small, 1 medium, 2 large).34    var gridSize: Int { didSet { d.set(gridSize, forKey: "gridSize") } }3536    init() {37        let d = AppEnvironment.defaults38        func b(_ k: String, _ def: Bool) -> Bool { d.object(forKey: k) == nil ? def : d.bool(forKey: k) }39        finderIntegration = b("finderIntegration", true); notifyTransfers = b("notifyTransfers", true); notifyConflicts = b("notifyConflicts", true); notifyDeposits = b("notifyDeposits", true)40        uploadLimitKB = d.integer(forKey: "uploadLimitKB"); downloadLimitKB = d.integer(forKey: "downloadLimitKB"); parallelTransfers = d.integer(forKey: "parallelTransfers")41        biometricLock = b("biometricLock", false); syncPaused = b("syncPaused", false); showMenuBarIcon = b("showMenuBarIcon", true); gridView = b("gridView", false)42        respectPower = b("respectPower", true); dropZone = b("dropZone", false); dropZoneFolderID = d.string(forKey: "dropZoneFolderID"); spotlightIndex = b("spotlightIndex", false)43        gridSize = d.object(forKey: "gridSize") == nil ? 1 : d.integer(forKey: "gridSize")44    }45}46
Files main
Menu

Theme