Improve logged out handler of extension, create new local db path

This commit is contained in:
Jackson Harper
2024-01-04 12:20:57 +08:00
parent ab004caad7
commit 486ec19937
7 changed files with 54 additions and 7 deletions

View File

@ -22,4 +22,20 @@ public extension PlatformViewController {
#endif
return hostingController
}
static func makeLoggedOutShareExtensionController(
extensionContext: NSExtensionContext?
) -> PlatformViewController {
registerFonts()
let hostingController = PlatformHostingController(
rootView: LoggedOutShareExtensionView(extensionContext: extensionContext)
)
#if os(iOS)
hostingController.view.layer.cornerRadius = 12
hostingController.view.layer.masksToBounds = true
hostingController.view.layer.isOpaque = false
#endif
return hostingController
}
}

View File

@ -17,7 +17,7 @@ public class ShareExtensionViewModel: ObservableObject {
@Published var debugText: String?
@Published var noteText: String = ""
let services = Services()
public let services = Services()
let queue = OperationQueue()
public init() {}

View File

@ -470,3 +470,26 @@ public struct ShareExtensionView: View {
}
}
}
public struct LoggedOutShareExtensionView: View {
let extensionContext: NSExtensionContext?
public init(
extensionContext: NSExtensionContext?)
{
self.extensionContext = extensionContext
}
public var body: some View {
VStack(spacing: 20) {
Text("You are not logged in. Please open the Omnivore app and log in to start saving items to your library")
Button(action: {
if let extensionContext = extensionContext {
extensionContext.completeRequest(returningItems: nil)
}
}, label: { Text("Dismiss") })
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(20)
}
}

View File

@ -7,7 +7,8 @@ let logger = Logger(subsystem: "app.omnivore", category: "models")
/// An `NSPersistentContainer` subclass that lives in the `Models` package so that
/// the data model is looked for in the same package bundle (rather than the main bundle)
public class PersistentContainer: NSPersistentContainer {
public static var DatabaseFile = "store.sqlite"
public static var DatabaseVersion = "002"
public static var DatabaseFile = "store-v\(DatabaseVersion).sqlite"
public static func path() -> URL? {
// Store the sqlite file in the app group container.

View File

@ -53,10 +53,6 @@ public final class DataService: ObservableObject {
}
public init(appEnvironment: AppEnvironment, networker: Networker) {
if Self.isFirstTimeRunningNewAppBuild() {
Self.deleteLocalStorage()
}
self.appEnvironment = appEnvironment
self.networker = networker
self.persistentContainer = PersistentContainer.make()
@ -197,6 +193,7 @@ public final class DataService: ObservableObject {
}
} catch {
print(error.localizedDescription)
print("ERROR: ", error)
}
}

View File

@ -44,7 +44,7 @@ public extension DataService {
continuation.resume(throwing: BasicError.message(messageText: "CoreData error"))
}
case .error:
continuation.resume(throwing: BasicError.message(messageText: "Newsletter Email fetch error"))
continuation.resume(throwing: BasicError.message(messageText: "labels fetch error"))
}
}
}

View File

@ -16,6 +16,16 @@ import Views
super.viewDidLoad()
view.backgroundColor = .clear
if !viewModel.services.authenticator.isLoggedIn,
!viewModel.services.dataService.appEnvironment.environmentConfigured
{
embed(
childViewController: UIViewController.makeLoggedOutShareExtensionController(extensionContext: extensionContext),
heightRatio: 0.60
)
return
}
NotificationCenter.default.addObserver(
forName: Notification.Name("ShowAddNoteSheet"),
object: nil,