mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-11 02:51:11 +00:00
Refactoring
This commit is contained in:
1 parent
093390084f
commit
d46b62d3de
10 files changed
+35
-63
No files matched your search
@@ -5,8 +5,9 @@
|
||||
// Created by Leon Böttger on 04.04.25.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CryptoKit
|
||||
import Foundation
|
||||
import LUI
|
||||
|
||||
extension Data {
|
||||
func urlSafeBase64EncodedString() -> String {
|
||||
@@ -111,7 +112,11 @@ extension String {
|
||||
|
||||
|
||||
public func fullVersion() -> Bool {
|
||||
return Settings.sharedInstance.gotPlus
|
||||
#if GITHUB
|
||||
return true
|
||||
#else
|
||||
return IAPManager.sharedInstance.plusVersionState
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1739,8 +1739,8 @@
|
||||
MTL_FAST_MATH = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
SHARED_BUILD = 126;
|
||||
SHARED_VERSION = 2.13.1;
|
||||
SHARED_BUILD = 128;
|
||||
SHARED_VERSION = 2.13.2;
|
||||
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
@@ -1802,8 +1802,8 @@
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
SDKROOT = macosx;
|
||||
SHARED_BUILD = 126;
|
||||
SHARED_VERSION = 2.13.1;
|
||||
SHARED_BUILD = 128;
|
||||
SHARED_VERSION = 2.13.2;
|
||||
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
||||
SWIFT_COMPILATION_MODE = wholemodule;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
"location" : "https://github.com/leonboe1/LUI.git",
|
||||
"state" : {
|
||||
"branch" : "main",
|
||||
"revision" : "24e35e2829f478d4219e82921302321dae6c1e78"
|
||||
"revision" : "b1be835c12befddc3c5f678837a766d51db1bdc5"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -87,8 +87,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-protobuf.git",
|
||||
"state" : {
|
||||
"revision" : "9bbb079b69af9d66470ced85461bf13bb40becac",
|
||||
"version" : "1.35.0"
|
||||
"revision" : "5596511fce902e649c403cd4d6d5da1254f142b7",
|
||||
"version" : "1.35.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -26,7 +26,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
||||
private var sheetAttachedWindow: NSWindow? = nil
|
||||
private var errorAlertHandler = ErrorAlertHandler.shared
|
||||
|
||||
private var iapManager: IAPManager?
|
||||
private var receiveModel: ReceiveModel?
|
||||
|
||||
var showsFirewallAlert = false
|
||||
@@ -35,11 +34,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
||||
|
||||
// MARK: NSApplicationDelegate functions
|
||||
|
||||
func applicationWillFinishLaunching(_: Notification) {
|
||||
LUIInit(configuration: configuration)
|
||||
}
|
||||
|
||||
|
||||
func applicationDidFinishLaunching(_: Notification) {
|
||||
|
||||
let menu = NSMenu()
|
||||
@@ -72,27 +66,26 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
||||
statusItem?.button?.image = NSImage(named: "MenuBarIcon")
|
||||
statusItem?.menu = menu
|
||||
statusItem?.behavior = .removalAllowed
|
||||
|
||||
iapManager = IAPManager.sharedInstance
|
||||
|
||||
|
||||
// app did not lauch before
|
||||
if !Settings.sharedInstance.appLaunchedBefore {
|
||||
log("[AppDelegate] Opening Welcome Screen")
|
||||
// open welcome screen
|
||||
openMainWindow()
|
||||
|
||||
DispatchQueue.main.async {
|
||||
// open welcome screen in next cycle (await LUIInit)
|
||||
self.openMainWindow()
|
||||
}
|
||||
|
||||
// user installed the app after the IAP was implemented, set the user as eligible for IAP
|
||||
Settings.sharedInstance.isEligibleForIap = true
|
||||
} else {
|
||||
// app launched before
|
||||
|
||||
#if GITHUB
|
||||
log("[AppDelegate] Downloaded from GitHub.")
|
||||
#else
|
||||
// user installed the app before the IAP was implemented, grant the plus version
|
||||
if !Settings.sharedInstance.isEligibleForIap {
|
||||
log("[AppDelegate] Granting QuickDrop+ for old user")
|
||||
Settings.sharedInstance.gotPlus = true
|
||||
UserDefaults.standard.set(true, forKey: Settings.UserDefaultsKeys.plusVersionLegacy.rawValue)
|
||||
} else {
|
||||
if !fullVersion() {
|
||||
@@ -109,6 +102,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
||||
// only start receiving immediately for existing user, for new users we want to delay the permission prompt
|
||||
startReceiving()
|
||||
}
|
||||
|
||||
LUIInit(configuration: configuration)
|
||||
|
||||
UNUserNotificationCenter.current().delegate = self
|
||||
|
||||
|
||||
@@ -13,14 +13,6 @@ let configuration = LUIConfiguration(
|
||||
|
||||
plusVersionInfo: GetPlusViewInformation(lifetimeID: "plusversion", monthlyID: "quickdrop.monthly", yearlyID: "quickdrop.yearly", plusViewHeader: isMac() ? "plusview_title" : nil, description: isMac() ? "plusview_description" : "plusview_description_phone", onBoughtPlusVersionAlertMessage: "plusview_success_description", plusVersionFeatures: [], settingsLabelColor: .orange, settingsFooter: "plusview_footer_phone"),
|
||||
|
||||
setPlusVersion: { result in
|
||||
#if !GITHUB
|
||||
DispatchQueue.main.async {
|
||||
Settings.sharedInstance.gotPlus = result
|
||||
}
|
||||
#endif
|
||||
},
|
||||
|
||||
hasRoundedFont: false,
|
||||
|
||||
switchedToIAPafterBundleVersion: AppVersionBundle(appVersion: "1.2", buildVersion: 0, legacyUserDefaultsKey: Settings.UserDefaultsKeys.plusVersionLegacy.rawValue),
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "new",
|
||||
"value" : "QuickDropGitHub"
|
||||
"value" : "QuickDrop"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -17,14 +17,6 @@ final class Settings: SharedInstance {
|
||||
|
||||
// MARK: - Published UserDefaults Backed Properties
|
||||
|
||||
#if GITHUB
|
||||
let gotPlus = true
|
||||
#else
|
||||
@Published var gotPlus = UserDefaults.standard.bool(forKey: UserDefaultsKeys.plusVersion.rawValue)
|
||||
{ didSet { UserDefaults.standard.set(gotPlus, forKey: UserDefaultsKeys.plusVersion.rawValue) }}
|
||||
#endif
|
||||
|
||||
|
||||
@Published var automaticallyAcceptFiles: Bool = UserDefaults.standard.bool(forKey: UserDefaultsKeys.automaticallyAcceptFiles.rawValue)
|
||||
{ didSet { UserDefaults.standard.set(automaticallyAcceptFiles, forKey: UserDefaultsKeys.automaticallyAcceptFiles.rawValue) }}
|
||||
|
||||
@@ -76,7 +68,6 @@ final class Settings: SharedInstance {
|
||||
public enum UserDefaultsKeys: String, CaseIterable, RawRepresentable {
|
||||
case isEligibleForIap = "isEligibleForIap"
|
||||
case appLaunchedBefore = "ShowedWelcomeScreen"
|
||||
case plusVersion = "plusVersion"
|
||||
case transmissionCount = "reviewRequestCountKey"
|
||||
case automaticallyAcceptFiles = "automaticallyAcceptFiles"
|
||||
case saveFolderBookmark = "saveFolderBookmark"
|
||||
|
||||
@@ -15,7 +15,7 @@ struct TutorialView: View {
|
||||
let openPlus: () -> Void
|
||||
|
||||
@State private var licenseWindow: NSWindow?
|
||||
@ObservedObject var settings = Settings.sharedInstance
|
||||
@ObservedObject var iapManager = IAPManager.sharedInstance
|
||||
|
||||
var body: some View {
|
||||
|
||||
@@ -54,8 +54,9 @@ struct TutorialView: View {
|
||||
.opacity(0.5)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
|
||||
if !settings.gotPlus {
|
||||
|
||||
#if !GITHUB
|
||||
if !iapManager.plusVersionState {
|
||||
Button {
|
||||
openPlus()
|
||||
} label: {
|
||||
@@ -66,8 +67,9 @@ struct TutorialView: View {
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
Button {
|
||||
Settings.sharedInstance.deleteAllUserDefaults()
|
||||
} label: {
|
||||
@@ -77,7 +79,7 @@ struct TutorialView: View {
|
||||
.opacity(0.5)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ import StoreKit
|
||||
struct ContentView: View {
|
||||
|
||||
@ObservedObject var luiSettings = LUISettings.sharedInstance
|
||||
@ObservedObject var settings = Settings.sharedInstance
|
||||
@ObservedObject var iapManager = IAPManager.sharedInstance
|
||||
|
||||
var body: some View {
|
||||
AppRootView(isPlus: $settings.gotPlus, phoneView: {
|
||||
AppRootView(phoneView: {
|
||||
DeviceListView()
|
||||
.environment(\.sheetActive, isShareExtension())
|
||||
}, settingsView: {
|
||||
CustomSection(header: settings.gotPlus ? "" : "General", footer: "TrustedDevicesFooterShort") {
|
||||
CustomSection(header: iapManager.plusVersionState ? "" : "General", footer: "TrustedDevicesFooterShort") {
|
||||
LUIButton {
|
||||
FileManager.default.openDocumentFolder()
|
||||
} label: {
|
||||
@@ -46,13 +46,10 @@ struct DeviceListView: View {
|
||||
#if !EXTENSION
|
||||
@StateObject var receiveModel = ReceiveModel(controlPlusScreen: { show in
|
||||
log("[DeviceListView] Setting showPlusScreen to \(show)")
|
||||
errorVibration()
|
||||
DeviceListViewModel.sharedInstance.showPlusScreen = show
|
||||
presentPaywall()
|
||||
})
|
||||
#endif
|
||||
|
||||
@ObservedObject var model = DeviceListViewModel.sharedInstance
|
||||
|
||||
@Environment(\.scenePhase) var scenePhase
|
||||
@Environment(\.sheetActive) var sheetActive
|
||||
@ObservedObject var nearbyConnectionManager = NearbyConnectionManager.shared
|
||||
@@ -219,9 +216,6 @@ struct DeviceListView: View {
|
||||
NearbyConnectionManager.shared.stopDeviceDiscovery()
|
||||
}
|
||||
}
|
||||
#if !EXTENSION
|
||||
.modifier(PlusVersionSheetModifier(sheetActive: $model.showPlusScreen, isPlusVersion: $settings.gotPlus))
|
||||
#endif
|
||||
.animation(.smooth, value: nearbyConnectionManager.hasLocalNetworkPermission)
|
||||
.animation(.smooth, value: nearbyConnectionManager.isConnectedToLocalNetwork)
|
||||
.navigationBarItems(trailing: ZStack {
|
||||
@@ -236,13 +230,6 @@ struct DeviceListView: View {
|
||||
}
|
||||
|
||||
|
||||
final class DeviceListViewModel: SharedInstance {
|
||||
static var sharedInstance = DeviceListViewModel()
|
||||
|
||||
@Published var showPlusScreen = false
|
||||
}
|
||||
|
||||
|
||||
struct DeviceFilePickerButton: View {
|
||||
|
||||
let device: RemoteDeviceInfo
|
||||
|
||||
@@ -15,7 +15,7 @@ public struct LocalNetworkPermissionView: View {
|
||||
|
||||
public var body: some View {
|
||||
|
||||
PermissionView(title: "introduction_local_network_access", symbol: "", subtitle: "introduction_local_network_access_description".localized(with: "introduction_continue".localized()), permissionAction: {
|
||||
PermissionView(title: "introduction_local_network_access", watchSymbol: "", subtitle: "introduction_local_network_access_description".localized(with: "introduction_continue".localized()), permissionAction: {
|
||||
|
||||
if requestedLocalNetworkAccess {
|
||||
// Something went wrong, user pressed again on continue. In this case, just continue with setup
|
||||
|
||||
Reference in new issue
Block a user